3
votes

In local environment pdf with header footer generated successfully. but in hosting linux server environment pdf generated without header and footer.Below is my wkhtmltopdf (WickedPdf) config

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'
}

for additional info :

this is my dir structure i am on linux rails hosting app\views\layouts , inside layouts i am having pdf.html.erb , pdf_footer.html.erb , pdf_header.html.erb The above stuff works perfectly on my local windows development environment , but in production pdf generated without headers and footers.so guys please help me to produce pdf with headers and footers

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>

Note* The above codes working perfectly on my windows development environment (ie) PDF generated properly with header and footers. But when i hosted my application in linux production server PDF generated without headers and footers.*


Resolved Header Footer Issue , the above is the working code. The above problem is due to my files don't have enough executable permissions in production Linux environment.


1
Seems like a path issue. Are you sure the currently running process can find the headers and footers from a relative path? You might want to use an absolute path using Rails.root. - Casper
this is my dir structure i am on linux rails hosting app\views\layouts , inside layouts i am having pdf.html.erb , pdf_footer.html.erb , pdf_header.html.erb , i am new to ruby on rails , i am try to running an existing projects , i dont know how to refer these things in WickedPdf.config - Sam
i tried :layout => "#{RAILS_ROOT}/app/views/layouts/pdf.html", :header => {:html => { :template=> '#{RAILS_ROOT}/app/views/layouts/pdf_header.html'}}, :footer => {:html => { :template=> '#{RAILS_ROOT}/app/views/layouts/pdf_footer.html'}} but i got this error ActionView::MissingTemplate (Missing layout /home/software/rails_apps/saras/app/views/layouts/pdf.html in view path app/views:vendor/plugins/fckeditor/app/views:vendor/bundle/ruby/1.8/gems/declarative_authorization-0.5.1/app/views): vendor/bundle/ruby/1.8/gems/actionpack-2.3.5/lib/action_view/paths.rb:66:in `find_template' - Sam
Ok. Yeah that doesn't work. I checked WickedPdf and it seems it takes care of the rails paths itself. So you don't need Rails.root. Sorry about that. So something else must be wrong. - Casper
@user1402576 could you please check the same directly with the library i.e wkhtmltopdf instead of wickedpdf - Viren

1 Answers

1
votes

Put .erb at the end of filename

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