Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails PDFKit wait for client side

I have successfully implemented PDFKit into my Rails application. But my application is mostly client side. I have lots of javascript widgets and it takes around 3 seconds for all of them to load. When I generate the pdf I can see some of the widgets have loaded, some are in the process of loading, and others have not loaded at all.

Is there some way to work around this? It doesn't have to be too fancy. If I can delay the PDF generation for 5 seconds, until the page has completed loaded, that's fine.

like image 268
Remington Gates Avatar asked Sep 29 '13 11:09

Remington Gates


Video Answer


1 Answers

PDFKit uses wkhtmltopdf to generate the pdfs based on a webkit render of the page. There is a --javascript-delay params that looks like it could be used to delay the generation for the client side to finish.

Try this in pdfkit.rb

config.default_options = {
  :javascript_delay => 5000
} 
like image 153
Carlos Cervantes Avatar answered Oct 10 '22 10:10

Carlos Cervantes