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 {
|
class PDFEditor {
|
||||||
constructor({ useObjectStreams = true, title = "", author = "" } = {}) {
|
constructor({ useObjectStreams = true, title = "", author = "" } = {}) {
|
||||||
this.hasSingleFile = false;
|
this.hasSingleFile = false;
|
||||||
@ -59,6 +69,7 @@ class PDFEditor {
|
|||||||
this.oldPages = [];
|
this.oldPages = [];
|
||||||
this.newPages = [];
|
this.newPages = [];
|
||||||
this.xref = [null];
|
this.xref = [null];
|
||||||
|
this.xrefWrapper = new XRefWrapper(this.xref);
|
||||||
this.newRefCount = 1;
|
this.newRefCount = 1;
|
||||||
[this.rootRef, this.rootDict] = this.newDict;
|
[this.rootRef, this.rootDict] = this.newDict;
|
||||||
[this.infoRef, this.infoDict] = this.newDict;
|
[this.infoRef, this.infoDict] = this.newDict;
|
||||||
@ -173,9 +184,11 @@ class PDFEditor {
|
|||||||
let dict;
|
let dict;
|
||||||
if (obj instanceof BaseStream) {
|
if (obj instanceof BaseStream) {
|
||||||
({ dict } = obj = obj.getOriginalStream().clone());
|
({ dict } = obj = obj.getOriginalStream().clone());
|
||||||
|
dict.xref = this.xrefWrapper;
|
||||||
} else if (obj instanceof Dict) {
|
} else if (obj instanceof Dict) {
|
||||||
if (mustClone) {
|
if (mustClone) {
|
||||||
obj = obj.clone();
|
obj = obj.clone();
|
||||||
|
obj.xref = this.xrefWrapper;
|
||||||
}
|
}
|
||||||
dict = obj;
|
dict = obj;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user