Studiosity / grover

A Ruby gem to transform HTML into PDFs, PNGs or JPEGs using Google Puppeteer/Chromium

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Print HTML on PDF Template

pichutan opened this issue · comments

Dear Community,

With prawn it was possible that we can load a pdf template (e.g. a customer can upload his writing paper) and we print bills over it.

Is there a possibility to do it with Grover too?

Thank you!

Torsten

Good question, but I'm not sure (I don't believe so). Grover uses Puppeteer/Chrome to render the HTML content and as far as I'm aware there is no way to set the background of a page to be a PDF. Having said that, I see two options that should work:

  1. take a look at the combine_pdf gem. It's already a dependency of grover for adding cover pages etc.. however it also supports page "stamp/watermarking". See https://github.com/boazsegev/combine_pdf#add-content-to-existing-pages-stamp--watermark and I'm pretty sure that will do exactly what you're asking.
  2. you convert the PDF to an image, then set your page background to that image, then export.. could be a bit sketchy to align things, but should work as an alternative to the above option.

Although, I'm not sure what the security implications of either of these options might be. ie it may be possible to craft a specially formed PDF (or similar) document that is able to escape out of the conversion process (either PDF -> image or within combine_pdf). This would of course require those PDF handling libraries to have some sort of vulnerability.. Not saying you shouldn't do it.. but i'd want to be exceptionally careful when accepting then processing anything from the big bad world that you can't easily sanitise! 😬