Move the collection logic from the document to the catalog
The `Collection` entry is part of the catalog, not of the document, so its logic should be placed there instead. The document should look in the catalog to fetch it, and not have knowledge of `catDict`, which is a member internal to the catalog. Moreover, remove the collection member from the document instance. It's only used internally and was also never intended to be public. For users it's exposed by the `getMetadata` API endpoint as `IsCollectionPresent`. Moving this out of the `parse` function makes sure that the getter is only executed if the document information is actually requested (potentially making initial parsing a tiny bit faster).
This commit is contained in:
parent
935d95b462
commit
b41a2f4d5a
@ -600,19 +600,6 @@ class PDFDocument {
|
||||
info("Cannot fetch AcroForm entry; assuming no AcroForms are present");
|
||||
this.acroForm = null;
|
||||
}
|
||||
|
||||
// Check if a Collection dictionary is present in the document.
|
||||
try {
|
||||
const collection = this.catalog.catDict.get("Collection");
|
||||
if (isDict(collection) && collection.size > 0) {
|
||||
this.collection = collection;
|
||||
}
|
||||
} catch (ex) {
|
||||
if (ex instanceof MissingDataException) {
|
||||
throw ex;
|
||||
}
|
||||
info("Cannot fetch Collection dictionary.");
|
||||
}
|
||||
}
|
||||
|
||||
get linearization() {
|
||||
@ -745,7 +732,7 @@ class PDFDocument {
|
||||
IsLinearized: !!this.linearization,
|
||||
IsAcroFormPresent: !!this.acroForm,
|
||||
IsXFAPresent: !!this.xfa,
|
||||
IsCollectionPresent: !!this.collection,
|
||||
IsCollectionPresent: !!this.catalog.collection,
|
||||
};
|
||||
|
||||
let infoDict;
|
||||
|
@ -84,6 +84,22 @@ class Catalog {
|
||||
return shadow(this, "version", version.name);
|
||||
}
|
||||
|
||||
get collection() {
|
||||
let collection = null;
|
||||
try {
|
||||
const obj = this.catDict.get("Collection");
|
||||
if (isDict(obj) && obj.size > 0) {
|
||||
collection = obj;
|
||||
}
|
||||
} catch (ex) {
|
||||
if (ex instanceof MissingDataException) {
|
||||
throw ex;
|
||||
}
|
||||
info("Cannot fetch Collection entry; assuming no collection is present.");
|
||||
}
|
||||
return shadow(this, "collection", collection);
|
||||
}
|
||||
|
||||
get metadata() {
|
||||
const streamRef = this.catDict.getRaw("Metadata");
|
||||
if (!isRef(streamRef)) {
|
||||
|
Loading…
Reference in New Issue
Block a user