gutschilla / elixir-pdf-generator

Create PDFs with wkhtmltopdf or puppeteer/chromium from Elixir.
MIT License
332 stars 71 forks source link

xvfb always needed on Windows #59

Closed niknetniko closed 4 years ago

niknetniko commented 4 years ago

For some reason, when running on Windows, it always tries to use xvfb-run, which obviously fails. I'm not entirely sure if this is a bug or I'm missing something.

I'm using:

> iex --version
IEx 1.9.2 (compiled with Erlang/OTP 20)
> wkhtmltopdf --version
wkhtmltopdf 0.12.5 (with patched qt)

Erlang, Elixir and wkhtmltopdf are all on my path. When running the example, I get:

iex(2)> PdfGenerator.generate(html, page_size: "A5", command_prefix: nil)
[debug] {"xvfb-run", ["-a", "c:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe", "--page-size", "A5", "C:\\Users\\strij\\AppData\\Local\\Temp/8PnBbvX0.html", "C:\\Users\\strij\\AppData\\Local\\Temp/8PnBbvX0.pdf"]}
** (ErlangError) Erlang error: :enoent
    (elixir) lib/system.ex:791: System.cmd("xvfb-run", ["-a", "c:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe", "--page-size", "A5", "C:\\Users\\strij\\AppData\\Local\\Temp/8PnBbvX0.html", "C:\\Users\\strij\\AppData\\Local\\Temp/8PnBbvX0.pdf"], [stderr_to_stdout:
 true])
    (pdf_generator) lib/pdf_generator.ex:141: PdfGenerator.generate/2
gutschilla commented 4 years ago

Hi @niknetniko , thanks a lot for reporting. Generally speaking, xvfb should be an option, not the norm. Which version of PdfGenerator are you using?

niknetniko commented 4 years ago

@gutschilla I'm using version 0.6.0.

gutschilla commented 4 years ago

This is weird. Running on Linux, OTP22, Elixir 19.4, wkhtmltopdf 0.12.4 yields

PdfGenerator.generate("<html><body>yo", page_size: "A5", command_prefix: nil)                            
15:40:28.130 [debug] {"/home/mart/.asdf/shims/wkhtmltopdf", ["--page-size", "A5", "/tmp/Xjz3QNdv.html", "/tmp/Xjz3QNdv.pdf"]}

As we both have wkhtmltopdf on PATH, the minor version differences in wkhtmltopdf and Elixir shouldn't matter. Neither should the OS.

Could you do me a favour and try

git clone https://github.com/gutschilla/elixir-pdf-generator.git
cd elixir-pdf-generator
iex -S mix

and in your IEX shell

PdfGenerator.generate("<html><body>yo", page_size: "A5", command_prefix: nil)

and while we're at it in your (Power)shell

mix test

This reminds me that I should set up a test running on Wondows.

gutschilla commented 4 years ago

Also @niknetniko , are you sure that you do not specify a :command_prefix in your config.exs? May I kindly ask for your mix.exs and yourconfig/config.exs and your environment-specific config (usually config/dev.exs)

gutschilla commented 4 years ago

Looking at https://github.com/gutschilla/elixir-pdf-generator/blob/b088619b38a032a3b3b06fbfbad63010a331a81e/lib/pdf_generator.ex#L258 the prefix really only kicks in when there's a configuration set accordingly or an option. The latter is untrue.

So, what's the output of

Application.get_env(:pdf_generator, :command_prefix)
niknetniko commented 4 years ago

@gutschilla It was indeed configured in my config.exs file, if I remove the prefix from the config file, it works. Thank you for taking the time to look into this, I really appreciate it!

gutschilla commented 4 years ago

@niknetniko Glad it works now!