mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.52k stars 640 forks source link

Header won't rendered #1079

Open RawinCotactic opened 8 months ago

RawinCotactic commented 8 months ago

Issue description

There's a lot of issue I've face. for example

  1. I can't set margin in Controller but can set normally in wicked_pdf.rb in Initializer
  2. header won't show no matter where i set this option config in Controller or wicked_pdf.rb it won't even show in wkhtmltopdf command for example [wicked_pdf]: ["/Users/appleclub/.rbenv/versions/2.5.1/gemsets/leadcombo/bin/wkhtmltopdf", "--enable-local-file-access", "--lowquality", "--margin-top", "0.1", "--margin-bottom", "0.1", "--margin-left", "0.1", "--margin-right", "0.1", "file:////var/folders/h3/p73w345x36v093ff9xwh3zqh0000gn/T/wicked_pdf20231012-58597-1yy4e4p.html", "/var/folders/h3/p73w345x36v093ff9xwh3zqh0000gn/T/wicked_pdf_generated_file20231012-58597-l0ov39.pdf"]

this is what show in rails

Expected or desired behavior

  1. can set margin freely in controller so I can set for multiple pdf not default
  2. header show properly

System specifications

wicked_pdf gem version (output of cat Gemfile.lock | grep wicked_pdf): 2.7.0

wkhtmltopdf version (output of wkhtmltopdf --version): 0.12.6 (with patched qt)

whtmltopdf provider gem and version if one is used:

platform/distribution and version (e.g. Windows 10 / Ubuntu 16.04 / Heroku cedar): Mac OS

wicked_pdf.rb

WickedPdf.config = {
  margin: { top: 0.1, bottom: 0.1, left: 0.1, right: 0.1 },
  header: {html: { template: 'pdf/header.html.erb' } },
  enable_local_file_access: true,
  lowquality: true,
}
Rails.logger.debug("Wicked PDF Configuration: #{WickedPdf.config}")

pdf_controller

class PdfController < ApplicationController
    def pdf_detail
        id = params["id"].to_i
        @lead = CustomerLead.find(id)
        response.headers['Content-Disposition'] = "inline; filename=#{@lead.company.name} - #{@lead.full_name}(#{@lead.source_detail}).pdf"
        respond_to do |format|
        format.html
        format.pdf do
            render pdf: "pdfdetail",template: 'pdf/pdf_detail.html.erb' , disposition: 'inline' , layout: 'pdf.html.erb'
        end
        end
    end

end

app/view/pdf/header.html.erb

<!DOCTYPE html>
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
    <meta charset="utf-8"/>
    <style>
    .navbar {
    background: #0C276A;
    margin-bottom: 20px;
}
.com-head {
    color:white;
    font-size: 1.7rem;
    width: 50%;
    text-align:right;
}
.container-fluidn {
    display: -webkit-box; /* wkhtmltopdf uses this one */
    display: flex;
    -webkit-box-pack: justify; /* wkhtmltopdf uses this one */
    justify-content: space-between;
    -webkit-box-align: center;
    align-items: center;
    width:100%;
}
    </style>
  </head>
    <body style="height:100px;">
<div id="header">
      <nav class="navbar nav-bg-new">
                    <div class="container-fluidn">
                        <img class="lc-logo" src="/images/leadcombo-logo-2.png" target="_blank" style="height:70px;width:auto">
                        <div class="com-head"></div>
                    </div>
                </nav>
    </div>
  </body>
</html>