javascript - Rails PDFKit wait for client side - Stack Overflow

I have successfully implemented PDFKit into my Rails application. But my application is mostly client s

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 pleted loaded, that's fine.

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 pleted loaded, that's fine.

Share Improve this question asked Sep 29, 2013 at 11:26 Remington GatesRemington Gates 731 silver badge4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

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
} 

You can tell pdfkit to wait until window.status JS variable gets a specific value.

PDFKit.new(
  ...,
  window_status: 'ready',
  ...
)

Thus within your javascript you can flag for PDFKit it's time to generate PDF by doing:

window.status = 'ready'

Simple as this :D

Not waiting more than needed. Not risking generating PDF before wished.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744143600a4560316.html

相关推荐

  • javascript - Rails PDFKit wait for client side - Stack Overflow

    I have successfully implemented PDFKit into my Rails application. But my application is mostly client s

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信