@adnsistemas/pdf-lib 2.9.0 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cjs/api/PDFDocument.d.ts.map +1 -1
- package/cjs/api/PDFDocument.js +4 -6
- package/cjs/api/PDFDocument.js.map +1 -1
- package/cjs/core/PDFContext.d.ts.map +1 -1
- package/cjs/core/PDFContext.js +30 -20
- package/cjs/core/PDFContext.js.map +1 -1
- package/cjs/core/objects/PDFDict.d.ts.map +1 -1
- package/cjs/core/objects/PDFDict.js +19 -14
- package/cjs/core/objects/PDFDict.js.map +1 -1
- package/dist/pdf-lib.esm.js +53 -40
- package/dist/pdf-lib.esm.js.map +1 -1
- package/dist/pdf-lib.esm.min.js +2 -2
- package/dist/pdf-lib.esm.min.js.map +1 -1
- package/dist/pdf-lib.js +53 -40
- package/dist/pdf-lib.js.map +1 -1
- package/dist/pdf-lib.min.js +3 -3
- package/dist/pdf-lib.min.js.map +1 -1
- package/es/api/PDFDocument.d.ts.map +1 -1
- package/es/api/PDFDocument.js +4 -6
- package/es/api/PDFDocument.js.map +1 -1
- package/es/core/PDFContext.d.ts.map +1 -1
- package/es/core/PDFContext.js +30 -20
- package/es/core/PDFContext.js.map +1 -1
- package/es/core/objects/PDFDict.d.ts.map +1 -1
- package/es/core/objects/PDFDict.js +20 -15
- package/es/core/objects/PDFDict.js.map +1 -1
- package/package.json +1 -1
- package/src/api/PDFDocument.ts +7 -8
- package/src/core/PDFContext.ts +30 -23
- package/src/core/objects/PDFDict.ts +28 -16
package/dist/pdf-lib.esm.js
CHANGED
|
@@ -8674,34 +8674,39 @@ class PDFDict extends PDFObject {
|
|
|
8674
8674
|
constructor(map, context) {
|
|
8675
8675
|
super();
|
|
8676
8676
|
this.suppressEncryption = false;
|
|
8677
|
-
this.dict = map;
|
|
8677
|
+
this.dict = new Map(Array.from(map.entries()).map((entry) => [entry[0].toString(), entry]));
|
|
8678
8678
|
this.context = context;
|
|
8679
8679
|
}
|
|
8680
8680
|
keys() {
|
|
8681
|
-
return Array.from(this.dict.
|
|
8681
|
+
return Array.from(this.dict.values()).map((value) => value[0]);
|
|
8682
8682
|
}
|
|
8683
8683
|
values() {
|
|
8684
|
-
return Array.from(this.dict.values());
|
|
8684
|
+
return Array.from(this.dict.values()).map((value) => value[1]);
|
|
8685
8685
|
}
|
|
8686
8686
|
entries() {
|
|
8687
|
-
return Array.from(this.dict.
|
|
8687
|
+
return Array.from(this.dict.values());
|
|
8688
8688
|
}
|
|
8689
8689
|
set(key, value) {
|
|
8690
8690
|
this.registerChange();
|
|
8691
|
-
this.dict.set(key, value);
|
|
8691
|
+
this.dict.set(key.asString(), [key, value]);
|
|
8692
8692
|
}
|
|
8693
8693
|
get(key,
|
|
8694
8694
|
// TODO: `preservePDFNull` is for backwards compatibility. Should be
|
|
8695
8695
|
// removed in next breaking API change.
|
|
8696
8696
|
preservePDFNull = false) {
|
|
8697
|
-
|
|
8698
|
-
if (value === PDFNull$1 && !preservePDFNull)
|
|
8697
|
+
if (!key.asString)
|
|
8699
8698
|
return undefined;
|
|
8700
|
-
|
|
8699
|
+
const value = this.dict.get(key.asString());
|
|
8700
|
+
if (!value ||
|
|
8701
|
+
(isPDFInstance(value[1], PDFClasses.PDFNull) && !preservePDFNull))
|
|
8702
|
+
return undefined;
|
|
8703
|
+
return value[1];
|
|
8701
8704
|
}
|
|
8702
8705
|
has(key) {
|
|
8703
|
-
|
|
8704
|
-
|
|
8706
|
+
if (!key.asString)
|
|
8707
|
+
return false;
|
|
8708
|
+
const value = this.dict.get(key.asString());
|
|
8709
|
+
return value !== undefined && !isPDFInstance(value[1], PDFClasses.PDFNull);
|
|
8705
8710
|
}
|
|
8706
8711
|
lookupMaybe(key, ...types) {
|
|
8707
8712
|
// TODO: `preservePDFNull` is for backwards compatibility. Should be
|
|
@@ -8710,7 +8715,7 @@ class PDFDict extends PDFObject {
|
|
|
8710
8715
|
const value = this.context.lookupMaybe(this.get(key, preservePDFNull),
|
|
8711
8716
|
// @ts-ignore
|
|
8712
8717
|
...types);
|
|
8713
|
-
if (value
|
|
8718
|
+
if (isPDFInstance(value, PDFClasses.PDFNull) && !preservePDFNull)
|
|
8714
8719
|
return undefined;
|
|
8715
8720
|
return value;
|
|
8716
8721
|
}
|
|
@@ -8721,16 +8726,16 @@ class PDFDict extends PDFObject {
|
|
|
8721
8726
|
const value = this.context.lookup(this.get(key, preservePDFNull),
|
|
8722
8727
|
// @ts-ignore
|
|
8723
8728
|
...types);
|
|
8724
|
-
if (value
|
|
8729
|
+
if (isPDFInstance(value, PDFClasses.PDFNull) && !preservePDFNull)
|
|
8725
8730
|
return undefined;
|
|
8726
8731
|
return value;
|
|
8727
8732
|
}
|
|
8728
8733
|
delete(key) {
|
|
8729
8734
|
this.registerChange();
|
|
8730
|
-
return this.dict.delete(key);
|
|
8735
|
+
return this.dict.delete(key.asString());
|
|
8731
8736
|
}
|
|
8732
8737
|
asMap() {
|
|
8733
|
-
return new Map(this.dict);
|
|
8738
|
+
return new Map(this.dict.values());
|
|
8734
8739
|
}
|
|
8735
8740
|
/** Generate a random key that doesn't exist in current key set */
|
|
8736
8741
|
uniqueKey(tag = '') {
|
|
@@ -9257,18 +9262,18 @@ class PDFContext {
|
|
|
9257
9262
|
}
|
|
9258
9263
|
assign(ref, object) {
|
|
9259
9264
|
if (this.preserveObjectsVersions) {
|
|
9260
|
-
const prevOV = this.indirectObjects.get(ref);
|
|
9265
|
+
const prevOV = this.indirectObjects.get(ref.toString());
|
|
9261
9266
|
if (prevOV) {
|
|
9262
|
-
const prevList = this.objectsPreviousVersions.get(ref);
|
|
9267
|
+
const prevList = this.objectsPreviousVersions.get(ref.toString());
|
|
9263
9268
|
if (!prevList) {
|
|
9264
|
-
this.objectsPreviousVersions.set(ref, [prevOV]);
|
|
9269
|
+
this.objectsPreviousVersions.set(ref.toString(), [prevOV[1]]);
|
|
9265
9270
|
}
|
|
9266
9271
|
else {
|
|
9267
|
-
prevList.unshift(prevOV);
|
|
9272
|
+
prevList.unshift(prevOV[1]);
|
|
9268
9273
|
}
|
|
9269
9274
|
}
|
|
9270
9275
|
}
|
|
9271
|
-
this.indirectObjects.set(ref, object);
|
|
9276
|
+
this.indirectObjects.set(ref.toString(), [ref, object]);
|
|
9272
9277
|
if (ref.objectNumber > this.largestObjectNumber) {
|
|
9273
9278
|
this.largestObjectNumber = ref.objectNumber;
|
|
9274
9279
|
}
|
|
@@ -9289,27 +9294,32 @@ class PDFContext {
|
|
|
9289
9294
|
if (this.snapshot)
|
|
9290
9295
|
this.snapshot.markDeletedRef(ref);
|
|
9291
9296
|
if (this.preserveObjectsVersions) {
|
|
9292
|
-
const object = this.indirectObjects.get(ref);
|
|
9297
|
+
const object = this.indirectObjects.get(ref.toString());
|
|
9293
9298
|
if (object) {
|
|
9294
9299
|
// check is not already deleted
|
|
9295
|
-
const verlist = this.objectsPreviousVersions.get(ref);
|
|
9300
|
+
const verlist = this.objectsPreviousVersions.get(ref.toString());
|
|
9296
9301
|
if (verlist) {
|
|
9297
|
-
verlist.unshift(object);
|
|
9302
|
+
verlist.unshift(object[1]);
|
|
9298
9303
|
}
|
|
9299
9304
|
else {
|
|
9300
|
-
this.objectsPreviousVersions.set(ref, [object]);
|
|
9305
|
+
this.objectsPreviousVersions.set(ref.toString(), [object[1]]);
|
|
9301
9306
|
}
|
|
9302
9307
|
}
|
|
9303
9308
|
}
|
|
9304
|
-
return this.indirectObjects.delete(ref);
|
|
9309
|
+
return this.indirectObjects.delete(ref.toString());
|
|
9305
9310
|
}
|
|
9306
9311
|
lookupMaybe(ref, ...types) {
|
|
9307
9312
|
// TODO: `preservePDFNull` is for backwards compatibility. Should be
|
|
9308
9313
|
// removed in next breaking API change.
|
|
9309
9314
|
const preservePDFNull = types.includes(PDFNull$1);
|
|
9310
|
-
|
|
9311
|
-
|
|
9312
|
-
|
|
9315
|
+
let result;
|
|
9316
|
+
if (isPDFInstance(ref, PDFClasses.PDFRef)) {
|
|
9317
|
+
const iobj = this.indirectObjects.get(ref.toString());
|
|
9318
|
+
result = iobj ? iobj[1] : undefined;
|
|
9319
|
+
}
|
|
9320
|
+
else {
|
|
9321
|
+
result = ref;
|
|
9322
|
+
}
|
|
9313
9323
|
if (!result ||
|
|
9314
9324
|
(isPDFInstance(result, PDFClasses.PDFNull) && !preservePDFNull))
|
|
9315
9325
|
return undefined;
|
|
@@ -9324,9 +9334,14 @@ class PDFContext {
|
|
|
9324
9334
|
throw new UnexpectedObjectTypeError(types, result);
|
|
9325
9335
|
}
|
|
9326
9336
|
lookup(ref, ...types) {
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9337
|
+
let result;
|
|
9338
|
+
if (isPDFInstance(ref, PDFClasses.PDFRef)) {
|
|
9339
|
+
const iobj = this.indirectObjects.get(ref.toString());
|
|
9340
|
+
result = iobj ? iobj[1] : undefined;
|
|
9341
|
+
}
|
|
9342
|
+
else {
|
|
9343
|
+
result = ref;
|
|
9344
|
+
}
|
|
9330
9345
|
if (types.length === 0)
|
|
9331
9346
|
return result;
|
|
9332
9347
|
for (let idx = 0, len = types.length; idx < len; idx++) {
|
|
@@ -9345,7 +9360,7 @@ class PDFContext {
|
|
|
9345
9360
|
return this.getObjectRef(pdfObject);
|
|
9346
9361
|
}
|
|
9347
9362
|
getObjectRef(pdfObject) {
|
|
9348
|
-
const entries = Array.from(this.indirectObjects.
|
|
9363
|
+
const entries = Array.from(this.indirectObjects.values());
|
|
9349
9364
|
for (let idx = 0, len = entries.length; idx < len; idx++) {
|
|
9350
9365
|
const [ref, object] = entries[idx];
|
|
9351
9366
|
if (object === pdfObject) {
|
|
@@ -9355,7 +9370,7 @@ class PDFContext {
|
|
|
9355
9370
|
return undefined;
|
|
9356
9371
|
}
|
|
9357
9372
|
enumerateIndirectObjects() {
|
|
9358
|
-
return Array.from(this.indirectObjects.
|
|
9373
|
+
return Array.from(this.indirectObjects.values()).sort(byAscendingObjectNumber);
|
|
9359
9374
|
}
|
|
9360
9375
|
obj(literal) {
|
|
9361
9376
|
if (isPDFInstance(literal, PDFClasses.PDFObject)) {
|
|
@@ -9496,7 +9511,7 @@ class PDFContext {
|
|
|
9496
9511
|
}
|
|
9497
9512
|
}
|
|
9498
9513
|
findContainingIndirectObject(target) {
|
|
9499
|
-
const entries = Array.from(this.indirectObjects.
|
|
9514
|
+
const entries = Array.from(this.indirectObjects.values());
|
|
9500
9515
|
for (let idx = 0, len = entries.length; idx < len; idx++) {
|
|
9501
9516
|
const [ref, object] = entries[idx];
|
|
9502
9517
|
if (this.objectContains(object, target)) {
|
|
@@ -9530,7 +9545,7 @@ class PDFContext {
|
|
|
9530
9545
|
getObjectVersions(ref) {
|
|
9531
9546
|
if (!this.preserveObjectsVersions)
|
|
9532
9547
|
return [];
|
|
9533
|
-
const list = this.objectsPreviousVersions.get(ref);
|
|
9548
|
+
const list = this.objectsPreviousVersions.get(ref.toString());
|
|
9534
9549
|
if (list)
|
|
9535
9550
|
return list;
|
|
9536
9551
|
return [];
|
|
@@ -37732,7 +37747,7 @@ class PDFDocument {
|
|
|
37732
37747
|
const changed = new Map();
|
|
37733
37748
|
for (const entry of entries) {
|
|
37734
37749
|
const ref = entry.ref;
|
|
37735
|
-
changed.set(ref, {
|
|
37750
|
+
changed.set(ref.toString(), {
|
|
37736
37751
|
ref,
|
|
37737
37752
|
actual: entry.deleted ? undefined : this.context.lookup(ref),
|
|
37738
37753
|
previous: this.context.getObjectVersions(ref),
|
|
@@ -37740,13 +37755,13 @@ class PDFDocument {
|
|
|
37740
37755
|
}
|
|
37741
37756
|
// if not the las update, then check objects later modified and adjust PDFObjectVersions accordingly
|
|
37742
37757
|
if (!lastUpdateMinusX)
|
|
37743
|
-
return Array.from(changed.
|
|
37758
|
+
return Array.from(changed.values());
|
|
37744
37759
|
while (lastUpdateMinusX) {
|
|
37745
37760
|
lastUpdateMinusX -= 1;
|
|
37746
37761
|
const upind = this.context.xrefs.length - lastUpdateMinusX - 1;
|
|
37747
37762
|
const nentries = this.context.listXrefEntries(upind);
|
|
37748
37763
|
for (const nentry of nentries) {
|
|
37749
|
-
const oce = changed.get(nentry.ref);
|
|
37764
|
+
const oce = changed.get(nentry.ref.toString());
|
|
37750
37765
|
if (oce && oce.actual) {
|
|
37751
37766
|
oce.actual = oce.previous[0];
|
|
37752
37767
|
oce.previous = oce.previous.slice(1);
|
|
@@ -37754,9 +37769,7 @@ class PDFDocument {
|
|
|
37754
37769
|
}
|
|
37755
37770
|
}
|
|
37756
37771
|
// if PDF has errors, it may happen to end with objects that has no current, nor previous versions
|
|
37757
|
-
return Array.from(changed.
|
|
37758
|
-
.map((value) => value[1])
|
|
37759
|
-
.filter((ov) => ov.actual || ov.previous.length);
|
|
37772
|
+
return Array.from(changed.values()).filter((ov) => ov.actual || ov.previous.length);
|
|
37760
37773
|
}
|
|
37761
37774
|
/**
|
|
37762
37775
|
* Saves the current changes to the document as an incremental update, returns the full document,
|