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, each Kid being a WidgetAnnotation. In some rare cases (probably due to bad pdf generators) there are cases that there is a PDFField with a an annotation in it Kids 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.
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