Comments (3)
I suspect your issue is that the image has to load from a remote source multiple times, which is longer than the timeout to get assets, so wkhtmltopdf
gives up.
You can try adjusting the timeout, or using the window_status
setting. Though, if the images are the same repeated, I'd suggest caching them so they don't have to re-download every time.
Maybe something like this (untested, but I'm sure you'll see where I'm going):
def embed_remote_image(url, content_type)
# Setup data store to memoize assets already downloaded.
@assets ||= @assets.presence || {}
# Return early from cache if already cached.
return @assets[url] if @assets[url].present?
asset = URI.open(url, "r:UTF-8", &:read)
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
result = "data:#{content_type};base64,#{Rack::Utils.escape(base64)}"
# Cache { url: result } to @assets hash for later requests to the same URL.
@assets[url] = result
result
rescue OpenURI::HTTPError => e
if e.message == '404 Not Found'
Rails.logger.debug "Missing file"
elsif e.message == '403 Forbidden'
Rails.logger.debug "Forbidden file"
else
Rails.logger.debug { "HTTP Error: #{e.message}" }
end
end
from wicked_pdf.
Have you tried to render the same image more than 18 times (have you tried to debug URI.read
return?)?
I've tried to render base64 images and it can render 500 easily.
from wicked_pdf.
Interesting follow up - I've been trying to work on this intermittently. A real-time render on a similar PDF on the site will do hundreds of images no problem. Only when it kicks to a background task does this happen. So somewhere in either the controller or the task, this is failing silently. There's nothing glaring in console (but it also runs by a mile a minute pulling everything in). I'm guessing something is breaking in the background task, and not with the image fetching itself.
from wicked_pdf.
Related Issues (20)
- Add support for --load-error-handling and --load-media-error-handling
- Remote asset returning non-200 response does not trigger an error
- Greek Character "𝛼" not showing correctly within PDF generated by Wicked PDF HOT 7
- Images won't load from Active Storage using Amazon S3 Bucket HOT 2
- version 2.7.0 breaks with webpacker
- Content is getting cropped in PDF
- ActionView::Template::Error uninitialized constant WickedPdf::WickedPdfHelper::Assets::SprocketsEnvironment::Sprockets HOT 3
- Feature Request: PDF/A-1
- pdf_from_url CSS not working HOT 1
- Raw PDF being rendered. HOT 1
- OpenStruct causes NameError in Rake13.2.0
- PDF is being rendered with raw ERB code HOT 4
- Content overlaps with the header layout
- RuntimeError on PDf Generation HOT 1
- wicked_pdf due to wkhtmltopdf not finding OpenSSL 1.1 despite installing over OpenSSL 3 HOT 7
- Remove usage of `OpenStruct` or add `ostruct` as dependency
- v2.8.0 causing ActionView::Template::Error: no implicit conversion of nil into String for first time in years HOT 7
- ArgumentError when changing the WickedPdf.config={...} to the new WickedPdf.configure.do |c| ... end HOT 1
- Error: PDF could not be generated! HOT 1
- Public assets not getting loaded after upgrade to Rails 7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wicked_pdf.