wicked_pdf: footer height/styling
You'll have to adjust the bottom margin of the PDF to make room for the footer if it is over a certain size.
respond_to do |format|
format.pdf do
render :pdf => 'some_pdf',
:margin => { :bottom => 30 },
:footer => { :html => { :template => 'pdfs/footer.pdf.erb' } }
end
end
or you can throw that margin value in your config/initializers/wicked_pdf.rb file if it is a site-wide thing.
Wicked_pdf setting footer height or margin on page by page basis
Unfortunately the solution is not straight forward. You would have to strip the pdf out to individual pages create a pdf of each page then stitch the pdfs back together. See this explanation
wicked_pdf footer not working
Just had this same issue, the problem seemed to be that my wkhtmltopdf install did not generate the footers as requested.
The version I had was installed via the Ubuntu repository, I un-installed this and downloaded a pre-built version as described here and now it works fine:
https://github.com/mileszs/wicked_pdf/wiki/Getting-Started-Installing-wkhtmltopdf
Wicked pdf not rendering footer
Try setting the margin:
format.pdf do
render pdf: 'document',
footer: { html: { template:"/document/_footer" },
margin: { top: 10, left: 20, bottom: 15, right: 20 }
end
Wicked PDF header not showing up
For anyone else reaching here... it was a CSS issue. The header was there but "invisible" and no matter what margin I set on the render options it was a CSS issue. After starting the CSS from scratch, the header appeared! I could not debug it with the flag show_as_html: true
because header and footer are not rendered in that mode, only the body.
If anyone reads this and happens to be in the same situation, use the search tool in the PDF document to find a word you know that's in the header. If it finds something but it's invisible, then you know you have a CSS problem.
Also don't forget to check if you included in the html of the header the <!DOCTYPE html>
. Thanks @joaolell for this.
Another thing to check, is that you have the version with patched qt of the wkhtmltopdf library (0.12.4 and above) that supports header and footer. Previous versions won't
wicked_pdf handlebars/mustache support
It should work.
WickedPdf merely hooks into the Rails 'render' method, so anything it can do, can be done with wicked_pdf.
wicked_pdf: Is it possible to have the header only show on the first page & the footer only on the last?
Some quick javascript can take care of this. Follow the boilerplate laid out under 'Footers And Headers' on wkhtmltopdf
These are your header and footer templates respectively.
The key variable to keep track of is 'page' which is available from URL hash.
Your header will look something like this:
<div class="headerContent" style="display:none">
...my awesome html
<hr />
</div>
<script type="text/javascript">
var headerCheck = function() {
var x=document.location.search.substring(1).split('&');
for (var i in x) {
if(x[i] == "page=1")
document.getElementsByClassName("headerContent")[0].style.display = "block";
}
}();
</script>
Similarly for your footer the code will look something like this:
<div class="footerContent" style="display: none">
...awesome footer html
</div>
<script type="text/javascript">
var footerCheck = function() {
var x=document.location.search.substring(1).split('&');
var currentPage = 1;
for (var i in x) {
var z=x[i].split('=',2);
if(z[0] == "page")
currentPage = unescape(z[1]);
if(z[0] == "topage" && currentPage == unescape(z[1]))
document.getElementsByClassName("footerContent")[0].style.display = "block";
}
}();
</script>
Related Topics
How to Remove the Zone from a Datetime Value
Another Way Instead of Escaping Regex Patterns
How to Populate an Array with Random Numbers
Ruby on Rails Activerecord Scopes VS Class Methods
Rails 4: How to Upload Files with Ajax
How to Force Rails to Load All Models
Devise Not Displaying Error Messge During an Authentication Failure
Positive Lookahead Doesn't Stop at First Occurrence
(New to Rails) Rails Server Error: Cannot Load Such File -- Bootsnap/Setup (Loaderror)
Getting Current Line of Code in Ruby
Automatic Associations in Ruby on Rails Fixtures
Why Does Hash.New({}) Hide Hash Members
Bundle Install/Error in Installing Libv8 (3.3.10.4) on Rails (Running on Lion)
Thor & Yaml Outputting as Binary
Understanding Ruby Splat in Ranges and Arrays