Giter Site home page Giter Site logo

Comments (3)

unixmonkey avatar unixmonkey commented on August 27, 2024 1

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.

dmitry avatar dmitry commented on August 27, 2024

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.

jathayde avatar jathayde commented on August 27, 2024

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)

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.