在本地开发环境(windows) pdf 中成功生成了 Css 样式。但是在托管 linux 服务器环境中生成的 pdf 没有应用 css 样式。下面是我的 wkhtmltopdf (WickedPdf) 配置
WickedPdf.config = {
#:wkhtmltopdf => "#{RAILS_ROOT}/pdfbin/wkhtmltopdf-amd64",
:exe_path => "/home/software/.gems/bin/wkhtmltopdf",
:layout => "layouts/pdf.html.erb",
:margin => { :top=> 40,
:bottom => 20,
:left=> 30,
:right => 30},
:header => {:html => { :template=> 'layouts/pdf_header.html.erb'}},
:footer => {:html => { :template=> 'layouts/pdf_footer.html.erb'}}
#:exe_path => '/usr/bin/wkhtmltopdf'
}
更多信息:
这是我的目录结构,我在 linux rails 托管 app\views\layouts 上,在布局内我有 pdf.html.erb 、 pdf_footer.html.erb 、 pdf_header.html.erb 上面的东西在我的本地 Windows 开发环境中完美运行,但在生产中生成的 pdf 没有样式。所以请大家帮我制作带有 CSS 样式的 pdf
应用程序/视图/布局/pdf.html.erb
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="<%= (rtl?) ? 'rtl' : 'ltr' %>">
<head>
<% @direction = (rtl?) ? 'rtl/' : '' %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<%= stylesheet_link_tag([@direction+'application', @direction+'_styles/ui.all'])%>
<%= stylesheet_link_tag(*get_stylesheets) %>
<%= stylesheet_link_tag @direction+"_layouts/pdf" %>
<link rel="stylesheet" type="text/css" href="<%="#{RAILS_ROOT}/public/stylesheets/#{@direction}_layouts/pdf.css" %>" media="all" />
<link rel="stylesheet" type="text/css" href="<%="#{RAILS_ROOT}/public/stylesheets/#{get_stylesheets}.css"%>" media="all" />
<link rel="stylesheet" type="text/css" href="<%= "#{RAILS_ROOT}/public/stylesheets/#{@direction}_styles/ui.all.css"%>" media="all" />
</head>
<body>
<%= yield %>
</body>
</html>
pdf.html.erb 包含用于呈现 pdf 的所有样式信息,在托管环境中,这些样式不是由 wkhtmltopdf 获取的。所以请大家帮帮我