How to download css to pdf using wicked_pdf

For my rails 4 application, I want to convert html and Css to a PDF file. I use wkhtmltopdf and wicked_pdf gem if I use an evil helper, it does not show css, but it only displays text

in my controller i:

respond_to do |format| format.html format.pdf do render :pdf => "#{@card.name}", :template => 'cards/show.html.slim', :page_size => "A4", :disposition => 'attachment' 

And in show.html.slim

  = link_to "Download PDF", :action => "show", :format => :pdf 

aplication.html.erb

 <%= wicked_pdf_stylesheet_link_tag "pdf" -%> <%= wicked_pdf_stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= wicked_pdf_javascript_include_tag "application", "data-turbolinks-track" => true %> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> 
+6
source share
1 answer
 <%= wicked_pdf_stylesheet_link_tag "css_file_name" -%> 

this is the css file name you should have in the app/assets/stylesheets/ directory

 <%= wicked_pdf_stylesheet_link_tag "css_file_name" -%> <%= wicked_pdf_stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= wicked_pdf_javascript_include_tag "application", "data-turbolinks-track" => true %> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> 

Hope this can help you.

+8
source

Source: https://habr.com/ru/post/979294/


All Articles