Update PDFDocument._getLinearizationPage
to do the /Type-check correctly (PR 14400 follow-up)
I forgot about this in PR 14400, since we should obviously be consistent *and* given that the existing check is actually wrong; sorry about this!
This commit is contained in:
parent
b99927e1ee
commit
a20393e6e4
@ -1264,7 +1264,7 @@ class PDFDocument {
|
||||
}
|
||||
|
||||
async _getLinearizationPage(pageIndex) {
|
||||
const { catalog, linearization } = this;
|
||||
const { catalog, linearization, xref } = this;
|
||||
if (
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||
@ -1277,22 +1277,25 @@ class PDFDocument {
|
||||
|
||||
const ref = Ref.get(linearization.objectNumberFirst, 0);
|
||||
try {
|
||||
const obj = await this.xref.fetchAsync(ref);
|
||||
const obj = await xref.fetchAsync(ref);
|
||||
// Ensure that the object that was found is actually a Page dictionary.
|
||||
if (
|
||||
isDict(obj, "Page") ||
|
||||
(isDict(obj) && !obj.has("Type") && obj.has("Contents"))
|
||||
) {
|
||||
if (ref && !catalog.pageKidsCountCache.has(ref)) {
|
||||
catalog.pageKidsCountCache.put(ref, 1); // Cache the Page reference.
|
||||
if (obj instanceof Dict) {
|
||||
let type = obj.getRaw("Type");
|
||||
if (type instanceof Ref) {
|
||||
type = await xref.fetchAsync(type);
|
||||
}
|
||||
if (isName(type, "Page") || (!obj.has("Type") && !obj.has("Kids"))) {
|
||||
if (ref && !catalog.pageKidsCountCache.has(ref)) {
|
||||
catalog.pageKidsCountCache.put(ref, 1); // Cache the Page reference.
|
||||
}
|
||||
return [obj, ref];
|
||||
}
|
||||
return [obj, ref];
|
||||
}
|
||||
throw new FormatError(
|
||||
"The Linearization dictionary doesn't point to a valid Page dictionary."
|
||||
);
|
||||
} catch (reason) {
|
||||
info(reason);
|
||||
warn(`_getLinearizationPage: "${reason.message}".`);
|
||||
return catalog.getPageDict(pageIndex);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user