@adnsistemas/pdf-lib 2.7.3 → 2.8.0
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 -0
- package/cjs/api/PDFDocument.d.ts +16 -2
- package/cjs/api/PDFDocument.d.ts.map +1 -1
- package/cjs/api/PDFDocument.js +58 -4
- package/cjs/api/PDFDocument.js.map +1 -1
- package/cjs/api/PDFEmbeddedFile.d.ts +6 -0
- package/cjs/api/PDFEmbeddedFile.d.ts.map +1 -1
- package/cjs/api/PDFEmbeddedFile.js +10 -0
- package/cjs/api/PDFEmbeddedFile.js.map +1 -1
- package/cjs/api/PDFPage.js +1 -1
- package/cjs/api/operations.js +2 -2
- package/cjs/api/operations.js.map +1 -1
- package/cjs/core/embedders/JpegEmbedder.d.ts.map +1 -1
- package/cjs/core/embedders/JpegEmbedder.js +1 -1
- package/cjs/core/embedders/JpegEmbedder.js.map +1 -1
- package/cjs/core/structures/PDFCatalog.d.ts +3 -0
- package/cjs/core/structures/PDFCatalog.d.ts.map +1 -1
- package/cjs/core/structures/PDFCatalog.js +7 -0
- package/cjs/core/structures/PDFCatalog.js.map +1 -1
- package/dist/pdf-lib.esm.js +78 -8
- 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 +78 -8
- package/dist/pdf-lib.js.map +1 -1
- package/dist/pdf-lib.min.js +2 -2
- package/dist/pdf-lib.min.js.map +1 -1
- package/es/api/PDFDocument.d.ts +16 -2
- package/es/api/PDFDocument.d.ts.map +1 -1
- package/es/api/PDFDocument.js +58 -4
- package/es/api/PDFDocument.js.map +1 -1
- package/es/api/PDFEmbeddedFile.d.ts +6 -0
- package/es/api/PDFEmbeddedFile.d.ts.map +1 -1
- package/es/api/PDFEmbeddedFile.js +10 -0
- package/es/api/PDFEmbeddedFile.js.map +1 -1
- package/es/api/PDFPage.js +1 -1
- package/es/api/operations.js +2 -2
- package/es/api/operations.js.map +1 -1
- package/es/core/embedders/JpegEmbedder.d.ts.map +1 -1
- package/es/core/embedders/JpegEmbedder.js +1 -1
- package/es/core/embedders/JpegEmbedder.js.map +1 -1
- package/es/core/structures/PDFCatalog.d.ts +3 -0
- package/es/core/structures/PDFCatalog.d.ts.map +1 -1
- package/es/core/structures/PDFCatalog.js +7 -0
- package/es/core/structures/PDFCatalog.js.map +1 -1
- package/package.json +4 -2
- package/src/api/PDFDocument.ts +74 -9
- package/src/api/PDFEmbeddedFile.ts +12 -0
- package/src/api/PDFPage.ts +1 -1
- package/src/api/operations.ts +2 -2
- package/src/core/embedders/JpegEmbedder.ts +5 -1
- package/src/core/structures/PDFCatalog.ts +9 -0
- package/ts3.4/cjs/api/PDFDocument.d.ts +16 -2
- package/ts3.4/cjs/api/PDFEmbeddedFile.d.ts +6 -0
- package/ts3.4/cjs/core/structures/PDFCatalog.d.ts +3 -0
- package/ts3.4/es/api/PDFDocument.d.ts +16 -2
- package/ts3.4/es/api/PDFEmbeddedFile.d.ts +6 -0
- package/ts3.4/es/core/structures/PDFCatalog.d.ts +3 -0
|
@@ -5,6 +5,7 @@ const PDFDict_1 = tslib_1.__importDefault(require("../objects/PDFDict"));
|
|
|
5
5
|
const PDFName_1 = tslib_1.__importDefault(require("../objects/PDFName"));
|
|
6
6
|
const acroform_1 = require("../acroform");
|
|
7
7
|
const ViewerPreferences_1 = tslib_1.__importDefault(require("../interactive/ViewerPreferences"));
|
|
8
|
+
const PDFArray_1 = tslib_1.__importDefault(require("../objects/PDFArray"));
|
|
8
9
|
class PDFCatalog extends PDFDict_1.default {
|
|
9
10
|
Pages() {
|
|
10
11
|
return this.lookup(PDFName_1.default.of('Pages'), PDFDict_1.default);
|
|
@@ -12,6 +13,12 @@ class PDFCatalog extends PDFDict_1.default {
|
|
|
12
13
|
AcroForm() {
|
|
13
14
|
return this.lookupMaybe(PDFName_1.default.of('AcroForm'), PDFDict_1.default);
|
|
14
15
|
}
|
|
16
|
+
Names() {
|
|
17
|
+
return this.lookupMaybe(PDFName_1.default.of('Names'), PDFDict_1.default);
|
|
18
|
+
}
|
|
19
|
+
AttachedFiles() {
|
|
20
|
+
return this.lookupMaybe(PDFName_1.default.of('AF'), PDFArray_1.default);
|
|
21
|
+
}
|
|
15
22
|
getAcroForm() {
|
|
16
23
|
const dict = this.AcroForm();
|
|
17
24
|
if (!dict)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PDFCatalog.js","sourceRoot":"","sources":["../../../src/core/structures/PDFCatalog.ts"],"names":[],"mappings":";;;AAAA,yEAAsD;AACtD,yEAAyC;AAIzC,0CAA0C;AAC1C,iGAAiE;
|
|
1
|
+
{"version":3,"file":"PDFCatalog.js","sourceRoot":"","sources":["../../../src/core/structures/PDFCatalog.ts"],"names":[],"mappings":";;;AAAA,yEAAsD;AACtD,yEAAyC;AAIzC,0CAA0C;AAC1C,iGAAiE;AACjE,2EAA2C;AAE3C,MAAM,UAAW,SAAQ,iBAAO;IAc9B,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAO,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAO,CAAgB,CAAC;IAClE,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,iBAAO,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAO,CAAC,CAAC;IACxD,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,kBAAQ,CAAC,CAAC;IACtD,CAAC;IAED,WAAW;QACT,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC7B,IAAI,CAAC,IAAI;YAAE,OAAO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,CAAC,OAAe,EAAE,KAAa;QAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAW,CAAC;QACzD,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACnE,OAAO,cAAc,IAAI,QAAQ,CAAC;IACpC,CAAC;IAED,cAAc,CAAC,KAAa;QAC1B,IAAI,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;;AAhFM,8BAAmB,GAAG,CAC3B,OAAmB,EACnB,KAA2B,EAC3B,EAAE;IACF,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;IACvB,IAAI,CAAC,GAAG,CAAC,iBAAO,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,iBAAO,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IACpD,IAAI,CAAC,GAAG,CAAC,iBAAO,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC,CAAC;AAEK,6BAAkB,GAAG,CAAC,GAAY,EAAE,OAAmB,EAAE,EAAE,CAChE,IAAI,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAwEjC,kBAAe,UAAU,CAAC"}
|
package/dist/pdf-lib.esm.js
CHANGED
|
@@ -12445,6 +12445,12 @@ class PDFCatalog extends PDFDict {
|
|
|
12445
12445
|
AcroForm() {
|
|
12446
12446
|
return this.lookupMaybe(PDFName.of('AcroForm'), PDFDict);
|
|
12447
12447
|
}
|
|
12448
|
+
Names() {
|
|
12449
|
+
return this.lookupMaybe(PDFName.of('Names'), PDFDict);
|
|
12450
|
+
}
|
|
12451
|
+
AttachedFiles() {
|
|
12452
|
+
return this.lookupMaybe(PDFName.of('AF'), PDFArray);
|
|
12453
|
+
}
|
|
12448
12454
|
getAcroForm() {
|
|
12449
12455
|
const dict = this.AcroForm();
|
|
12450
12456
|
if (!dict)
|
|
@@ -13275,7 +13281,7 @@ const ChannelToColorSpace = {
|
|
|
13275
13281
|
class JpegEmbedder {
|
|
13276
13282
|
static for(imageData) {
|
|
13277
13283
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13278
|
-
const dataView = new DataView(imageData.buffer);
|
|
13284
|
+
const dataView = new DataView(imageData.buffer, imageData.byteOffset, imageData.byteLength);
|
|
13279
13285
|
const soi = dataView.getUint16(0);
|
|
13280
13286
|
if (soi !== 0xffd8)
|
|
13281
13287
|
throw new Error('SOI not found in JPEG');
|
|
@@ -29517,13 +29523,13 @@ const drawOptionList = (options) => {
|
|
|
29517
29523
|
];
|
|
29518
29524
|
};
|
|
29519
29525
|
const getDrawingOperator = ({ color, borderWidth, borderColor, fillRule, }) => {
|
|
29520
|
-
if (color && borderColor && borderWidth) {
|
|
29526
|
+
if (color && borderColor && borderWidth !== 0) {
|
|
29521
29527
|
return fillAndStroke;
|
|
29522
29528
|
}
|
|
29523
29529
|
else if (color) {
|
|
29524
29530
|
return fillRule === FillRule.EvenOdd ? fillEvenOdd : fill;
|
|
29525
29531
|
}
|
|
29526
|
-
else if (borderColor && borderWidth) {
|
|
29532
|
+
else if (borderColor && borderWidth !== 0) {
|
|
29527
29533
|
return stroke;
|
|
29528
29534
|
}
|
|
29529
29535
|
return undefined;
|
|
@@ -34228,6 +34234,16 @@ class PDFEmbeddedFile {
|
|
|
34228
34234
|
getEmbedder() {
|
|
34229
34235
|
return this.embedder;
|
|
34230
34236
|
}
|
|
34237
|
+
/**
|
|
34238
|
+
* Returns whether or not this file has already been embedded.
|
|
34239
|
+
* @returns true if the file has already been embedded, false otherwise.
|
|
34240
|
+
*/
|
|
34241
|
+
getAlreadyEmbedded() {
|
|
34242
|
+
return this.alreadyEmbedded;
|
|
34243
|
+
}
|
|
34244
|
+
getRef() {
|
|
34245
|
+
return this.ref;
|
|
34246
|
+
}
|
|
34231
34247
|
}
|
|
34232
34248
|
/**
|
|
34233
34249
|
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
|
@@ -36790,13 +36806,17 @@ class PDFDocument {
|
|
|
36790
36806
|
for (let idx = 0, len = EFNames.size(); idx < len; idx += 2) {
|
|
36791
36807
|
const fileName = EFNames.lookup(idx);
|
|
36792
36808
|
const fileSpec = EFNames.lookup(idx + 1, PDFDict);
|
|
36793
|
-
rawAttachments.push({
|
|
36809
|
+
rawAttachments.push({
|
|
36810
|
+
fileName,
|
|
36811
|
+
fileSpec,
|
|
36812
|
+
specRef: EFNames.get(idx + 1),
|
|
36813
|
+
});
|
|
36794
36814
|
}
|
|
36795
36815
|
return rawAttachments;
|
|
36796
36816
|
}
|
|
36797
36817
|
getSavedAttachments() {
|
|
36798
36818
|
const rawAttachments = this.getRawAttachments();
|
|
36799
|
-
return rawAttachments.flatMap(({ fileName, fileSpec }) => {
|
|
36819
|
+
return rawAttachments.flatMap(({ fileName, fileSpec, specRef }) => {
|
|
36800
36820
|
const efDict = fileSpec.lookup(PDFName.of('EF'));
|
|
36801
36821
|
if (!(efDict instanceof PDFDict))
|
|
36802
36822
|
return [];
|
|
@@ -36829,7 +36849,11 @@ class PDFDocument {
|
|
|
36829
36849
|
modificationDate = modDateRaw.decodeDate();
|
|
36830
36850
|
}
|
|
36831
36851
|
}
|
|
36832
|
-
const
|
|
36852
|
+
const descRaw = fileSpec.lookup(PDFName.of('Desc'));
|
|
36853
|
+
let description;
|
|
36854
|
+
if (descRaw instanceof PDFHexString) {
|
|
36855
|
+
description = descRaw.decodeText();
|
|
36856
|
+
}
|
|
36833
36857
|
return [
|
|
36834
36858
|
{
|
|
36835
36859
|
name: fileName.decodeText(),
|
|
@@ -36839,12 +36863,16 @@ class PDFDocument {
|
|
|
36839
36863
|
description,
|
|
36840
36864
|
creationDate,
|
|
36841
36865
|
modificationDate,
|
|
36866
|
+
embeddedFileDict: efDict,
|
|
36867
|
+
specRef,
|
|
36842
36868
|
},
|
|
36843
36869
|
];
|
|
36844
36870
|
});
|
|
36845
36871
|
}
|
|
36846
36872
|
getUnsavedAttachments() {
|
|
36847
|
-
const attachments = this.embeddedFiles.
|
|
36873
|
+
const attachments = this.embeddedFiles.flatMap((file) => {
|
|
36874
|
+
if (file.getAlreadyEmbedded())
|
|
36875
|
+
return [];
|
|
36848
36876
|
const embedder = file.getEmbedder();
|
|
36849
36877
|
return {
|
|
36850
36878
|
name: embedder.fileName,
|
|
@@ -36854,6 +36882,7 @@ class PDFDocument {
|
|
|
36854
36882
|
afRelationship: embedder.options.afRelationship,
|
|
36855
36883
|
creationDate: embedder.options.creationDate,
|
|
36856
36884
|
modificationDate: embedder.options.modificationDate,
|
|
36885
|
+
pdfEmbeddedFile: file,
|
|
36857
36886
|
};
|
|
36858
36887
|
});
|
|
36859
36888
|
return attachments;
|
|
@@ -36868,6 +36897,47 @@ class PDFDocument {
|
|
|
36868
36897
|
const unsavedAttachments = this.getUnsavedAttachments();
|
|
36869
36898
|
return [...savedAttachments, ...unsavedAttachments];
|
|
36870
36899
|
}
|
|
36900
|
+
/**
|
|
36901
|
+
* Removes an attachment from PDF, based on name.
|
|
36902
|
+
* @param {string} name Name of the attachmet to remove.
|
|
36903
|
+
*/
|
|
36904
|
+
detach(name) {
|
|
36905
|
+
const attachedFiles = this.getAttachments();
|
|
36906
|
+
attachedFiles.forEach((file) => {
|
|
36907
|
+
var _a, _b, _c;
|
|
36908
|
+
if (file.name !== name)
|
|
36909
|
+
return;
|
|
36910
|
+
// the file wasn't embedded into context yet
|
|
36911
|
+
if ('pdfEmbeddedFile' in file) {
|
|
36912
|
+
const i = this.embeddedFiles.findIndex((f) => file.pdfEmbeddedFile === f);
|
|
36913
|
+
if (i !== undefined)
|
|
36914
|
+
this.embeddedFiles.splice(i, 1);
|
|
36915
|
+
}
|
|
36916
|
+
else {
|
|
36917
|
+
// remove references from catalog
|
|
36918
|
+
const namesArr = (_a = this.catalog
|
|
36919
|
+
.Names()) === null || _a === void 0 ? void 0 : _a.lookup(PDFName.of('EmbeddedFiles'), PDFDict).lookup(PDFName.of('Names'), PDFArray);
|
|
36920
|
+
const iNames = namesArr === null || namesArr === void 0 ? void 0 : namesArr.indexOf(file.specRef);
|
|
36921
|
+
if (iNames !== undefined && iNames > 0) {
|
|
36922
|
+
// attachment spec ref
|
|
36923
|
+
namesArr === null || namesArr === void 0 ? void 0 : namesArr.remove(iNames);
|
|
36924
|
+
// attachment name
|
|
36925
|
+
namesArr === null || namesArr === void 0 ? void 0 : namesArr.remove(iNames - 1);
|
|
36926
|
+
}
|
|
36927
|
+
// AF-Tag for PDF-A3 compliance
|
|
36928
|
+
const AF = this.catalog.AttachedFiles();
|
|
36929
|
+
const afIndex = AF === null || AF === void 0 ? void 0 : AF.indexOf(file.specRef);
|
|
36930
|
+
if (afIndex !== undefined)
|
|
36931
|
+
AF === null || AF === void 0 ? void 0 : AF.remove(afIndex);
|
|
36932
|
+
// remove references from context
|
|
36933
|
+
const streamRef = (_c = (_b = this.context
|
|
36934
|
+
.lookupMaybe(file.specRef, PDFDict)) === null || _b === void 0 ? void 0 : _b.lookupMaybe(PDFName.of('EF'), PDFDict)) === null || _c === void 0 ? void 0 : _c.get(PDFName.of('F'));
|
|
36935
|
+
if (streamRef)
|
|
36936
|
+
this.context.delete(streamRef);
|
|
36937
|
+
this.context.delete(file.specRef);
|
|
36938
|
+
}
|
|
36939
|
+
});
|
|
36940
|
+
}
|
|
36871
36941
|
/**
|
|
36872
36942
|
* Embed a font into this document. The input data can be provided in multiple
|
|
36873
36943
|
* formats:
|
|
@@ -38559,7 +38629,7 @@ class PDFPage {
|
|
|
38559
38629
|
rotate: (_c = options.rotate) !== null && _c !== void 0 ? _c : degrees(0),
|
|
38560
38630
|
color: (_d = options.color) !== null && _d !== void 0 ? _d : undefined,
|
|
38561
38631
|
borderColor: (_e = options.borderColor) !== null && _e !== void 0 ? _e : undefined,
|
|
38562
|
-
borderWidth: (_f = options.borderWidth) !== null && _f !== void 0 ? _f :
|
|
38632
|
+
borderWidth: (_f = options.borderWidth) !== null && _f !== void 0 ? _f : 1,
|
|
38563
38633
|
borderDashArray: (_g = options.borderDashArray) !== null && _g !== void 0 ? _g : undefined,
|
|
38564
38634
|
borderDashPhase: (_h = options.borderDashPhase) !== null && _h !== void 0 ? _h : undefined,
|
|
38565
38635
|
borderLineCap: (_j = options.borderLineCap) !== null && _j !== void 0 ? _j : undefined,
|