Open spq24 opened 7 years ago
How random is "randomly"?
What version of wkhtmltopdf
are you running, and from what gem or package?
If you open one of these blank PDFs in a text editor, do you see the %PDF-1.
at the beginning and %EOF
at the end?
Did anything change that might explain this (move to Heroku, gem update, new Rails version)?
Things I could think of that might cause this to "just start happening":
wkhtmltopdf
between 0.9.x
- 0.12.1.2
, there's an HTTPS over SSLv3 issue that started rearing it's head when the POODLE attack caused sysadmins to quickly disable SSLv3 over their networks. I doubt this would be "randomly" though, unless you are fetching assets from variable sources for use in your PDFswkhtmltopdf
renderer gives up on it. Extend with javascript_delay
or window_status
optionsIt may or may not be related, but thread safety with Puma on Heroku was brought up in #512, might be worth a look.
Hope this helps. Let me know if you have any more information or findings!
Thank you for the quick and in depth reply. I tried everything you mentioned but still no luck :/
Versions
From my gemfile.lock
wicked (1.3.0) railties (>= 3.0.7) wicked_pdf (1.0.6) wkhtmltopdf-binary-edge (0.12.3.0)
"randomly" random as in nothing I can find/think of would've caused this so it looks like it was some update I wasn't aware of in a dependency.
"SSLv3" I don't have any images or downloads from third parties (in fact I don't have any media of any sort in the pdf, just straight styled text)
I looked at #344 which is where I got the different ideas to try the different wkhtmltopdf
I'm also not downloading the PDF with an SSL'd URL to make sure that's not the reason.
"Invalid HTML" I don't think it's incomplete or invalid HTML as nothing changed there from when it worked.
I even just tried rendering the below, with no luck:
<html>
<head><meta charset='utf-8' /></head>
<body>
<div id="header">
test
</div>
<div id="content">
test
</div>
</body>
</html>
"CSS Print" I tried to do the emulate media but when I click "rendering" nothing happens.
"Javascript not loading" No javascript in this. It's a really simple PDF so it's boggling my mind what could've gone wrong.
"Server Timeouts" I don't think so. Both locally and on Heroku I have no indication of a timeout. It says it's being rendered in the log. I can see when it does the *wicked and it looks like a command to convert a text file to a pdf...but nothing shows up.
"Webrick" I'm using Puma on Heroku and locally I'm using thin. Could either of those cause a problem?
I'll look more into 512 but that wouldn't explain why it's not working locally right?
Thank you for any help/ideas you can provide on this. It's much appreciated
Did you inspect a "bad" pdf with a text editor?
How random is it? It sounds like you can make it fail regularly, so I'm guessing it's less random than, say, 1 in 1000 times. Does it ever work successfully? Is it certain reports, or will it fail once, then be successful later for the same URL?
Does anything change if you update wicked_pdf
to the latest version of the gem to get whatever fixes are in there:
Gemfile
gem 'wicked_pdf', '1.1.0'
or perhaps even to master
:
gem 'wicked_pdf', github: 'mileszs/wicked_pdf', branch: 'master'
I don't know if this helps very much for your situation, but if you are in a pinched-for-time situation, you can use debug=true
with wkhtmltopdf
directly like this:
wkhtmltopdf http://yourapp.com/reports/1.pdf?debug=true report1.pdf
Of course that assumes the issue isn't with wkhtmltopdf
itself, or the system you are running it on. You could probably script a way to automate it.
Sorry I see what you are saying with the random. What I meant was that it's random that it happened , caused by no change done by myself (admittedly poor choice of wording in hindsight).
Now the PDF never works. Only debug mode shows anything.
I updated to 1.1.0 and updated wkhtmltopdf-binary-edge to 0.12.4.0
Still no luck.
Where would i put this?
wkhtmltopdf http://yourapp.com/reports/1.pdf?debug=true report1.pdf
in the controller?
I guess I'm going to have to try another PDF builder
Contact me by email or Twitter DM if you'd like some help troubleshooting this before giving up.
If you do choose another PDF builder, you might check out PDFkit or Prawn.
I suspect you'll have a similar issue with PDFkit if the issue is actually with wkhtmltopdf
, since it uses that, too. Prawn would require you to re-author your template to no longer be HTML, and it uses a pretty different template structure, but is good at doing things that wkthtmltopdf
cannot easily, like precise positioning and repeating table headers. I like it for simple table reports.
From a brief screen share it appears we were seeing some form of this issue: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3241
PDFs would render with the font size zoomed WAY out, and for whatever reason would not show up in Chrome at all (black screen). When saving to file or opening with Firefox it would open, but be so small it was unreadable.
We were able to revert to a previous version of the wkhtmltopdf
gem to get things looking normal again, but there seems to still be something up with how Chrome opens those files (maybe on that machine only, or maybe not).
This is a PDF generated on the command line from this system with:
wkhtmltopdf https://google.com google.pdf
I have the same issue with wicked_pdf 1.1.0
If you are indeed having the same issue, this command above should have a similar output:
wkhtmltopdf https://google.com google.pdf
This is not a problem with wicked_pdf
, but with wkhtmltopdf
. Please see the linked issue above for workarounds.
I am getting this error on the server. Working fine on the local.
gems I have used are gem 'wicked_pdf', '~> 1.1' gem 'wkhtmltopdf-binary', '~> 0.12.3.1'
RuntimeError (Failed to execute: ["/usr/local/bin/wkhtmltopdf", "-q", "file:////tmp/wicked_pdf20180531-994-1x8fbfn.html", "/tmp/wicked_pdf_generated_file20180531-994-1vidmtk.pdf"] Error: PDF could not be generated!
Command Error: /usr/bin/env: ruby: No such file or directory ):
@bibinjpalathara I have the same, added permission on /usr/local/bundle/gems/wkhtmltopdf-binary-0.12.6.5/bin/
but still getting the error, Did you manage to fix it ?
This just started happening randomly. When I go to open the PDF nothing happens and it just renders an empty black (as far as I can tell nothing in it) PDF. Nothing changed code wise on my end.
I used wkhtmltopdf-binary-edge originally. I also tried to install wkhtmltopdf-heroku and regular wkhtmltopdf-binary but none of that worked. I restarted the server and bundle installed. I removed 'wkhtmltopdf-binary' to see if that was the issue and nothing has worked.
This is happening both locally and in production on heroku.
The other weird thing: If I put ?debug to view it in HTML it works perfectly.
I'm not seeing any errors or problems in the logs at all and nothing should interfere with it. All the data is properly being pulled from the db and sent. Nothing has changed from that end since it was last working.
Any ideas? Could really use some help. These are billing reports that have to go out ASAP.
Initializer: wicked_pdf.rb
WickedPdf.config = {}
Controller: