Pdfkit: Transparency/Blend Support

Created on 15 Jan 2016  路  2Comments  路  Source: foliojs/pdfkit

The big limiting factor with all of the open-source PDF-writing libraries (f.e. PDFKit and libHaru) is that none of them support groups or transparency groups. Vector graphics involves layers and blending, referencing large amounts of geometry multiple times for blurs, and without this support, then you can't really export documents of significant complexity. Any plans to work on this? It's all in the 1.4 spec, so I anticipate I'll just have to implement it myself. It's rather daunting unless you understand the graphics stack well, since pushing a PDF group or transparency group resets some aspects of the stack.

feature

Most helpful comment

I implemented functions for groups: PDFGroup.js. Once a group is created content can be added inside it with the classic PDFKit functions. Groups can be drawn on the page or used as a mask.

However there are serious limitations

  1. Groups are only defined on the current page and don't work on the other pages
  2. All groups must be closed with the closeGroup function or the PDF document won't open
  3. It would be better and less confusing to have specific group.rect(), group.text()... functions rather than using doc.rect(), doc.text()... but it is a lot of work to implement

All 2 comments

I implemented functions for groups: PDFGroup.js. Once a group is created content can be added inside it with the classic PDFKit functions. Groups can be drawn on the page or used as a mask.

However there are serious limitations

  1. Groups are only defined on the current page and don't work on the other pages
  2. All groups must be closed with the closeGroup function or the PDF document won't open
  3. It would be better and less confusing to have specific group.rect(), group.text()... functions rather than using doc.rect(), doc.text()... but it is a lot of work to implement

in case anyone else is looking for that file, here's the archive link: https://github.com/alafr/SVG-to-PDFKit/blob/39c9faf32fd906bdac1eb7436fac600af54969de/PDFGroup.js

Was this page helpful?
0 / 5 - 0 ratings