I am using wicked_pdf for generating pdf
from html
on my rails project. It is rendering template
but I could not manage to print header/footer
sections. Below is my code that print only template
section
render pdf: "pdf_name",
layout: 'application',
template: 'reports/show',
formats: [:html],
margin: { top: 10, bottom: 10, left: 10, right: 10 },
disable_javascript: true,
show_as_html: params[:debug],
header: {
html: { template: 'shared/header' },
spacing: 10
},
footer: {
html: { template: 'shared/footer' },
spacing: 30,
line: true
}
If I try to use WickedPdf.new.pdf_from_string render_to_string
it show Failed to load PDF document
error even simple WickedPdf.new.pdf_from_string('<html><body><h1>Hello There!</h1></body></html>')
does not work.
I have tried to use render_to_string_with_wicked_pdf, render_with_wicked_pdf
but did not success. My Rails version is 3.2.19
, wicked_pdf
gem version is 1.1.0
and wkhtmltopdf
version is wkhtmltopdf-0.13.0-alpha-7b36694_linux-trusty-amd64.deb
. I also tried to use wkhtmltopdf
version 0.12.0
.
My questions are
pdf_from_string
does not work?Any kind of help is appreciated. Thanks.
Use a version of wkhtmltopdf
built with patched qt, which properly works with footer and header.
$ wget http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
$ tar xf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
$ sudo mv wkhtmltox /usr/local/share/
$ sudo update-alternatives --install /usr/local/bin/wkhtmltopdf wkhtmltopdf /usr/local/share/wkhtmltox/bin/wkhtmltopdf 1005
check the version:
$ wkhtmltopdf --version
it should say:
wkhtmltopdf 0.12.4 (with patched qt)
test it:
$ wkhtmltopdf --footer-center 'footer' http://www.google.com google.pdf
you can also install the wkhtmltoimage:
$ sudo update-alternatives --install /usr/local/bin/wkhtmltoimage wkhtmltoimage /usr/local/share/wkhtmltox/bin/wkhtmltoimage 1005
you can use a script like this: wkhtmltox installer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With