Skip to content

Commit

Permalink
**BUGFIX** introduced in 0.5.0 when global options to wkhtmltopdf wer…
Browse files Browse the repository at this point in the history
…en't accepted any more due to wrong shell parameter order. Thanks to [manukall](https://github.com/manukall) for reporting.
  • Loading branch information
gutschilla committed Apr 19, 2019
1 parent d6ef825 commit 7fdf481
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# elixir-pdf-generator

A wrapper for wkhtmltopdf (HTML to PDF) and PDFTK (adds in encryption) for use
in Elixir projects. If available, it will use xvfb-run (x virtual frame buffer)
to use wkhtmltopdf on systems that have no X installed, e.g. a server.
A wrapper for both wkhtmltopdf and chrome-headless plus PDFTK (adds in
encryption) for use in Elixir projects. If available, it will use xvfb-run (x
virtual frame buffer) to use wkhtmltopdf on systems that have no X installed,
e.g. a server.

# New in 0.5.0 - farewell Porcelain, hello chrome-headless (puppeteer)

Expand All @@ -16,6 +17,15 @@ to use wkhtmltopdf on systems that have no X installed, e.g. a server.
- **Support for chrome-headless** for (at least for me) faster and nicer renderings.
- Since this is hopefully helpful, I rose the version to 0.5.0 even tough
the API stays consistent
- 0.5.1
- allow chrome to be executed as root via default config option
`disable_chrome_sandbox` – this is required for an easy usage within a
docker container as in
[elixir-pdf-server](https://github.com/gutschilla/elixir-pdf-server)
- 0.5.2
- **BUGFIX** introduced in 0.5.0 when global options to wkhtmltopdf weren't
accepted any more due to wrong shell parameter order. Thanks to
[manukall](https://github.com/manukall) for reporting.

For a proper changelog, see [CHANGES](CHANGES.md)

Expand Down
8 changes: 4 additions & 4 deletions lib/pdf_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ defmodule PdfGenerator do
{:url, url} -> url
_html -> html_path
end
more_params = options[:shell_params] || []
arguments = [
shell_params = options[:shell_params] || []
arguments = List.flatten([
shell_params,
"--page-size", options[:page_size] || "A4",
source, pdf_path
] ++ more_params

])
# for wkhtmltopdf we support prefixes like ["xvfb-run", "-a"] to precede the actual command
case get_command_prefix(options) do
nil -> {executable, arguments}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule PdfGenerator.Mixfile do
[
app: :pdf_generator,
name: "PDF Generator",
version: "0.5.0",
version: "0.5.2",
elixir: ">= 1.1.0",
deps: deps(),
description: description(),
Expand Down
9 changes: 8 additions & 1 deletion test/pdf_generator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ defmodule PdfGeneratorTest do
@html
|> PdfGenerator.generate!(delete_temporary: true)
|> String.replace( ~r(\.pdf$), ".html")
|> File.exists?
|> File.exists?()
|> refute

# cannot really be sure if temporyr file was deleted but this shouldn't
Expand All @@ -88,4 +88,11 @@ defmodule PdfGeneratorTest do
assert {:ok, "%PDF-1" <> _pdf} = @html |> PdfGenerator.generate_binary(delete_temporary: true)
end

test "shell_params are accepted" do
@html
|> PdfGenerator.generate!(shell_params: ["--orientation", "landscape", "--margin-right", "0"])
|> File.exists?()
|> assert
end

end

0 comments on commit 7fdf481

Please sign in to comment.