Closed AmadorZcv closed 4 years ago
It looks like you can use shell_params
with the Chrome headless variation. If you look at the docs for the Node package in use, chome-headless-render-pdf
, there is an option for chrome-binary
:
https://www.npmjs.com/package/chrome-headless-render-pdf
That may be all you need if you have access to your node_modules directory while running.
Hi @AmadorZcv and @kiere thanks for the heads-up. Might be well worth documenting
Can you help me with the chrome path? I have the same problem as @AmadorZcv. I tried to set an option chrome-binary
in shell_params
, but it doesn't work. It still refers to the highest level directory, not to assets, and the chrome path doesn't change. I even try to set chrome_path
in the config, but this also doesn't work.
{:ok, filename} = PdfGenerator.generate(html, generator: :chrome, shell_params: ["--chrome_binary", File.cwd!() <> "/assets/node_modules/chrome-headless-render-pdf/dist/cli/chrome-headless-render-pdf.js"], prefer_system_executable: false)
[debug] {"/Users/kkobierska/.nvm/versions/node/v8.16.0/bin/node",
["/Users/kkobierska/workspace/yata/yata-phoenix/_build/dev/lib/pdf_generator/../../../../node_modules/chrome-headless-render-pdf/dist/cli/chrome-headless-render-pdf.js", "--url",
"file:///var/folders/js/1yzf61s96dqf4sw_35nmxxxw0000gn/T/2ojByMIM.html", "--pdf",
"/var/folders/js/1yzf61s96dqf4sw_35nmxxxw0000gn/T/2ojByMIM.pdf", "--paper-width",
"8.26772", "--paper-height", "11.695", "--chrome_binary",
"/Users/kkobierska/workspace/yata/yata-phoenix/assets/node_modules/chrome-headless-render-pdf/dist/cli/chrome-headless-render-pdf.js"]}
** (MatchError) no match of right hand side value:
{:error, {:generator_failed, "module.js:550\n throw err;\n ^\n\n
Error: Cannot find module '/Users/kkobierska/workspace/yata/yata-phoenix/node_modules/chrome-headless-render-pdf/dist/cli/chrome-headless-render-pdf.js'\n
at Function.Module._resolveFilename (module.js:548:15)\n
at Function.Module._load (module.js:475:25)\n at Function.Module.runMain (module.js:694:10)\n
at startup (bootstrap_node.js:204:16)\n
at bootstrap_node.js:625:3\n"}}
So there is no option to set the path to the chrome-headless-render-pdf module.
My solution was to have a extra node_modules on the root directory of the project with just that package.
Not optimal at all, maybe there should be an option to specify the path to that? The wkhtmltopdf equivalent has the option available
@AmadorZcv Sorry for the late reply. I am working using a more direct Elixir<->NodeJS integration (see https://github.com/revelrylabs/elixir-nodejs) which will allow us to have to javascript placed in the library's priv
directory. I will probably vernodr this.
There will probably different releases for this library, one with everything vendored-in (when lecenses allow, and this is going to be quite big) and one where one still has to run npm install
or point to a globally available chrome-binary.
Can i specify the chrome path? I need to use the node modules however the package searches for one on the highest level, not on assets.