对于我的rails 4应用程序,我想将html和Css转换为pdf文件。 我使用wkhtmltopdf和wicked_pdf gem 如果我使用邪恶的助手它不显示css但它只渲染文本
在我的控制器里我有:
respond_to do |format|
format.html
format.pdf do
render :pdf => "#{@card.name}",
:template => 'cards/show.html.slim',
:page_size => "A4",
:disposition => 'attachment'
在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>
答案 0 :(得分:9)
<%= wicked_pdf_stylesheet_link_tag "css_file_name" -%>
这是 app/assets/stylesheets/
目录中必须包含的css文件名
<%= 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>
希望这可以帮到你。