2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-04 03:10:52 +00:00

Fix isPagesObject and isPageObject

There are lots of things with /Kids that are not pages. Repair the
pages tree, then do a reliable check.
This commit is contained in:
Jay Berkenbilt 2021-02-20 19:16:40 -05:00
parent 3aefdd18a6
commit 05eb5826d8

View File

@ -3039,6 +3039,12 @@ bool
QPDFObjectHandle::isPageObject()
{
// See comments in QPDFObjectHandle.hh.
if (getOwningQPDF() == nullptr)
{
return false;
}
// getAllPages repairs /Type when traversing the page tree.
getOwningQPDF()->getAllPages();
if (! this->isDictionary())
{
return false;
@ -3066,8 +3072,16 @@ QPDFObjectHandle::isPageObject()
bool
QPDFObjectHandle::isPagesObject()
{
// Some PDF files have /Type broken on pages.
return (this->isDictionary() && this->hasKey("/Kids"));
if (getOwningQPDF() == nullptr)
{
return false;
}
// getAllPages repairs /Type when traversing the page tree.
getOwningQPDF()->getAllPages();
return (this->isDictionary() &&
this->hasKey("/Type") &&
this->getKey("/Type").isName() &&
this->getKey("/Type").getName() == "/Pages");
}
bool