Finally, after 3 days of searching, traces and errors, I found a solution for this
First of all, I have to use wicked_pdf, not pdfkit, because the first provides two important helper functions
wicked_pdf_stylesheet_link_tag wicked_pdf_javascript_include_tag
then I have to use these two helpers to include a stylesheet and javascript like
<%= wicked_pdf_stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= wicked_pdf_javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= javascript_include_tag "http://www.google.com/jsapi"%> <%= wicked_pdf_javascript_include_tag 'chartkick'%>
The difference between javascript_include_tag and wicked_pdf_javascript_include_tag is that the latter will write all the original java code to the html file. This is important because wkhtmltopdf, the core of wicked_pdf, does not know where to find js and css assets. These assets are located in some place, for example / usr / local / lib / ruby ββ/ gems / 2.1.0 / gems / (you may have something else), but only your rails application knows where it is
note that for
<%= javascript_include_tag "http://www.google.com/jsapi"%>
you cannot and do not need wicked_pdf_javascript_include_tag.
The most important thing here. wicked_pdf (as well as pdfkit) will instruct you to install the gem wkhtmltopdf-binary, which has the latest version 0.9.9, and then just call something like this
format.pdf {render pdf :"test",layout:'application',template:'stinfos/testpage.html.erb'}
to create pdf. This ONLY works for html without a chart or high performance component. In the created PDF file, the chart or high-risk figures will be displayed only as "download"
To solve this problem, you need to remove the wkhtmltopdf binary pearls by running
gem uninstall wkhtmltopdf-binary
in rails root directory
Then download the latest version of wkhtmltopdf from http://wkhtmltopdf.org/downloads.html
the precompiled version http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-trusty-amd64.deb works for me
and install
dpkg -i wkhtmltox-0.12.1_linux-trusty-amd64.deb
Most likely it will be located here / usr / local / bin / wkhtmltopdf
If not, change config / initializers / wicked_pdf.rb
:exe_path => '/yourpath/wkhtmltopdf'
Then add javascript_delay: 2000 to .pdf format
format.pdf {render pdf:"test",javascript_delay:2000, layout:'application',template:'stinfos/testpage.html.erb'}
Then you should see that the chart numbers are displayed in pdf format. If not, use a longer delay time.
Please note that the javascript_delay option is not available for wkhtmlpdf below version 0.10