Wicked pdf without rendering header / footer

I am using wicked_pdf to generate pdffrom htmlin my rails project. This is a rendering template, but I was not able to print the sections header/footer. Below is my code that only prints a templatesection

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 shows an error Failed to load PDF document, even a simple one WickedPdf.new.pdf_from_string('<html><body><h1>Hello There!</h1></body></html>')does not work.

I tried to use render_to_string_with_wicked_pdf, render_with_wicked_pdf, but did not succeed. My version of the Rails 3.2.19, wicked_pdfversion gem - 1.1.0and wkhtmltopdfversion wkhtmltopdf-0.13.0-alpha-7b36694_linux-trusty-amd64.deb. I also tried using the wkhtmltopdfversion 0.12.0.

My questions

  • Why is my implementation above not working?
  • Why pdf_from_stringdoesn’t work?

Any help is appreciated. Thank.

+4
1

wkhtmltopdf, qt, .

$ 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

:

$ wkhtmltopdf --version

:

wkhtmltopdf 0.12.4 (with patched qt)

:

$ wkhtmltopdf --footer-center 'footer' http://www.google.com google.pdf

wkhtmltoimage:

$ sudo update-alternatives --install /usr/local/bin/wkhtmltoimage wkhtmltoimage /usr/local/share/wkhtmltox/bin/wkhtmltoimage 1005

script : wkhtmltox

+4

Source: https://habr.com/ru/post/1666450/


All Articles