3

ローカル環境では、ヘッダーフッター付きの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'
}

追加情報:

これは私のdir構造です。app\views\ layoutsをホストしているLinuxレール上にあり、レイアウト内には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環境でファイルに十分な実行可能権限がないことが原因です。


4

1 に答える 1

1

ファイル名の最後に.erbを置きます

:header => {:html => { :template=> 'layouts/pdf_header.html.erb'}},
:footer => {:html => { :template=> 'layouts/pdf_footer.html.erb'}}
于 2012-06-23T11:32:54.150 に答える