mileszs / wicked_pdf

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

Slow load #112

Closed bcackerman closed 12 years ago

bcackerman commented 12 years ago

My pdf generation process takes about 10 seconds. How can I speed this up? Because in Heroku it times out.

I'm pulling css and a few images into the pdf fyi.

unixmonkey commented 12 years ago

@bcackerman How much quicker is it without the images and css? Are the images/css remote, or part of your app? I've never heard of it taking that long.

bcackerman commented 12 years ago

Yeah i found you need 2 web dynos to run it smoothly with resources.

Thanks, Bruce Ackerman www.bruceackerman.com

On Mon, May 7, 2012 at 5:05 PM, David Jones < reply@reply.github.com

wrote:

@bcackerman How much quicker is it without the images and css? Are the images/css remote, or part of your app? I've never heard of it taking that long.


Reply to this email directly or view it on GitHub: https://github.com/mileszs/wicked_pdf/issues/112#issuecomment-5562098

bcackerman commented 12 years ago

It only helps a bit actually

kaluznyo commented 12 years ago

Hi, This is very slow for me. To generate one page PDF, it's about 10 seconde. I generate like this : In my model :

   def create_viewer
      viewer = ActionView::Base.new(Rails.configuration.paths['app/views'].first)
      viewer.extend ApplicationHelper
      viewer
    end

 html = create_viewer.render(
        partial: 'pdfs/return_slip',
        locals: {:return_slip => return_slip, lang: lang}
      )
      generate(html, lang, return_slip.date.year)

Then generate is :

   def generate(html, lang=:fr, year=Date.today.year)
      lang ||= 'fr'
      WickedPdf.new.pdf_from_string(
        html,
        {
          :orientation => 'Portrait',
          :page_size => 'A4',
          :dpi => 300,
          :footer => {:html => {:url => "#{PDF_HOST}/bill/#{year < 2012 ? 'before_2012_' : '' }footer_#{lang}.html"}},
          :margin => {
            :top => 15,
            :right => 5,
            :bottom => 15,
            :left => 5
          }
        }
      )
    end

My view is composed of some texte, table, 2 images.

If delete this line (style) in my view : <%= wicked_pdf_stylesheet_link_tag 'pdfs' %> And it's 2 time faster.

I don't know if your gem is normaly slower than prawn (but very faster in coding time ;) )

unixmonkey commented 12 years ago

What version of WickedPdf and Rails? If you look at lib/wicked_pdf_helper.rb you can see that different things happen based on if you are using the asset pipeline. Try making your own helper or try to inline the css in that stylesheet and see if it improves performance any, and please report back.

jfrux commented 11 years ago

+1

mileszs commented 11 years ago

Speeding up your specific instance is pretty subjective. Perhaps you could tell us more about what you're doing?

You might also consider pushing PDF generation to the background, using DelayedJob, or some other job queue. PDF generation is very often going to take longer than most users are willing to wait.

On Fri, Mar 1, 2013 at 4:04 PM, Joshua Rountree notifications@github.comwrote:

+1

— Reply to this email directly or view it on GitHubhttps://github.com/mileszs/wicked_pdf/issues/112#issuecomment-14311291 .

jfrux commented 11 years ago

It was the wkhtmltopdf 0.11 rc2 issue… I just moved back to 0.9.9 and it's fine now.

Sorry for bringing up a dead issue!

:P On Mar 1, 2013, at 4:20 PM, Miles Z. Sterrett notifications@github.com wrote:

Speeding up your specific instance is pretty subjective. Perhaps you could tell us more about what you're doing?

You might also consider pushing PDF generation to the background, using DelayedJob, or some other job queue. PDF generation is very often going to take longer than most users are willing to wait.

On Fri, Mar 1, 2013 at 4:04 PM, Joshua Rountree notifications@github.comwrote:

+1

— Reply to this email directly or view it on GitHubhttps://github.com/mileszs/wicked_pdf/issues/112#issuecomment-14311291 .

— Reply to this email directly or view it on GitHub.

HuzaifaSaifuddin commented 6 years ago

Nothing has worked for me so far...wicked_pdf takes almost 3 seconds to just load an empty pdf view...Is there no way around?? Please help it chokes my server if multiple print requests are placed

wicked_pdf 1.1 wkhtmltopdf-binary-edge 0.12.3.0

unixmonkey commented 6 years ago

@HuzaifaSaifuddin WickedPDF isn't exactly fast, it has to pre-render your html, the pass it to the wkhtmltopdf binary, which boots up a headless webkit browser that essentially paints your HTML and JS to the screen and does a "print to pdf" back to a tempfile which gets re-read and sent to the browser. On my dev machine (touchbar Macbook Pro), it takes about 2 seconds to render this:

WickedPdf.new.pdf_from_string('<doctype html><html><head><title>Hello</title></head><body><h1>Hello</h1></body></html>')

If performance is a primary concern, you may want to try either rendering your PDFs in a background job, and delivering them via email, or evaluate switching to Princely, which uses PrinceXML as it's HTML-to-PDF engine. Be aware Princely is quite costly, but could be worth it for your business.

Other than that, Prawn is much more performant, and gives you a high degree of control over authoring your documents, but you cannot use HTML, CSS, & Javascript to build them. I suggest giving that a look.