Make pdf-lib more graceful like other pdf software #1407
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some broken fields may include annotations in their Kids array that couldn't be found on any pages. Up until now we've been throwing an exception when dealing with such fields. But it appears that other PDF software are more resilient to this and gracefully ignore them.
This commit ensures we'll do the same.
Fixes #967,#1281,#1349
What?
PDF Fields can have
Kids
in them, eachKid
being aWidgetAnnotation
. In some rare cases (probably due to bad pdf generators) there are cases that there is aPDFField
with a an annotation in itKids
but that annotation doesn't exist on any page. Therefore we don't know on which page it must be rendered.Why?
PDFForm.findPageForAnnotationRe
is responsible for finding the page for a given annotation. Up until now it'd throw an exception if it couldn't find a page.This means when trying to flatten such PDF's, pdf-lib would throw an error. So basically you have a pdf file that can be opened up with Chrome, Firefox/pdfjs, Acrobat Reader and even pdf-lib. But trying to flatten it using pdf-lib would cause an exception (as seen in #967,#1281,#1349)
How?
This patch makes pdf-lib's Flatten gracefully ignore such cases and render the PDF like other pdf readers.
Testing?
Checklist