gpt4 book ai didi

ruby-on-rails - ruby on rails(wkhtmltopdf 页眉页脚问题)

转载 作者:数据小太阳 更新时间:2023-10-29 08:09:59 26 4
gpt4 key购买 nike

在本地环境中成功生成页眉页脚的 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

app/views/layouts/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>

app/views/layouts/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>

app/views/layouts/pdf_footer.html.erb

<div id="pdf-footer">
<%= t('signature') %>
</div>

注意* 以上代码在我的 Windows 开发环境中运行良好(即)正确生成带有页眉和页脚的 PDF。 但是当我在 linux 生产服务器上托管我的应用程序时,生成的 PDF 没有页眉和页脚。*


已解决页眉页脚问题,以上是工作代码。以上问题是由于我的文件在生产Linux环境中没有足够的可执行权限。


最佳答案

.erb放在文件名的末尾

:header => {:html => { :template=> 'layouts/pdf_header.html.erb'}},
:footer => {:html => { :template=> 'layouts/pdf_footer.html.erb'}}

关于ruby-on-rails - ruby on rails(wkhtmltopdf 页眉页脚问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11167427/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com