Add a wrapper for the new xref in order to be able to get some values from cloned dictionaries
This commit is contained in:
parent
37f4712f7e
commit
65881f0e21
@ -52,6 +52,16 @@ class DocumentData {
|
||||
}
|
||||
}
|
||||
|
||||
class XRefWrapper {
|
||||
constructor(entries) {
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
fetch(ref) {
|
||||
return ref instanceof Ref ? this.entries[ref.num] : ref;
|
||||
}
|
||||
}
|
||||
|
||||
class PDFEditor {
|
||||
constructor({ useObjectStreams = true, title = "", author = "" } = {}) {
|
||||
this.hasSingleFile = false;
|
||||
@ -59,6 +69,7 @@ class PDFEditor {
|
||||
this.oldPages = [];
|
||||
this.newPages = [];
|
||||
this.xref = [null];
|
||||
this.xrefWrapper = new XRefWrapper(this.xref);
|
||||
this.newRefCount = 1;
|
||||
[this.rootRef, this.rootDict] = this.newDict;
|
||||
[this.infoRef, this.infoDict] = this.newDict;
|
||||
@ -173,9 +184,11 @@ class PDFEditor {
|
||||
let dict;
|
||||
if (obj instanceof BaseStream) {
|
||||
({ dict } = obj = obj.getOriginalStream().clone());
|
||||
dict.xref = this.xrefWrapper;
|
||||
} else if (obj instanceof Dict) {
|
||||
if (mustClone) {
|
||||
obj = obj.clone();
|
||||
obj.xref = this.xrefWrapper;
|
||||
}
|
||||
dict = obj;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user