gutschilla / elixir-pdf-generator

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

Can't run without wkhtmltopdf #53

Closed PJUllrich closed 5 years ago

PJUllrich commented 5 years ago

I'm having problems running this without installing wkhtmltopdf. The documentation says that one needs either wkhtmltopdf or chromium, so I installed chromium.

However, when I start the application with mix phx.server, the following error occurs:

** (Mix) Could not start application pdf_generator: PdfGenerator.start(:normal, []) returned an error: shutdown: failed to start child: PdfGenerator.PathAgent
    ** (EXIT) an exception was raised:
        ** (RuntimeError) wkhtmltopdf executable was not found on your system
            (pdf_generator) lib/pdf_generator_path_agent.ex:76: PdfGenerator.PathAgent.maybe_raise/3
            (pdf_generator) lib/pdf_generator_path_agent.ex:69: PdfGenerator.PathAgent.raise_or_continue/1
            (pdf_generator) lib/pdf_generator_path_agent.ex:37: PdfGenerator.PathAgent.init_opts/1
            (elixir) lib/agent/server.ex:8: Agent.Server.init/1
            (stdlib) gen_server.erl:374: :gen_server.init_it/2
            (stdlib) gen_server.erl:342: :gen_server.init_it/6
            (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

So, is wkhtmltopdf required when I only want to use chromium as well?

My Setup

I installed chromium locally with:

npm install chrome-headless-render-pdf puppeteer

I added this to config/config.exs:

config :pdf_generator,
    use_chrome: true

And added :pdf_generator to application:

def application do
    [
      mod: {MyApp.Application, []},
      extra_applications: [:logger, :runtime_tools, :pdf_generator]
    ]
end
gutschilla commented 5 years ago

Hi @PJUllrich - there's a configuration option for this. Unfortunately it's more or less undocumented:

config :pdf_generator,
  raise_on_missing_wkhtmltopdf_binary: false

The dafault is true, hence the error.

I will log this as bug, since it's only visible if you look at the module docs for PdfGenerator. It should be in the README.

gutschilla commented 5 years ago

Oh and thanks a lot for reporting

PJUllrich commented 5 years ago

Hey @gutschilla thank you for your answer! I managed to get it to work with your mentioned workaround, so thank you very much!

PJUllrich commented 5 years ago

Sorry, this should probably be open until a fix is ready ;)

gutschilla commented 5 years ago

@PJUllrich - great to hear it's working.

The idea behind the error was to immediately crash on startup when the binary wasn't there (so no PDF could be generated anyways).

Then support for Chrome was added ... and the configuration option that never made a lot of sense using suddenly became viable to use ;-)

gutschilla commented 5 years ago

Fixed in https://github.com/gutschilla/elixir-pdf-generator/commit/1938bb09b4f5ffaf3b68c44dad9b13c097f11acb

Will be included in next release.

gutschilla commented 5 years ago

@PJUllrich please let me know if that would have gotten you to the missing option in the first place. Thanks for reporting, again!

PJUllrich commented 5 years ago

Looks good to me! Thank you!

tech-giants commented 4 years ago

Hi, @gutschilla I am experiencing the same issue as @PJUllrich stated above and Currently I am using Ubuntu 20.04, as per 1938bb0 it is fixed for Ubuntu 18 does this also apply for Ubuntu 20? For now I have fixed this issue with:

config :pdf_generator, raise_on_missing_wkhtmltopdf_binary: false