prawn icon indicating copy to clipboard operation
prawn copied to clipboard

Support for embedded PDFs (e.g., for vectorial images)

Open gioele opened this issue 8 years ago • 3 comments

It would be nice if Prawn could embed existing PDFs files into the PDF being generated. In my particular case, this would be useful to embed drawings, logos and other kinds of vectorial images inside Prawn-generated PDFs.

Right now Prawn's #image does not support any kind of vectorial images, only two raster formats: JPEGs and PNGs. In LaTeX-land the common formats used for vectorial images are EPS and PDF (they are natively supported by includegraphics inside pdftex). SVGs are also very common in other settings (web pages, for instance).

It seems to me that supporting PDF would be easiest way to support vectorial images in prawn. Supporting EPS and SVG would require writing decoders or transcoders for these formats.

IIUC, Prawn used to support templates that could be used to embed PDFs, as suggested by @practicingruby in issue #91. This does not seem to be the case anymore.

Proof-of-concept code by @yob against an old (2012) version of Prawn can be found at https://github.com/yob/prawn/commits/pdf_images.

gioele avatar Apr 03 '17 19:04 gioele

@gioele Using PDFs as image format requires a PDF parser which Prawn doesn't have. However, Prawn can use the pdf-reader and prawn-templates gems for using PDFs as template for a page. Maybe this functionality could be reused for image support? @bvogel might know more about this.

gettalong avatar Apr 03 '17 19:04 gettalong

@gioele you can still use PDF-Templates via prawn-templates, however you are limited to one template per page and if you want to draw on top of the template it is recommended to fit the template size to the required page size. The code basically creates an additional content stream with the help of pdf-reader that sits in the background. The overall ramifications of this approach are above my level of understanding of the PDF specifications.

bvogel avatar Apr 04 '17 07:04 bvogel

There's a prawn-svg gem for embedding vector graphics.

pointlessone avatar Apr 04 '17 07:04 pointlessone

I'm calling out of scope for this request. There are prawn-eps and prawn-svg extensions maintained by wonderful people in the community. Those can be used to draw vector images in your documents.

pointlessone avatar Jan 16 '24 13:01 pointlessone