Skip to content

Explicitly define default value for CIDToGIDMap#1019

Merged
blikblum merged 1 commit into
foliojs:masterfrom
PadraigGalvin:define-font-mapping
Sep 4, 2019
Merged

Explicitly define default value for CIDToGIDMap#1019
blikblum merged 1 commit into
foliojs:masterfrom
PadraigGalvin:define-font-mapping

Conversation

@PadraigGalvin

@PadraigGalvin PadraigGalvin commented Sep 4, 2019

Copy link
Copy Markdown
Contributor

I'm using PDFKit to make PDF/A - 3B documents. Thanks to PDFKit's API it's not too difficult to do, but I've come across a minor issue which cannot be solved via the API.

What kind of change does this PR introduce?

CIDToGIDMap is an optional property of Type 2 CIDFonts with a default value of "Identity"1. However, the property is required by the PDF/A specification2. Defining this property does not change the behaviour of PDF 1.3 to 1.7 documents but does allow PDFKit to be used to generate valid PDF/A files.

  1. PDF 1.7 specification §9.7.4.1
  2. ISO 19005-3 clause 6.2.11.3 test 2

What is the current behavior?

CIDToGIDMap property is not set so viewers will presume "Identity" by default.

What is the new behavior?

CIDToGIDMap is property is explicitly set to "Identity".

Checklist:

  • Tests (preference for unit tests) - Unit tests run. Integration tests seem to be failing before change as all references are off by one. Results look okay otherwise.
  • Documentation - N/A
  • Update CHANGELOG.md - N/A? let me know if it's required for this minor change
  • Ready to be merged

This is my first PR so feedback is welcome.

Related to #369.

@blikblum blikblum merged commit 1228c25 into foliojs:master Sep 4, 2019
@PadraigGalvin PadraigGalvin deleted the define-font-mapping branch September 4, 2019 14:52
@sakarit-zz

sakarit-zz commented Sep 22, 2020

Copy link
Copy Markdown

@PadraigGalvin Can you please enlighten us how to create PDF/A-3b documents using PDFKit?

@PadraigGalvin

Copy link
Copy Markdown
Contributor Author

@sakarit you essentially just have to add some metadata and use a reduced feature set. Using a PDF validator can help figuring out if the features you are using are compatible with the spec or not.

I was able to gather bits and pieces from various libraries for other languages to put something together. Once you understand the spec it's not really that hard to do with PDFKit. Finding the info was the difficult part for me anyway!

Here is some sample code that should help: https://github.com/PadraigGalvin/pdfkit-pdfa-sample

@sakarit-zz

sakarit-zz commented Sep 29, 2020

Copy link
Copy Markdown

@PadraigGalvin Thank you. While I waited for your answer I figured it out by myself and ended up with a similar solution. :)

For anyone interested the above solution works and can be used to generate PDF/A-2b and PDF/A-3b documents since they are quite similar standards.

You can toggle between them by changing this part of the XMP metadata:

<pdfaid:part>3</pdfaid:part>

@PadraigGalvin

Copy link
Copy Markdown
Contributor Author

No problem @sakarit, glad to hear you solved it !

@walderich

Copy link
Copy Markdown

@PadraigGalvin Thanks for your demo code. I was able to successfully generate a PDF file PDF-A-3b-sample.pdf which correctly opens in the browser as well as my default PDF viewer (which claims it to be valid PDF/A-3b standard). But Acrobat Reader does not display any content. I also tried to validate the file (using the free 'verapdf' validator), but it throws an error (PDFParser::GetDictionary() invalid pdf dictonary). Did you get the same results, or did I do something wrong?

@PadraigGalvin

Copy link
Copy Markdown
Contributor Author

@walderich there seems to be a minor issue with your sample file compared to mine. The color profile name seems to be provided as an invalid reference instead of a string.

Here's your file:

/Info /sRGB IEC61966-2.1
/OutputConditionIdentifier /sRGB IEC61966-2.1

Here's what it should be:

/Info (sRGB IEC61966-2.1)
/OutputConditionIdentifier (sRGB IEC61966-2.1)

When creating PDF objects, PDFKit treats regular Javascript strings and instances of the string object differently. Regular strings are used as references and string objects are added as text. It's an easy trap to fall into, just make sure you are using new String() as shown below:

const refOutputIntent = doc.ref({
  Type: 'OutputIntent',
  S: 'GTS_PDFA1',
  Info: new String('sRGB IEC61966-2.1'),
  OutputConditionIdentifier: new String('sRGB IEC61966-2.1'),
  DestOutputProfile: refColorProfile,
});
refOutputIntent.end();

@walderich

Copy link
Copy Markdown

@PadraigGalvin Thanks a lot for your quick reply. I indeed removed the new operator as ESLint complained about it. But after getting my code working I didn't remember doing that. (I also wouldn't have thought it made a difference, really.)

This resolves my main issue as the PDF is now correctly displaying in Acrobat Reader. Thanks again!

@PadraigGalvin

Copy link
Copy Markdown
Contributor Author

You're welcome @walderich, I'm glad it helped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants