Closed churcho closed 5 years ago
This should be the method you are calling.
def from_string(html_code, pdf_output_path, options \\ []) do
# Random gen filename
{:ok, path} = Briefly.create(extname: ".html")
case File.open(path, [:write, :utf8]) do
{:ok, file} ->
IO.write(file, html_code)
File.close(file)
Path.absname(path)
|> from_file(pdf_output_path, options)
{:error, error} ->
{:error, error}
end
end
:enoent
is normally associated to "No such file or directory". I think it might be you are trying to generate inside a folder that doesn't exists, or you don't have permission to create the file (I don't think it is the last, because the error should be different).
I didn't test it in Docker (I will be doing that today for other project that I am using puppeteer-pdf).
When I check the directory I see the file created by {:ok, path} = Briefly.create(extname: ".html")
.
The result of File.ls
is {:ok, ["app", "briefly-1559"]}
, should it have a .html extention?
The pdf doesn't seem to be created. I am trying to work around the installation of puppeteer and the libraries that support it.
Chances are that is what the issue is.
My pdf default directory is /tmp/
What I find strange/confusing is I get back the location of the supposedly new file but it's not created.
Ok, another possibility is the path to execute puppeteer-pdf
in the command line, if the software can't find it, it will give that same error. Try to check the exec_path
,
Application.get_env(:puppeteer_pdf, :exec_path)
That I have to point to the right location. I am not getting an error on pdf create. That process is getting completed. The issue is. My PDF is missing. I can't read it.
When I log the results of PuppeteerPdf.Generate.from_string
I get something like this: "/tmp/contract-629b1178-e216.pdf"
The issue is within /tmp there is no such file.
Ok, I understood your question no. So, the :enoent
is on your code when you try to read the file from the pdf_output_path
you defined in from_string(html_code, pdf_output_path, options \\ [])
.
So, the file should be generate by puppeteer-pdf
and not any of my code. Can you check if you run the command in your command line puppeteer-pdf index.html --path output.pdf
it can generate the file ? I think I never call it with a directory behind the name.
EDIT: Check also if it takes more than 5 seconds to generate the file.
puppeteer-pdf index.html --path output.pdf
generates output.pdf
I just did a touch index.html and called the pdf generation code.
Try to print (you need to modify the dependency code and remove the _build
folder) the values in the array params
in case System.cmd(exec_path, params) do
.
What would result in my .html files all being created but none of the .pdf ones for the same operation?
Currently trying to see if I can inspect on https://github.com/coletiv/puppeteer-pdf/blob/master/lib/generate.ex#L65
I get the following:
System.cmd("/usr/lib/node_modules/puppeteer-pdf", params)
{"", 13}
Found out what my issue was. My container is using /usr/bin/puppeteer-pdf
and not /usr/lib/node_modules/puppeteer-pdf
Changed that and now the PDF generation is working
When I run
PuppeteerPdf.Generate.from_string
and pass it the correct params. I get back the location of the created pdf but on inspection, nothing seems to be created at that directory.I am running in a Docker env.
Is this a common issue? Do you have a Dockerfile you can share which installs all the necessary libs?