gutschilla / elixir-pdf-generator

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

(FunctionClauseError) no function clause matching in System.cmd/3 (Linux server) #65

Open feliperenan opened 4 years ago

feliperenan commented 4 years ago

Related to https://github.com/gutschilla/elixir-pdf-generator/issues/56

I'm getting this error on linux server:

(elixir) lib/system.ex:621: System.cmd(nil, ["/opt/app/lib/pdf_generator-0.6.0/priv/node_modules/chrome-headless-render-pdf/dist/cli/chrome-headless-render-pdf.js", "--url", "file:///tmp/0wolmM04.html", "--pdf", "/tmp/0wolmM04.pdf", "--paper-width", "8.26772", "--paper-height", "11.695", "--dpi", "300"], [stderr_to_stdout: true])

In my case, I'm switching from wkhtmltopdf which was working but with some issues in the layout to chrome-headless. I'm sure that chromdriver, nodejs, chrome-headless-render-pdf and, puppeteer are being installed as well.

RUN apk update && \
  apk upgrade --no-cache && \
  apk add --no-cache \
    ...
    nodejs \
    npm \
    chromium \
    chromium-chromedriver

RUN npm -g install chrome-headless-render-pdf puppeteer
config :pdf_generator,
  use_chrome: true,
  prefer_system_executable: true,
  raise_on_missing_wkhtmltopdf_binary: false
PdfGenerator.generate(
  html,
  generator: :chrome,
  prefer_system_executable: true,
  page_size: "A4",
  shell_params: ["--dpi", "300"],
  no_sandbox: true
)

Yeap, I'm using mix release.

gutschilla commented 4 years ago

Alright @feliperenan thanks for opening a new issue. Please help me reproduce this error:

Since reproducing this error by guessing you configuration is pretty time-consuming please consider granting me read access to your repo so I can at least run mix test which should yield an error.

gutschilla commented 4 years ago

Don't get me wrong – to reproduce I would have

I am looking for a shortcut to this :-)

gutschilla commented 4 years ago

@feliperenan We could do this together in a new github repo – I'd happily proivide the basics, you jot in your configuration.

gutschilla commented 4 years ago

https://github.com/gutschilla/test-pdf-generator-alpine-docker

feliperenan commented 4 years ago

Sure, I'm still doing some investigation here and if I didn't find anything I will come up with some reproduced app. Just opened the issue to make sure I'm doing anything wrong and maybe others also are having it 😄

gutschilla commented 4 years ago

@feliperenan Added you as contributer. Allow me to create the boilerplate

feliperenan commented 4 years ago

Hey @gutschilla

I've found the issue and it's my fault. The thing is that I misunderstood my Docker file (I was kind lost on it) since we have different images there and I couldn't get the required executables in the correct environment (the one that I was receiving the error).

So, once I was in the right env I able to check that with:

System.find_executable("chrome-headless-render-pdf")
#=> nil

But I still think we could improve that somehow in the library to thrown some friendly error when the executable is not found. I will try to understand this code a little bit more and if possible, I'll propose something for that.

I really appreciated your faster answers. Thank you very much and keep up with this awesome work 🙌

gutschilla commented 4 years ago

@feliperenan Thanks for your investigation and congrats for solving the issue. You are right, this error should emit some friendly warning like "please check if your chrome-headless-renderer-pdf is installed correctly as I cannot find the executable on PATH" or something.

I am happy to hear you suggestions.

On a side note: if you have questions about the code let me know. The underlying base dates back to 2015/16. It's been a while.

gutschilla commented 4 years ago

I'll reopen this so a PR can properly point to this.