pdf-lite 1.0.4 → 1.0.6
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/EXAMPLES.md +37 -87
- package/README.md +104 -144
- package/dist/acroform/acroform-manager.d.ts +49 -0
- package/dist/acroform/acroform-manager.js +215 -0
- package/dist/acroform/index.d.ts +1 -0
- package/dist/acroform/index.js +1 -0
- package/dist/core/generators.d.ts +2 -2
- package/dist/core/generators.js +3 -3
- package/dist/core/incremental-parser.d.ts +1 -1
- package/dist/core/incremental-parser.js +1 -1
- package/dist/core/objects/pdf-array.d.ts +3 -3
- package/dist/core/objects/pdf-array.js +4 -4
- package/dist/core/objects/pdf-boolean.d.ts +2 -2
- package/dist/core/objects/pdf-boolean.js +2 -2
- package/dist/core/objects/pdf-comment.d.ts +3 -3
- package/dist/core/objects/pdf-comment.js +4 -4
- package/dist/core/objects/pdf-date.d.ts +1 -1
- package/dist/core/objects/pdf-date.js +1 -1
- package/dist/core/objects/pdf-dictionary.d.ts +3 -3
- package/dist/core/objects/pdf-dictionary.js +5 -5
- package/dist/core/objects/pdf-hexadecimal.d.ts +3 -3
- package/dist/core/objects/pdf-hexadecimal.js +6 -6
- package/dist/core/objects/pdf-indirect-object.d.ts +5 -5
- package/dist/core/objects/pdf-indirect-object.js +9 -9
- package/dist/core/objects/pdf-name.d.ts +2 -2
- package/dist/core/objects/pdf-name.js +2 -2
- package/dist/core/objects/pdf-null.d.ts +2 -2
- package/dist/core/objects/pdf-null.js +2 -2
- package/dist/core/objects/pdf-number.d.ts +3 -3
- package/dist/core/objects/pdf-number.js +3 -3
- package/dist/core/objects/pdf-object-reference.d.ts +2 -2
- package/dist/core/objects/pdf-object-reference.js +2 -2
- package/dist/core/objects/pdf-start-xref.d.ts +4 -4
- package/dist/core/objects/pdf-start-xref.js +4 -4
- package/dist/core/objects/pdf-stream.d.ts +9 -8
- package/dist/core/objects/pdf-stream.js +39 -26
- package/dist/core/objects/pdf-string.d.ts +3 -3
- package/dist/core/objects/pdf-string.js +4 -4
- package/dist/core/objects/pdf-trailer.d.ts +8 -8
- package/dist/core/objects/pdf-trailer.js +6 -6
- package/dist/core/objects/pdf-xref-table.d.ts +7 -7
- package/dist/core/objects/pdf-xref-table.js +8 -8
- package/dist/core/serializer.d.ts +3 -3
- package/dist/core/serializer.js +2 -2
- package/dist/core/streams/object-stream.d.ts +3 -3
- package/dist/core/streams/object-stream.js +2 -2
- package/dist/core/tokens/boolean-token.d.ts +1 -1
- package/dist/core/tokens/boolean-token.js +1 -1
- package/dist/core/tokens/byte-offset-token.d.ts +2 -2
- package/dist/core/tokens/byte-offset-token.js +2 -2
- package/dist/core/tokens/comment-token.d.ts +2 -2
- package/dist/core/tokens/comment-token.js +4 -4
- package/dist/core/tokens/end-array-token.d.ts +1 -1
- package/dist/core/tokens/end-array-token.js +2 -2
- package/dist/core/tokens/end-dictionary-token.d.ts +1 -1
- package/dist/core/tokens/end-dictionary-token.js +2 -2
- package/dist/core/tokens/end-object-token.d.ts +1 -1
- package/dist/core/tokens/end-object-token.js +2 -2
- package/dist/core/tokens/end-stream-token.d.ts +2 -2
- package/dist/core/tokens/end-stream-token.js +2 -2
- package/dist/core/tokens/hexadecimal-token.d.ts +2 -2
- package/dist/core/tokens/hexadecimal-token.js +2 -2
- package/dist/core/tokens/name-token.d.ts +1 -1
- package/dist/core/tokens/name-token.js +2 -2
- package/dist/core/tokens/null-token.d.ts +1 -1
- package/dist/core/tokens/null-token.js +2 -2
- package/dist/core/tokens/number-token.d.ts +3 -3
- package/dist/core/tokens/number-token.js +3 -3
- package/dist/core/tokens/object-reference-token.d.ts +1 -1
- package/dist/core/tokens/object-reference-token.js +2 -2
- package/dist/core/tokens/start-array-token.d.ts +1 -1
- package/dist/core/tokens/start-array-token.js +2 -2
- package/dist/core/tokens/start-dictionary-token.d.ts +1 -1
- package/dist/core/tokens/start-dictionary-token.js +2 -2
- package/dist/core/tokens/start-object-token.d.ts +1 -1
- package/dist/core/tokens/start-object-token.js +2 -2
- package/dist/core/tokens/start-stream-token.d.ts +3 -3
- package/dist/core/tokens/start-stream-token.js +3 -3
- package/dist/core/tokens/start-xref-token.d.ts +1 -1
- package/dist/core/tokens/start-xref-token.js +2 -2
- package/dist/core/tokens/stream-chunk-token.d.ts +2 -2
- package/dist/core/tokens/stream-chunk-token.js +1 -1
- package/dist/core/tokens/string-token.d.ts +2 -2
- package/dist/core/tokens/string-token.js +3 -3
- package/dist/core/tokens/token.d.ts +1 -1
- package/dist/core/tokens/token.js +1 -1
- package/dist/core/tokens/trailer-token.d.ts +1 -1
- package/dist/core/tokens/trailer-token.js +2 -2
- package/dist/core/tokens/whitespace-token.d.ts +2 -2
- package/dist/core/tokens/whitespace-token.js +1 -1
- package/dist/core/tokens/xref-table-entry-token.d.ts +3 -3
- package/dist/core/tokens/xref-table-entry-token.js +2 -2
- package/dist/core/tokens/xref-table-section-start-token.d.ts +2 -2
- package/dist/core/tokens/xref-table-section-start-token.js +3 -3
- package/dist/core/tokens/xref-table-start-token.d.ts +1 -1
- package/dist/core/tokens/xref-table-start-token.js +2 -2
- package/dist/crypto/key-derivation/key-derivation-aes256.d.ts +1 -1
- package/dist/crypto/key-derivation/key-derivation-aes256.js +2 -2
- package/dist/crypto/key-gen/key-gen-rc4-128.d.ts +1 -1
- package/dist/crypto/key-gen/key-gen-rc4-128.js +5 -5
- package/dist/crypto/types.d.ts +1 -1
- package/dist/filters/asciihex.d.ts +1 -1
- package/dist/filters/asciihex.js +2 -2
- package/dist/filters/lzw.d.ts +1 -1
- package/dist/filters/types.d.ts +1 -1
- package/dist/pdf/pdf-document.d.ts +28 -14
- package/dist/pdf/pdf-document.js +60 -21
- package/dist/pdf/pdf-reader.d.ts +3 -3
- package/dist/pdf/pdf-reader.js +2 -2
- package/dist/pdf/pdf-revision.d.ts +5 -5
- package/dist/pdf/pdf-revision.js +4 -4
- package/dist/pdf/pdf-xref-lookup.d.ts +7 -7
- package/dist/pdf/pdf-xref-lookup.js +11 -10
- package/dist/security/crypt-filters/aesv2.d.ts +2 -2
- package/dist/security/crypt-filters/aesv2.js +2 -2
- package/dist/security/crypt-filters/aesv3.d.ts +2 -2
- package/dist/security/crypt-filters/aesv3.js +2 -2
- package/dist/security/crypt-filters/base.d.ts +4 -4
- package/dist/security/crypt-filters/base.js +3 -3
- package/dist/security/crypt-filters/identity.d.ts +2 -2
- package/dist/security/crypt-filters/identity.js +1 -1
- package/dist/security/crypt-filters/v2.d.ts +1 -1
- package/dist/security/crypt-filters/v2.js +1 -1
- package/dist/security/handlers/base.d.ts +4 -4
- package/dist/security/handlers/base.js +12 -12
- package/dist/security/handlers/pubSec.d.ts +3 -3
- package/dist/security/handlers/pubSec.js +10 -10
- package/dist/security/handlers/utils.d.ts +4 -4
- package/dist/security/handlers/utils.js +12 -12
- package/dist/security/handlers/v1.d.ts +4 -4
- package/dist/security/handlers/v1.js +7 -7
- package/dist/security/handlers/v2.d.ts +3 -3
- package/dist/security/handlers/v2.js +5 -5
- package/dist/security/handlers/v4.d.ts +6 -6
- package/dist/security/handlers/v4.js +11 -11
- package/dist/security/handlers/v5.d.ts +5 -5
- package/dist/security/handlers/v5.js +9 -9
- package/dist/security/types.d.ts +9 -9
- package/dist/signing/document-security-store.d.ts +11 -11
- package/dist/signing/document-security-store.js +4 -4
- package/dist/signing/signatures/adbe-pkcs7-detached.d.ts +4 -4
- package/dist/signing/signatures/adbe-pkcs7-detached.js +11 -11
- package/dist/signing/signatures/adbe-pkcs7-sha1.d.ts +4 -4
- package/dist/signing/signatures/adbe-pkcs7-sha1.js +12 -12
- package/dist/signing/signatures/adbe-x509-rsa-sha1.d.ts +4 -4
- package/dist/signing/signatures/adbe-x509-rsa-sha1.js +8 -8
- package/dist/signing/signatures/base.d.ts +5 -5
- package/dist/signing/signatures/base.js +11 -11
- package/dist/signing/signatures/etsi-cades-detached.d.ts +4 -4
- package/dist/signing/signatures/etsi-cades-detached.js +17 -17
- package/dist/signing/signatures/etsi-rfc3161.d.ts +2 -2
- package/dist/signing/signatures/etsi-rfc3161.js +9 -9
- package/dist/signing/signatures/index.d.ts +6 -6
- package/dist/signing/signatures/index.js +6 -6
- package/dist/signing/signer.d.ts +3 -3
- package/dist/signing/signer.js +10 -10
- package/dist/signing/types.d.ts +7 -7
- package/dist/signing/utils.d.ts +2 -2
- package/dist/signing/utils.js +1 -1
- package/dist/utils/algos.js +1 -1
- package/dist/utils/bytesToHex.d.ts +1 -1
- package/dist/utils/bytesToHex.js +2 -2
- package/dist/utils/bytesToHexBytes.d.ts +1 -1
- package/dist/utils/bytesToString.d.ts +1 -1
- package/dist/utils/concatUint8Arrays.d.ts +1 -1
- package/dist/utils/escapeString.d.ts +1 -1
- package/dist/utils/escapeString.js +1 -1
- package/dist/utils/hexBytesToBytes.d.ts +1 -1
- package/dist/utils/hexBytesToString.d.ts +1 -1
- package/dist/utils/hexToBytes.d.ts +1 -1
- package/dist/utils/hexToBytes.js +2 -2
- package/dist/utils/padBytes.d.ts +1 -1
- package/dist/utils/replaceInBuffer.d.ts +1 -1
- package/dist/utils/stringToBytes.d.ts +1 -1
- package/dist/utils/stringToHexBytes.d.ts +1 -1
- package/dist/utils/unescapeString.d.ts +1 -1
- package/dist/xfa/index.d.ts +1 -0
- package/dist/xfa/index.js +1 -0
- package/dist/xfa/xfa-manager.d.ts +44 -0
- package/dist/xfa/xfa-manager.js +138 -0
- package/package.json +3 -3
package/dist/utils/algos.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deflate, Inflate } from 'pako';
|
|
2
2
|
import { bytesToHex } from './bytesToHex.js';
|
|
3
|
-
import { AlgorithmIdentifier } from 'pki-lite/algorithms/AlgorithmIdentifier';
|
|
3
|
+
import { AlgorithmIdentifier } from 'pki-lite/algorithms/AlgorithmIdentifier.js';
|
|
4
4
|
import 'pki-lite-crypto-extended';
|
|
5
5
|
/**
|
|
6
6
|
* Computes the SHA-1 hash of the input data.
|
package/dist/utils/bytesToHex.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { bytesToHexBytes } from './bytesToHexBytes';
|
|
2
|
-
import { bytesToString } from './bytesToString';
|
|
1
|
+
import { bytesToHexBytes } from './bytesToHexBytes.js';
|
|
2
|
+
import { bytesToString } from './bytesToString.js';
|
|
3
3
|
/**
|
|
4
4
|
* Converts a byte array to a hexadecimal string.
|
|
5
5
|
*
|
package/dist/utils/hexToBytes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { hexBytesToBytes } from './hexBytesToBytes';
|
|
2
|
-
import { stringToBytes } from './stringToBytes';
|
|
1
|
+
import { hexBytesToBytes } from './hexBytesToBytes.js';
|
|
2
|
+
import { stringToBytes } from './stringToBytes.js';
|
|
3
3
|
/**
|
|
4
4
|
* Converts a hexadecimal string to a byte array.
|
|
5
5
|
*
|
package/dist/utils/padBytes.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PdfXfaManager } from './xfa-manager.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PdfXfaManager } from './xfa-manager.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PdfDocument } from '../pdf/pdf-document.js';
|
|
2
|
+
/**
|
|
3
|
+
* Manages XFA (XML Forms Architecture) forms in PDF documents.
|
|
4
|
+
* Provides methods to read and write XFA form data as XML.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PdfXfaManager {
|
|
7
|
+
private document;
|
|
8
|
+
private _datasetsStream?;
|
|
9
|
+
constructor(document: PdfDocument);
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the document contains XFA forms.
|
|
12
|
+
* @returns True if the document has XFA forms, false otherwise
|
|
13
|
+
*/
|
|
14
|
+
hasXfaForms(): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Reads the XFA form data as XML string.
|
|
17
|
+
* @returns The XFA datasets XML content, or null if no XFA form exists
|
|
18
|
+
*/
|
|
19
|
+
readXml(): Promise<string | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Writes XML content to the XFA datasets stream.
|
|
22
|
+
* @param xml The XML content to write
|
|
23
|
+
* @throws Error if the document doesn't have XFA forms
|
|
24
|
+
*/
|
|
25
|
+
writeXml(xml: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the AcroForm dictionary from the document catalog.
|
|
28
|
+
* @returns The AcroForm dictionary or null if not found
|
|
29
|
+
*/
|
|
30
|
+
private getAcroForm;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the XFA datasets stream.
|
|
33
|
+
* Caches the stream for subsequent calls to preserve modifications.
|
|
34
|
+
* @returns The datasets stream or null if not found
|
|
35
|
+
*/
|
|
36
|
+
private getDatasetsStream;
|
|
37
|
+
/**
|
|
38
|
+
* Finds the XFA dataset object reference from the XFA array.
|
|
39
|
+
* XFA array structure: [(name1) ref1 (name2) ref2 ...]
|
|
40
|
+
* @param xfaArray The XFA array from the AcroForm
|
|
41
|
+
* @returns The object reference to the datasets stream, or null if not found
|
|
42
|
+
*/
|
|
43
|
+
private findXfaDatasetReference;
|
|
44
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { PdfStream } from '../core/objects/pdf-stream.js';
|
|
2
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
3
|
+
import { PdfArray } from '../core/objects/pdf-array.js';
|
|
4
|
+
import { PdfString } from '../core/objects/pdf-string.js';
|
|
5
|
+
import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
6
|
+
import { PdfIndirectObject } from '../core/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Manages XFA (XML Forms Architecture) forms in PDF documents.
|
|
9
|
+
* Provides methods to read and write XFA form data as XML.
|
|
10
|
+
*/
|
|
11
|
+
export class PdfXfaManager {
|
|
12
|
+
document;
|
|
13
|
+
_datasetsStream;
|
|
14
|
+
constructor(document) {
|
|
15
|
+
this.document = document;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the document contains XFA forms.
|
|
19
|
+
* @returns True if the document has XFA forms, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
async hasXfaForms() {
|
|
22
|
+
try {
|
|
23
|
+
const stream = await this.getDatasetsStream();
|
|
24
|
+
return stream !== null;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reads the XFA form data as XML string.
|
|
32
|
+
* @returns The XFA datasets XML content, or null if no XFA form exists
|
|
33
|
+
*/
|
|
34
|
+
async readXml() {
|
|
35
|
+
const stream = await this.getDatasetsStream();
|
|
36
|
+
if (!stream)
|
|
37
|
+
return null;
|
|
38
|
+
// Get decompressed data without modifying the original stream
|
|
39
|
+
const decompressed = stream.content.decode();
|
|
40
|
+
// Return the raw XML content as string
|
|
41
|
+
const decoder = new TextDecoder();
|
|
42
|
+
return decoder.decode(decompressed);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Writes XML content to the XFA datasets stream.
|
|
46
|
+
* @param xml The XML content to write
|
|
47
|
+
* @throws Error if the document doesn't have XFA forms
|
|
48
|
+
*/
|
|
49
|
+
async writeXml(xml) {
|
|
50
|
+
const stream = await this.getDatasetsStream();
|
|
51
|
+
if (!stream) {
|
|
52
|
+
throw new Error('Document does not contain XFA forms');
|
|
53
|
+
}
|
|
54
|
+
// Update the cached stream directly with the new XML content
|
|
55
|
+
const datasetsIndirect = new PdfIndirectObject({
|
|
56
|
+
...stream,
|
|
57
|
+
content: PdfStream.fromString(xml),
|
|
58
|
+
});
|
|
59
|
+
const isIncremental = this.document.isIncremental();
|
|
60
|
+
this.document.setIncremental(true);
|
|
61
|
+
await this.document.commit(datasetsIndirect);
|
|
62
|
+
this.document.setIncremental(isIncremental);
|
|
63
|
+
// Reset cached stream to force re-fetch if needed
|
|
64
|
+
this._datasetsStream = undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Gets the AcroForm dictionary from the document catalog.
|
|
68
|
+
* @returns The AcroForm dictionary or null if not found
|
|
69
|
+
*/
|
|
70
|
+
async getAcroForm() {
|
|
71
|
+
const catalog = this.document.rootDictionary;
|
|
72
|
+
if (!catalog)
|
|
73
|
+
return null;
|
|
74
|
+
const acroFormRef = catalog.get('AcroForm');
|
|
75
|
+
if (!acroFormRef)
|
|
76
|
+
return null;
|
|
77
|
+
if (acroFormRef instanceof PdfObjectReference) {
|
|
78
|
+
const acroFormObject = await this.document.readObject({
|
|
79
|
+
objectNumber: acroFormRef.objectNumber,
|
|
80
|
+
generationNumber: acroFormRef.generationNumber,
|
|
81
|
+
});
|
|
82
|
+
if (!acroFormObject)
|
|
83
|
+
return null;
|
|
84
|
+
return acroFormObject.content.as(PdfDictionary);
|
|
85
|
+
}
|
|
86
|
+
else if (acroFormRef instanceof PdfDictionary) {
|
|
87
|
+
return acroFormRef;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Gets the XFA datasets stream.
|
|
93
|
+
* Caches the stream for subsequent calls to preserve modifications.
|
|
94
|
+
* @returns The datasets stream or null if not found
|
|
95
|
+
*/
|
|
96
|
+
async getDatasetsStream() {
|
|
97
|
+
if (this._datasetsStream) {
|
|
98
|
+
return this._datasetsStream;
|
|
99
|
+
}
|
|
100
|
+
const acroForm = await this.getAcroForm();
|
|
101
|
+
if (!acroForm)
|
|
102
|
+
return null;
|
|
103
|
+
const xfaArray = acroForm.get('XFA');
|
|
104
|
+
if (!(xfaArray instanceof PdfArray))
|
|
105
|
+
return null;
|
|
106
|
+
const datasetsRef = this.findXfaDatasetReference(xfaArray);
|
|
107
|
+
if (!datasetsRef)
|
|
108
|
+
return null;
|
|
109
|
+
const datasetObject = await this.document.readObject({
|
|
110
|
+
objectNumber: datasetsRef.objectNumber,
|
|
111
|
+
generationNumber: datasetsRef.generationNumber,
|
|
112
|
+
allowUnindexed: true,
|
|
113
|
+
});
|
|
114
|
+
if (!datasetObject)
|
|
115
|
+
return null;
|
|
116
|
+
return datasetObject;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Finds the XFA dataset object reference from the XFA array.
|
|
120
|
+
* XFA array structure: [(name1) ref1 (name2) ref2 ...]
|
|
121
|
+
* @param xfaArray The XFA array from the AcroForm
|
|
122
|
+
* @returns The object reference to the datasets stream, or null if not found
|
|
123
|
+
*/
|
|
124
|
+
findXfaDatasetReference(xfaArray) {
|
|
125
|
+
const items = xfaArray.items;
|
|
126
|
+
// XFA array alternates between name strings and object references
|
|
127
|
+
for (let i = 0; i < items.length - 1; i += 2) {
|
|
128
|
+
const name = items[i];
|
|
129
|
+
const ref = items[i + 1];
|
|
130
|
+
if (name instanceof PdfString && name.value === 'datasets') {
|
|
131
|
+
if (ref instanceof PdfObjectReference) {
|
|
132
|
+
return ref;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-lite",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"pako": "2.1.0",
|
|
57
|
-
"pki-lite": "^1.0.
|
|
58
|
-
"pki-lite-crypto-extended": "^1.0.
|
|
57
|
+
"pki-lite": "^1.0.13",
|
|
58
|
+
"pki-lite-crypto-extended": "^1.0.13"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"test:acceptance": "vitest run test/acceptance",
|