mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.54k stars 647 forks source link

RuntimeError on PDf Generation #1113

Open mcieaaka opened 6 months ago

mcieaaka commented 6 months ago

Can anybody help me to figure out, Why am I facing this issue, and what might be the fix for the same?

Issue description

While trying to generate PDF in my Rails App, I randomly get this error, but unable to recreate or figure out why this is happening

Here is the error:

Failed to execute:
["/usr/local/bundle/bin/wkhtmltopdf", "--encoding", "UTF-8", "--enable-local-file-access", "--margin-bottom", "4", "--margin-left", "0", "--margin-right", "0", "--header-html", "file:////tmp/wicked_header_pdf20240423-3535-73r70r.html", "--footer-html", "file:////tmp/wicked_footer_pdf20240423-3535-vhx6uw.html", "file:////tmp/wicked_pdf20240423-3535-4x7ecq.html", "/tmp/wicked_pdf_generated_file20240423-3535-6n8vuc.pdf"]
Error: PDF could not be generated!
 Command Error: Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
Error: Failed to load file:////tmp/wicked_header_pdf20240423-3535-73r70r.html, with network status code 203 and http status code 0 - Error opening //tmp/wicked_header_pdf20240423-3535-73r70r.html: No such file or directory
Error: Failed loading page file:////tmp/wicked_header_pdf20240423-3535-73r70r.html (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: ContentNotFoundError

Before this, I was getting same error, but the message included: "Blocked Access", I tried adding --enable-local-file-access after which I am getting this new error.

System specifications

wicked_pdf gem version: 2.6.3

whtmltopdf provider gem and version if one is used: https://rubygems.org/gems/wkhtmltopdf-binary 0.12.6

platform/distribution and version: Ubuntu 20.04

unixmonkey commented 6 months ago

Error opening //tmp/wicked_header_pdf20240423-3535-73r70r.html: No such file or directory

Either your TMP directory is becoming non-writable at times, or something is clearing out tmp files before the process that needs them is done.

Do you have a recurring job or deploy process that empties the tmp dir?

Are you holding a separate reference to the header from one PDF generation, and trying to use it for a second one?

Sorry I don't have an answer on this. I'm just hoping maybe I can help you figure out what's happening on your end.