foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.92k stars 1.16k forks source link

Improve PDF/A compliance #1561

Open florianbepunkt opened 3 weeks ago

florianbepunkt commented 3 weeks ago

I had the need to implement Facture-x/ZUGFeRD compliant PDF for invoicing.

During this task I found two issues with PDFlib.

1. File attachments are not PDF/A3 compliant (maybe not PDF/A compliant at all).

When adding an attachment, the attachment needs an AFRelationship entry with one of the following values:

type Relationship = | 'Alternative'
      | 'Data'
      | 'Source'
      | 'Supplement'
      | 'Unspecified';

Also an AF entry in the catalog must be added.

Both points should not add issues for different subsets AFAIK, so the only harm would be an increased API surface when adding attachments (add an option to set the attachment relationship).

2. Font CIDSet generation

The CIDSet generation here https://github.com/foliojs/pdfkit/blob/2554c088ca1824119d77a27944eace83ed54d6b4/lib/font/embedded.js#L186 breaks PDF/A3 validation (probably A2 as well). It is only needed for A1 AFAIK, so it can be omitted for other subsets, which would make the resulting PDF compliant.

I have both features implemented in a downstream repo of React-pdf (which uses a fork), but I can port those changes and draft a PR, if this is worth merging. Both points are small in scope and should be backwards compatible.

blikblum commented 3 weeks ago

I have both features implemented in a downstream repo of React-pdf (which uses a fork), but I can port those changes and draft a PR, if this is worth merging. Both points are small in scope and should be backwards compatible.

Please open a PR with only these changes