Commit 05eb5826d8b8beb19e8ec65915af1476e7dd1db3
1 parent
3aefdd18
Fix isPagesObject and isPageObject
There are lots of things with /Kids that are not pages. Repair the pages tree, then do a reliable check.
Showing
1 changed file
with
16 additions
and
2 deletions
libqpdf/QPDFObjectHandle.cc
| @@ -3039,6 +3039,12 @@ bool | @@ -3039,6 +3039,12 @@ bool | ||
| 3039 | QPDFObjectHandle::isPageObject() | 3039 | QPDFObjectHandle::isPageObject() |
| 3040 | { | 3040 | { |
| 3041 | // See comments in QPDFObjectHandle.hh. | 3041 | // See comments in QPDFObjectHandle.hh. |
| 3042 | + if (getOwningQPDF() == nullptr) | ||
| 3043 | + { | ||
| 3044 | + return false; | ||
| 3045 | + } | ||
| 3046 | + // getAllPages repairs /Type when traversing the page tree. | ||
| 3047 | + getOwningQPDF()->getAllPages(); | ||
| 3042 | if (! this->isDictionary()) | 3048 | if (! this->isDictionary()) |
| 3043 | { | 3049 | { |
| 3044 | return false; | 3050 | return false; |
| @@ -3066,8 +3072,16 @@ QPDFObjectHandle::isPageObject() | @@ -3066,8 +3072,16 @@ QPDFObjectHandle::isPageObject() | ||
| 3066 | bool | 3072 | bool |
| 3067 | QPDFObjectHandle::isPagesObject() | 3073 | QPDFObjectHandle::isPagesObject() |
| 3068 | { | 3074 | { |
| 3069 | - // Some PDF files have /Type broken on pages. | ||
| 3070 | - return (this->isDictionary() && this->hasKey("/Kids")); | 3075 | + if (getOwningQPDF() == nullptr) |
| 3076 | + { | ||
| 3077 | + return false; | ||
| 3078 | + } | ||
| 3079 | + // getAllPages repairs /Type when traversing the page tree. | ||
| 3080 | + getOwningQPDF()->getAllPages(); | ||
| 3081 | + return (this->isDictionary() && | ||
| 3082 | + this->hasKey("/Type") && | ||
| 3083 | + this->getKey("/Type").isName() && | ||
| 3084 | + this->getKey("/Type").getName() == "/Pages"); | ||
| 3071 | } | 3085 | } |
| 3072 | 3086 | ||
| 3073 | bool | 3087 | bool |