Giter Site home page Giter Site logo

Comments (11)

myungwoo-song avatar myungwoo-song commented on August 27, 2024

Having same error here, without enable_local_file_access option, with no local file access, resulting blocked file access error.
I am currently doubting S3 bucket request rate exceeding.

from wicked_pdf.

unixmonkey avatar unixmonkey commented on August 27, 2024

Does reverting solve your problem? Did you also upgrade wkhtmltopdf at the same time? If you did, I would bet that's the real cause.

Something I've always tried to do is make sure my assets are always local files before PDF generation, and nothing is being fetched over the network in real-time.

from wicked_pdf.

staffler-xyz avatar staffler-xyz commented on August 27, 2024

Any update on this? Would an update to 2.7.0 or 2.8.0 fix this?

from wicked_pdf.

unixmonkey avatar unixmonkey commented on August 27, 2024

@staffler-xyz Possibly, but probably not. Have you tried yet?

Please provide more information if you can. What is the actual error? Do you get a stacktrace? What version are you running? Is it also random (like it works most of the time)?

I can't think of any good reason this happens randomly, unless your system is getting rid of tempfiles that are still in-use, or you have system limits that prevent too many wkhtmltopdf instances from running simultaneously.

from wicked_pdf.

staffler-xyz avatar staffler-xyz commented on August 27, 2024

hi, I get this error:

["/app/vendor/bundle/ruby/3.1.0/gems/wkhtmltopdf-heroku-2.12.6.0/bin/wkhtmltopdf-linux-amd64", "--disable-smart-shrinking", "--margin-top", "0", "--margin-bottom", "0", "--margin-left", "0", "--margin-right", "0", "--footer-spacing", "-30", "--footer-html", "file:////tmp/wicked_footer_pdf20240315-2-pag8lr.html", "file:////tmp/wicked_pdf20240315-2-gicnwn.html", "/tmp/wicked_pdf_generated_file20240315-2-1mghdn.pdf"]
Error: PDF could not be generated!
Command Error: Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[=======================>                                    ] 39%
[=========================>                                  ] 43%
[===========================>                                ] 45%
[============================>                               ] 47%
[=============================>                              ] 49%
[==================================>                         ] 57%
[=====================================>                      ] 63%
[=========================================>                  ] 69%
[=============================================>              ] 75%
[================================================>           ] 80%
[==================================================>         ] 84%
[============================================================] 100%
Counting pages (2/6)                                              
[============================================================] Object 1 of 1
Resolving links (4/6)                                                      
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                          
[>                                                           ] 1%
Warning: Blocked access to file    
[=&gā€¦

(unfortunately the output is truncated at the end)

wicked_pdf gem version (output of cat Gemfile.lock | grep wicked_pdf): wicked_pdf (2.6.3)
wkhtmltopdf version (output of wkhtmltopdf --version): 0.12.6.0
whtmltopdf [provider gem]: wkhtmltopdf-heroku (2.12.6.0)
platform/distribution and version: heroku-20

from wicked_pdf.

unixmonkey avatar unixmonkey commented on August 27, 2024

@staffler-xyz Does it always die out like this? Is it random, or every time for this specific PDF generation?

This looks like wkhtmltopdf is dying early on while setting up the headers and footers (which you have), and is also complaining that it can't load a file (which is default behavior in newish versions of wkhtmltopdf, but can be "fixed" by adding enable_local_file_access as true to the WickedPDF config.

Try either enabling that option, or disabling custom headers and footers, or some combination of both. Also make sure your footer is a complete and valid HTML document, including doctype and <html><head></head><body>.

from wicked_pdf.

staffler-xyz avatar staffler-xyz commented on August 27, 2024

it happens randomly, usually it works after reloading the page. But it also fails in the background with ActiveJob and WickedPdf.new.pdf_from_string.

We don't use local files, only images from CDN.

This is our layout (simplified):

<!DOCTYPE html>
<html>
<head>
  <meta charset='UTF-8' />
  <%= stylesheet_link_tag("pdf", :media => "all") %>
  <style type="text/css">
    <%= yield(:styles) %>
  </style>
  <%= javascript_tag do %>
    function number_pages() {
      <javascript code>
    }
  <% end %>
</head>
<body onload="number_pages()">
  <%= yield %>
</body>
</html>

I noticed that this might be the problem:

<%= stylesheet_link_tag("pdf", :media => "all") %>

Should it be replaced with:

<%= wicked_pdf_stylesheet_link_tag("pdf", :media => "all") %>

Did anyone solve this successfully?

from wicked_pdf.

unixmonkey avatar unixmonkey commented on August 27, 2024

Is it possible that generating the PDF is exceeding Heroku's memory limit, and thus getting killed off before it finishes?

from wicked_pdf.

staffler-xyz avatar staffler-xyz commented on August 27, 2024

I don't think so, memory is 16GB RAM and the application is running at about 1GB RAM (no spikes when running wkhtmltopdf commands)

from wicked_pdf.

unixmonkey avatar unixmonkey commented on August 27, 2024

If possible, try downloading remote resources from the CDN into local files or tempfiles or base64, and loading that instead.
This is what I've always done and advocated for, though I'm sure many others do not and it works fine for their use-cases.

I don't have any solid reasons for this, but experience & casually googling wkhtmltopdf dies sometimes turns up numerous issues, like this one where they needed to increase the JS delay, this one where they suggested it was opening too many files or running out of swap space, or this one where the network stack dies while downloading assets.

from wicked_pdf.

staffler-xyz avatar staffler-xyz commented on August 27, 2024

ok, thanks for your hints. I will check again and post the solution here, if found.

from wicked_pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.