在本地环境中,pdf已成功生成页眉。但在托管linux服务器环境pdf生成没有页眉和页脚。贝洛是我的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生成没有页眉和页脚。所以请帮我生成带页眉和页脚的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_header.html.erb
<div id="pdf-header">
<div class="logo">
<% if FileTest.exists?("#{RAILS_ROOT}/public/uploads/image/institute_logo.jpg") %>
<%= image_tag "#{request.protocol}#{request.host_with_port}/uploads/image/institute_logo.jpg" ,:width => "90", :height=>"85" %>
<% else %>
<div class="fed_logo">
<%= image_tag "#{request.protocol}#{request.host_with_port}/images/application/app_fedena_logo.jpg" ,:width => "90", :height=>"85" %>
</div>
<% end %>
</div>
<div class="header-content">
<p><%=Configuration.get_config_value('InstitutionName'); %></p>
<p><%=Configuration.get_config_value('InstitutionAddress'); %></p>
</div>
</div>
应用/视图/布局/ pdf_footer.html.erb
<div id="pdf-footer">
<%= t('signature') %>
</div>
注意* 以上代码在我的Windows开发环境中完美运行(即)使用页眉和页脚正确生成的PDF。 但是当我在Linux生产服务器上托管我的应用程序时,生成的PDF文件没有页眉和页脚。*
答案 0 :(得分:1)
将 .erb 放在文件名
的末尾:header => {:html => { :template=> 'layouts/pdf_header.html.erb'}},
:footer => {:html => { :template=> 'layouts/pdf_footer.html.erb'}}