pdf-lite 1.0.1-alpha.2 → 1.0.1-alpha.3
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/dist/core/decoder.d.ts +39 -0
- package/dist/core/decoder.js +367 -0
- package/dist/core/generators.d.ts +37 -0
- package/{packages/pdf-lite/src/core/generators.ts → dist/core/generators.js} +36 -67
- package/dist/core/incremental-parser.d.ts +103 -0
- package/{packages/pdf-lite/src/core/incremental-parser.ts → dist/core/incremental-parser.js} +63 -100
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +2 -0
- package/dist/core/objects/pdf-array.d.ts +12 -0
- package/dist/core/objects/pdf-array.js +42 -0
- package/dist/core/objects/pdf-boolean.d.ts +8 -0
- package/dist/core/objects/pdf-boolean.js +15 -0
- package/dist/core/objects/pdf-comment.d.ts +18 -0
- package/dist/core/objects/pdf-comment.js +39 -0
- package/dist/core/objects/pdf-date.d.ts +5 -0
- package/dist/core/objects/pdf-date.js +40 -0
- package/dist/core/objects/pdf-dictionary.d.ts +22 -0
- package/dist/core/objects/pdf-dictionary.js +136 -0
- package/dist/core/objects/pdf-hexadecimal.d.ts +17 -0
- package/dist/core/objects/pdf-hexadecimal.js +42 -0
- package/dist/core/objects/pdf-indirect-object.d.ts +27 -0
- package/dist/core/objects/pdf-indirect-object.js +100 -0
- package/dist/core/objects/pdf-name.d.ts +8 -0
- package/dist/core/objects/pdf-name.js +15 -0
- package/dist/core/objects/pdf-null.d.ts +7 -0
- package/dist/core/objects/pdf-null.js +11 -0
- package/dist/core/objects/pdf-number.d.ts +25 -0
- package/dist/core/objects/pdf-number.js +77 -0
- package/dist/core/objects/pdf-object-reference.d.ts +9 -0
- package/dist/core/objects/pdf-object-reference.js +19 -0
- package/dist/core/objects/pdf-object.d.ts +30 -0
- package/dist/core/objects/pdf-object.js +77 -0
- package/dist/core/objects/pdf-start-xref.d.ts +10 -0
- package/dist/core/objects/pdf-start-xref.js +32 -0
- package/dist/core/objects/pdf-stream.d.ts +100 -0
- package/dist/core/objects/pdf-stream.js +521 -0
- package/dist/core/objects/pdf-string.d.ts +15 -0
- package/dist/core/objects/pdf-string.js +30 -0
- package/dist/core/objects/pdf-trailer.d.ts +26 -0
- package/dist/core/objects/pdf-trailer.js +33 -0
- package/dist/core/objects/pdf-xref-table.d.ts +48 -0
- package/dist/core/objects/pdf-xref-table.js +183 -0
- package/{packages/pdf-lite/src/core/parser.ts → dist/core/parser.d.ts} +3 -4
- package/dist/core/parser.js +9 -0
- package/dist/core/ref.d.ts +59 -0
- package/{packages/pdf-lite/src/core/ref.ts → dist/core/ref.js} +23 -41
- package/dist/core/serializer.d.ts +36 -0
- package/{packages/pdf-lite/src/core/serializer.ts → dist/core/serializer.js} +20 -30
- package/dist/core/streams/object-stream.d.ts +6 -0
- package/dist/core/streams/object-stream.js +15 -0
- package/dist/core/tokeniser.d.ts +98 -0
- package/dist/core/tokeniser.js +552 -0
- package/dist/core/tokens/boolean-token.d.ts +8 -0
- package/dist/core/tokens/boolean-token.js +15 -0
- package/dist/core/tokens/byte-offset-token.d.ts +8 -0
- package/dist/core/tokens/byte-offset-token.js +15 -0
- package/dist/core/tokens/comment-token.d.ts +10 -0
- package/dist/core/tokens/comment-token.js +26 -0
- package/dist/core/tokens/end-array-token.d.ts +4 -0
- package/dist/core/tokens/end-array-token.js +8 -0
- package/dist/core/tokens/end-dictionary-token.d.ts +4 -0
- package/dist/core/tokens/end-dictionary-token.js +8 -0
- package/dist/core/tokens/end-object-token.d.ts +4 -0
- package/dist/core/tokens/end-object-token.js +8 -0
- package/dist/core/tokens/end-stream-token.d.ts +5 -0
- package/dist/core/tokens/end-stream-token.js +8 -0
- package/dist/core/tokens/hexadecimal-token.d.ts +7 -0
- package/dist/core/tokens/hexadecimal-token.js +16 -0
- package/dist/core/tokens/name-token.d.ts +6 -0
- package/dist/core/tokens/name-token.js +15 -0
- package/dist/core/tokens/null-token.d.ts +4 -0
- package/dist/core/tokens/null-token.js +8 -0
- package/dist/core/tokens/number-token.d.ts +24 -0
- package/dist/core/tokens/number-token.js +104 -0
- package/dist/core/tokens/object-reference-token.d.ts +7 -0
- package/dist/core/tokens/object-reference-token.js +17 -0
- package/dist/core/tokens/start-array-token.d.ts +4 -0
- package/dist/core/tokens/start-array-token.js +8 -0
- package/dist/core/tokens/start-dictionary-token.d.ts +4 -0
- package/dist/core/tokens/start-dictionary-token.js +8 -0
- package/dist/core/tokens/start-object-token.d.ts +8 -0
- package/dist/core/tokens/start-object-token.js +17 -0
- package/dist/core/tokens/start-stream-token.d.ts +8 -0
- package/dist/core/tokens/start-stream-token.js +38 -0
- package/dist/core/tokens/start-xref-token.d.ts +4 -0
- package/dist/core/tokens/start-xref-token.js +8 -0
- package/dist/core/tokens/stream-chunk-token.d.ts +5 -0
- package/dist/core/tokens/stream-chunk-token.js +6 -0
- package/dist/core/tokens/string-token.d.ts +7 -0
- package/dist/core/tokens/string-token.js +13 -0
- package/dist/core/tokens/token.d.ts +10 -0
- package/dist/core/tokens/token.js +32 -0
- package/dist/core/tokens/trailer-token.d.ts +5 -0
- package/dist/core/tokens/trailer-token.js +10 -0
- package/dist/core/tokens/whitespace-token.d.ts +11 -0
- package/dist/core/tokens/whitespace-token.js +36 -0
- package/dist/core/tokens/xref-table-entry-token.d.ts +13 -0
- package/dist/core/tokens/xref-table-entry-token.js +40 -0
- package/dist/core/tokens/xref-table-section-start-token.d.ts +8 -0
- package/dist/core/tokens/xref-table-section-start-token.js +21 -0
- package/dist/core/tokens/xref-table-start-token.d.ts +5 -0
- package/dist/core/tokens/xref-table-start-token.js +10 -0
- package/dist/crypto/ciphers/aes128.d.ts +19 -0
- package/{packages/pdf-lite/src/crypto/ciphers/aes128.ts → dist/crypto/ciphers/aes128.js} +17 -27
- package/dist/crypto/ciphers/aes256.d.ts +18 -0
- package/{packages/pdf-lite/src/crypto/ciphers/aes256.ts → dist/crypto/ciphers/aes256.js} +14 -17
- package/dist/crypto/ciphers/rc4.d.ts +18 -0
- package/{packages/pdf-lite/src/crypto/ciphers/rc4.ts → dist/crypto/ciphers/rc4.js} +25 -30
- package/dist/crypto/constants.d.ts +6 -0
- package/{packages/pdf-lite/src/crypto/constants.ts → dist/crypto/constants.js} +1 -1
- package/dist/crypto/key-derivation/key-derivation-aes256.d.ts +56 -0
- package/dist/crypto/key-derivation/key-derivation-aes256.js +156 -0
- package/dist/crypto/key-derivation/key-derivation.d.ts +42 -0
- package/{packages/pdf-lite/src/crypto/key-derivation/key-derivation.ts → dist/crypto/key-derivation/key-derivation.js} +35 -66
- package/dist/crypto/key-gen/key-gen-aes256.d.ts +36 -0
- package/{packages/pdf-lite/src/crypto/key-gen/key-gen-aes256.ts → dist/crypto/key-gen/key-gen-aes256.js} +25 -50
- package/dist/crypto/key-gen/key-gen-rc4-128.d.ts +47 -0
- package/{packages/pdf-lite/src/crypto/key-gen/key-gen-rc4-128.ts → dist/crypto/key-gen/key-gen-rc4-128.js} +45 -106
- package/dist/crypto/key-gen/key-gen-rc4-40.d.ts +60 -0
- package/{packages/pdf-lite/src/crypto/key-gen/key-gen-rc4-40.ts → dist/crypto/key-gen/key-gen-rc4-40.js} +26 -62
- package/dist/crypto/types.d.ts +5 -0
- package/dist/crypto/types.js +1 -0
- package/dist/crypto/utils.d.ts +40 -0
- package/{packages/pdf-lite/src/crypto/utils.ts → dist/crypto/utils.js} +27 -36
- package/dist/filters/ascii85.d.ts +16 -0
- package/{packages/pdf-lite/src/filters/ascii85.ts → dist/filters/ascii85.js} +41 -65
- package/dist/filters/asciihex.d.ts +16 -0
- package/{packages/pdf-lite/src/filters/asciihex.ts → dist/filters/asciihex.js} +18 -19
- package/dist/filters/flate.d.ts +15 -0
- package/{packages/pdf-lite/src/filters/flate.ts → dist/filters/flate.js} +7 -10
- package/dist/filters/lzw.d.ts +16 -0
- package/dist/filters/lzw.js +150 -0
- package/dist/filters/pass-through.d.ts +14 -0
- package/{packages/pdf-lite/src/filters/pass-through.ts → dist/filters/pass-through.js} +6 -9
- package/dist/filters/runlength.d.ts +16 -0
- package/{packages/pdf-lite/src/filters/runlength.ts → dist/filters/runlength.js} +36 -40
- package/dist/filters/types.d.ts +18 -0
- package/{packages/pdf-lite/src/filters/types.ts → dist/filters/types.js} +1 -10
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/pdf/errors.d.ts +6 -0
- package/{packages/pdf-lite/src/pdf/errors.ts → dist/pdf/errors.js} +2 -1
- package/dist/pdf/index.d.ts +4 -0
- package/dist/pdf/index.js +4 -0
- package/dist/pdf/pdf-document.d.ts +277 -0
- package/{packages/pdf-lite/src/pdf/pdf-document.ts → dist/pdf/pdf-document.js} +305 -541
- package/dist/pdf/pdf-reader.d.ts +37 -0
- package/{packages/pdf-lite/src/pdf/pdf-reader.ts → dist/pdf/pdf-reader.js} +12 -22
- package/dist/pdf/pdf-revision.d.ts +101 -0
- package/{packages/pdf-lite/src/pdf/pdf-revision.ts → dist/pdf/pdf-revision.js} +70 -105
- package/dist/pdf/pdf-xref-lookup.d.ts +149 -0
- package/dist/pdf/pdf-xref-lookup.js +402 -0
- package/dist/security/crypt-filters/aesv2.d.ts +35 -0
- package/{packages/pdf-lite/src/security/crypt-filters/aesv2.ts → dist/security/crypt-filters/aesv2.js} +9 -26
- package/dist/security/crypt-filters/aesv3.d.ts +36 -0
- package/{packages/pdf-lite/src/security/crypt-filters/aesv3.ts → dist/security/crypt-filters/aesv3.js} +9 -23
- package/{packages/pdf-lite/src/security/crypt-filters/base.ts → dist/security/crypt-filters/base.d.ts} +21 -73
- package/dist/security/crypt-filters/base.js +93 -0
- package/dist/security/crypt-filters/identity.d.ts +28 -0
- package/{packages/pdf-lite/src/security/crypt-filters/identity.ts → dist/security/crypt-filters/identity.js} +9 -13
- package/dist/security/crypt-filters/v2.d.ts +37 -0
- package/{packages/pdf-lite/src/security/crypt-filters/v2.ts → dist/security/crypt-filters/v2.js} +9 -26
- package/dist/security/handlers/base.d.ts +304 -0
- package/dist/security/handlers/base.js +359 -0
- package/dist/security/handlers/pubSec.d.ts +164 -0
- package/dist/security/handlers/pubSec.js +299 -0
- package/dist/security/handlers/utils.d.ts +77 -0
- package/dist/security/handlers/utils.js +244 -0
- package/dist/security/handlers/v1.d.ts +81 -0
- package/dist/security/handlers/v1.js +135 -0
- package/dist/security/handlers/v2.d.ts +63 -0
- package/{packages/pdf-lite/src/security/handlers/v2.ts → dist/security/handlers/v2.js} +25 -62
- package/dist/security/handlers/v4.d.ts +121 -0
- package/dist/security/handlers/v4.js +257 -0
- package/dist/security/handlers/v5.d.ts +112 -0
- package/dist/security/handlers/v5.js +210 -0
- package/{packages/pdf-lite/src/security/types.ts → dist/security/types.d.ts} +72 -94
- package/dist/security/types.js +1 -0
- package/dist/signing/document-security-store.d.ts +108 -0
- package/dist/signing/document-security-store.js +156 -0
- package/dist/signing/index.d.ts +3 -0
- package/dist/signing/index.js +3 -0
- package/dist/signing/signatures/adbe-pkcs7-detached.d.ts +57 -0
- package/dist/signing/signatures/adbe-pkcs7-detached.js +117 -0
- package/dist/signing/signatures/adbe-pkcs7-sha1.d.ts +55 -0
- package/dist/signing/signatures/adbe-pkcs7-sha1.js +121 -0
- package/dist/signing/signatures/adbe-x509-rsa-sha1.d.ts +49 -0
- package/dist/signing/signatures/adbe-x509-rsa-sha1.js +81 -0
- package/dist/signing/signatures/base.d.ts +107 -0
- package/dist/signing/signatures/base.js +145 -0
- package/dist/signing/signatures/etsi-cades-detached.d.ts +64 -0
- package/dist/signing/signatures/etsi-cades-detached.js +159 -0
- package/dist/signing/signatures/etsi-rfc3161.d.ts +37 -0
- package/{packages/pdf-lite/src/signing/signatures/etsi-rfc3161.ts → dist/signing/signatures/etsi-rfc3161.js} +21 -43
- package/dist/signing/signatures/index.d.ts +6 -0
- package/dist/signing/signatures/index.js +6 -0
- package/dist/signing/signer.d.ts +23 -0
- package/dist/signing/signer.js +92 -0
- package/{packages/pdf-lite/src/signing/types.ts → dist/signing/types.d.ts} +40 -48
- package/dist/signing/types.js +1 -0
- package/dist/signing/utils.d.ts +32 -0
- package/{packages/pdf-lite/src/signing/utils.ts → dist/signing/utils.js} +12 -31
- package/dist/types.d.ts +23 -0
- package/dist/types.js +11 -0
- package/dist/utils/IterableReadableStream.d.ts +24 -0
- package/{packages/pdf-lite/src/utils/IterableReadableStream.ts → dist/utils/IterableReadableStream.js} +6 -6
- package/dist/utils/algos.d.ts +242 -0
- package/{packages/pdf-lite/src/utils/algos.ts → dist/utils/algos.js} +63 -136
- package/dist/utils/assert.d.ts +28 -0
- package/{packages/pdf-lite/src/utils/assert.ts → dist/utils/assert.js} +5 -10
- package/dist/utils/bytesToHex.d.ts +13 -0
- package/{packages/pdf-lite/src/utils/bytesToHex.ts → dist/utils/bytesToHex.js} +4 -6
- package/dist/utils/bytesToHexBytes.d.ts +14 -0
- package/{packages/pdf-lite/src/utils/bytesToHexBytes.ts → dist/utils/bytesToHexBytes.js} +7 -12
- package/dist/utils/bytesToString.d.ts +13 -0
- package/{packages/pdf-lite/src/utils/bytesToString.ts → dist/utils/bytesToString.js} +3 -5
- package/dist/utils/concatUint8Arrays.d.ts +16 -0
- package/{packages/pdf-lite/src/utils/concatUint8Arrays.ts → dist/utils/concatUint8Arrays.js} +7 -9
- package/dist/utils/escapeString.d.ts +14 -0
- package/dist/utils/escapeString.js +43 -0
- package/dist/utils/hexBytesToBytes.d.ts +15 -0
- package/{packages/pdf-lite/src/utils/hexBytesToBytes.ts → dist/utils/hexBytesToBytes.js} +4 -6
- package/dist/utils/hexBytesToString.d.ts +13 -0
- package/{packages/pdf-lite/src/utils/hexBytesToString.ts → dist/utils/hexBytesToString.js} +5 -7
- package/dist/utils/hexToBytes.d.ts +13 -0
- package/{packages/pdf-lite/src/utils/hexToBytes.ts → dist/utils/hexToBytes.js} +4 -6
- package/dist/utils/padBytes.d.ts +15 -0
- package/{packages/pdf-lite/src/utils/padBytes.ts → dist/utils/padBytes.js} +5 -9
- package/dist/utils/predictors.d.ts +113 -0
- package/{packages/pdf-lite/src/utils/predictors.ts → dist/utils/predictors.js} +103 -156
- package/dist/utils/replaceInBuffer.d.ts +22 -0
- package/{packages/pdf-lite/src/utils/replaceInBuffer.ts → dist/utils/replaceInBuffer.js} +18 -27
- package/dist/utils/stringToBytes.d.ts +14 -0
- package/{packages/pdf-lite/src/utils/stringToBytes.ts → dist/utils/stringToBytes.js} +6 -7
- package/dist/utils/stringToHexBytes.d.ts +15 -0
- package/{packages/pdf-lite/src/utils/stringToHexBytes.ts → dist/utils/stringToHexBytes.js} +5 -7
- package/dist/utils/unescapeString.d.ts +16 -0
- package/dist/utils/unescapeString.js +114 -0
- package/package.json +37 -34
- package/.commitlintrc.cjs +0 -25
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -19
- package/.github/workflows/docs.yaml +0 -95
- package/.github/workflows/prepare-release.yaml +0 -79
- package/.github/workflows/release.yaml +0 -80
- package/.github/workflows/test.yaml +0 -35
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.prettierignore +0 -4
- package/.prettierrc +0 -4
- package/CONTRIBUTING.md +0 -109
- package/EXAMPLES.md +0 -1512
- package/docs/README.md +0 -127
- package/docs/core/README.md +0 -43
- package/docs/core/decoder/README.md +0 -11
- package/docs/core/decoder/classes/PdfDecoder.md +0 -362
- package/docs/core/generators/README.md +0 -14
- package/docs/core/generators/functions/bytesToPdfObjects.md +0 -26
- package/docs/core/generators/functions/pdfDecoder.md +0 -36
- package/docs/core/generators/functions/pdfDecoderAsync.md +0 -26
- package/docs/core/generators/functions/stringToPdfObjects.md +0 -25
- package/docs/core/incremental-parser/README.md +0 -13
- package/docs/core/incremental-parser/classes/EofReachedError.md +0 -55
- package/docs/core/incremental-parser/classes/IncrementalParser.md +0 -299
- package/docs/core/incremental-parser/classes/NoMoreTokensError.md +0 -55
- package/docs/core/objects/pdf-array/README.md +0 -11
- package/docs/core/objects/pdf-array/classes/PdfArray.md +0 -305
- package/docs/core/objects/pdf-boolean/README.md +0 -11
- package/docs/core/objects/pdf-boolean/classes/PdfBoolean.md +0 -265
- package/docs/core/objects/pdf-comment/README.md +0 -11
- package/docs/core/objects/pdf-comment/classes/PdfComment.md +0 -329
- package/docs/core/objects/pdf-date/README.md +0 -11
- package/docs/core/objects/pdf-date/classes/PdfDate.md +0 -317
- package/docs/core/objects/pdf-dictionary/README.md +0 -17
- package/docs/core/objects/pdf-dictionary/classes/PdfDictionary.md +0 -396
- package/docs/core/objects/pdf-dictionary/type-aliases/PdfDictionaryEntries.md +0 -9
- package/docs/core/objects/pdf-dictionary/type-aliases/PdfDictionaryEntry.md +0 -9
- package/docs/core/objects/pdf-dictionary/type-aliases/PdfDictionaryMap.md +0 -9
- package/docs/core/objects/pdf-hexadecimal/README.md +0 -11
- package/docs/core/objects/pdf-hexadecimal/classes/PdfHexadecimal.md +0 -320
- package/docs/core/objects/pdf-indirect-object/README.md +0 -11
- package/docs/core/objects/pdf-indirect-object/classes/PdfIndirectObject.md +0 -411
- package/docs/core/objects/pdf-name/README.md +0 -11
- package/docs/core/objects/pdf-name/classes/PdfName.md +0 -271
- package/docs/core/objects/pdf-null/README.md +0 -11
- package/docs/core/objects/pdf-null/classes/PdfNull.md +0 -259
- package/docs/core/objects/pdf-number/README.md +0 -12
- package/docs/core/objects/pdf-number/classes/PdfByteOffsetNumber.md +0 -369
- package/docs/core/objects/pdf-number/classes/PdfNumber.md +0 -345
- package/docs/core/objects/pdf-object/README.md +0 -11
- package/docs/core/objects/pdf-object/classes/PdfObject.md +0 -214
- package/docs/core/objects/pdf-object-reference/README.md +0 -11
- package/docs/core/objects/pdf-object-reference/classes/PdfObjectReference.md +0 -279
- package/docs/core/objects/pdf-start-xref/README.md +0 -11
- package/docs/core/objects/pdf-start-xref/classes/PdfStartXRef.md +0 -265
- package/docs/core/objects/pdf-stream/README.md +0 -23
- package/docs/core/objects/pdf-stream/classes/PdfObjStream.md +0 -699
- package/docs/core/objects/pdf-stream/classes/PdfStream.md +0 -570
- package/docs/core/objects/pdf-stream/classes/PdfXRefStream.md +0 -723
- package/docs/core/objects/pdf-stream/classes/PdfXRefStreamCompressedEntry.md +0 -51
- package/docs/core/objects/pdf-stream/type-aliases/PdfXRefStreamEntry.md +0 -9
- package/docs/core/objects/pdf-stream/type-aliases/PdfXRefStreamStandardEntry.md +0 -9
- package/docs/core/objects/pdf-stream/variables/PdfXRefStreamStandardEntry.md +0 -9
- package/docs/core/objects/pdf-string/README.md +0 -11
- package/docs/core/objects/pdf-string/classes/PdfString.md +0 -301
- package/docs/core/objects/pdf-trailer/README.md +0 -16
- package/docs/core/objects/pdf-trailer/classes/PdfTrailer.md +0 -271
- package/docs/core/objects/pdf-trailer/type-aliases/PdfTrailerDictionary.md +0 -9
- package/docs/core/objects/pdf-trailer/type-aliases/PdfTrailerEntries.md +0 -51
- package/docs/core/objects/pdf-xref-table/README.md +0 -13
- package/docs/core/objects/pdf-xref-table/classes/PdfXRefTable.md +0 -331
- package/docs/core/objects/pdf-xref-table/classes/PdfXRefTableEntry.md +0 -297
- package/docs/core/objects/pdf-xref-table/classes/PdfXRefTableSectionHeader.md +0 -277
- package/docs/core/parser/README.md +0 -11
- package/docs/core/parser/classes/Parser.md +0 -74
- package/docs/core/ref/README.md +0 -15
- package/docs/core/ref/classes/Ref.md +0 -149
- package/docs/core/ref/type-aliases/RefUpdateCallback.md +0 -33
- package/docs/core/serializer/README.md +0 -11
- package/docs/core/serializer/classes/PdfTokenSerializer.md +0 -106
- package/docs/core/streams/object-stream/README.md +0 -11
- package/docs/core/streams/object-stream/classes/PdfObjectStream.md +0 -69
- package/docs/core/tokeniser/README.md +0 -21
- package/docs/core/tokeniser/classes/PdfByteStreamTokeniser.md +0 -366
- package/docs/core/tokeniser/classes/PdfObjectTokeniser.md +0 -69
- package/docs/core/tokeniser/functions/objectToTokens.md +0 -25
- package/docs/core/tokeniser/functions/pdfObjectStreamTokeniser.md +0 -27
- package/docs/core/tokeniser/type-aliases/PdfTokeniser.md +0 -11
- package/docs/core/tokens/boolean-token/README.md +0 -11
- package/docs/core/tokens/boolean-token/classes/PdfBooleanToken.md +0 -139
- package/docs/core/tokens/byte-offset-token/README.md +0 -11
- package/docs/core/tokens/byte-offset-token/classes/PdfByteOffsetToken.md +0 -153
- package/docs/core/tokens/comment-token/README.md +0 -11
- package/docs/core/tokens/comment-token/classes/PdfCommentToken.md +0 -161
- package/docs/core/tokens/end-array-token/README.md +0 -11
- package/docs/core/tokens/end-array-token/classes/PdfEndArrayToken.md +0 -115
- package/docs/core/tokens/end-dictionary-token/README.md +0 -11
- package/docs/core/tokens/end-dictionary-token/classes/PdfEndDictionaryToken.md +0 -115
- package/docs/core/tokens/end-object-token/README.md +0 -11
- package/docs/core/tokens/end-object-token/classes/PdfEndObjectToken.md +0 -115
- package/docs/core/tokens/end-stream-token/README.md +0 -11
- package/docs/core/tokens/end-stream-token/classes/PdfEndStreamToken.md +0 -121
- package/docs/core/tokens/hexadecimal-token/README.md +0 -11
- package/docs/core/tokens/hexadecimal-token/classes/PdfHexadecimalToken.md +0 -127
- package/docs/core/tokens/name-token/README.md +0 -11
- package/docs/core/tokens/name-token/classes/PdfNameToken.md +0 -127
- package/docs/core/tokens/null-token/README.md +0 -11
- package/docs/core/tokens/null-token/classes/PdfNullToken.md +0 -115
- package/docs/core/tokens/number-token/README.md +0 -11
- package/docs/core/tokens/number-token/classes/PdfNumberToken.md +0 -271
- package/docs/core/tokens/object-reference-token/README.md +0 -11
- package/docs/core/tokens/object-reference-token/classes/PdfObjectReferenceToken.md +0 -137
- package/docs/core/tokens/start-array-token/README.md +0 -11
- package/docs/core/tokens/start-array-token/classes/PdfStartArrayToken.md +0 -115
- package/docs/core/tokens/start-dictionary-token/README.md +0 -11
- package/docs/core/tokens/start-dictionary-token/classes/PdfStartDictionaryToken.md +0 -115
- package/docs/core/tokens/start-object-token/README.md +0 -11
- package/docs/core/tokens/start-object-token/classes/PdfStartObjectToken.md +0 -147
- package/docs/core/tokens/start-stream-token/README.md +0 -11
- package/docs/core/tokens/start-stream-token/classes/PdfStartStreamToken.md +0 -147
- package/docs/core/tokens/start-xref-token/README.md +0 -11
- package/docs/core/tokens/start-xref-token/classes/PdfStartXRefToken.md +0 -115
- package/docs/core/tokens/stream-chunk-token/README.md +0 -11
- package/docs/core/tokens/stream-chunk-token/classes/PdfStreamChunkToken.md +0 -121
- package/docs/core/tokens/string-token/README.md +0 -11
- package/docs/core/tokens/string-token/classes/PdfStringToken.md +0 -127
- package/docs/core/tokens/token/README.md +0 -11
- package/docs/core/tokens/token/classes/PdfToken.md +0 -116
- package/docs/core/tokens/trailer-token/README.md +0 -11
- package/docs/core/tokens/trailer-token/classes/PdfTrailerToken.md +0 -127
- package/docs/core/tokens/whitespace-token/README.md +0 -11
- package/docs/core/tokens/whitespace-token/classes/PdfWhitespaceToken.md +0 -161
- package/docs/core/tokens/xref-table-entry-token/README.md +0 -11
- package/docs/core/tokens/xref-table-entry-token/classes/PdfXRefTableEntryToken.md +0 -157
- package/docs/core/tokens/xref-table-section-start-token/README.md +0 -11
- package/docs/core/tokens/xref-table-section-start-token/classes/PdfXRefTableSectionStartToken.md +0 -137
- package/docs/core/tokens/xref-table-start-token/README.md +0 -11
- package/docs/core/tokens/xref-table-start-token/classes/PdfXRefTableStartToken.md +0 -127
- package/docs/crypto/ciphers/aes128/README.md +0 -11
- package/docs/crypto/ciphers/aes128/functions/aes128.md +0 -39
- package/docs/crypto/ciphers/aes256/README.md +0 -11
- package/docs/crypto/ciphers/aes256/functions/aes256.md +0 -35
- package/docs/crypto/ciphers/rc4/README.md +0 -11
- package/docs/crypto/ciphers/rc4/functions/rc4.md +0 -35
- package/docs/crypto/constants/README.md +0 -11
- package/docs/crypto/constants/variables/DEFAULT_PADDING.md +0 -13
- package/docs/crypto/key-derivation/key-derivation/README.md +0 -13
- package/docs/crypto/key-derivation/key-derivation/functions/computeMasterKey.md +0 -57
- package/docs/crypto/key-derivation/key-derivation/functions/deriveObjectKey.md +0 -50
- package/docs/crypto/key-derivation/key-derivation/functions/padPassword.md +0 -33
- package/docs/crypto/key-derivation/key-derivation-aes256/README.md +0 -13
- package/docs/crypto/key-derivation/key-derivation-aes256/functions/computeAlgorithm2bHash.md +0 -45
- package/docs/crypto/key-derivation/key-derivation-aes256/functions/getFileKey.md +0 -66
- package/docs/crypto/key-derivation/key-derivation-aes256/functions/validatePasswordHash.md +0 -52
- package/docs/crypto/key-gen/key-gen-aes256/README.md +0 -12
- package/docs/crypto/key-gen/key-gen-aes256/functions/generateOandOe.md +0 -44
- package/docs/crypto/key-gen/key-gen-aes256/functions/generateUandUe.md +0 -38
- package/docs/crypto/key-gen/key-gen-rc4-128/README.md +0 -13
- package/docs/crypto/key-gen/key-gen-rc4-128/functions/computeOValueRc4_128.md +0 -38
- package/docs/crypto/key-gen/key-gen-rc4-128/functions/computeUValueRc4_128.md +0 -62
- package/docs/crypto/key-gen/key-gen-rc4-128/functions/decryptUserPasswordRc4_128.md +0 -38
- package/docs/crypto/key-gen/key-gen-rc4-40/README.md +0 -14
- package/docs/crypto/key-gen/key-gen-rc4-40/functions/computeEncryptionKeyRc4_40.md +0 -49
- package/docs/crypto/key-gen/key-gen-rc4-40/functions/computeORc4_40.md +0 -38
- package/docs/crypto/key-gen/key-gen-rc4-40/functions/computeURc4_40.md +0 -50
- package/docs/crypto/key-gen/key-gen-rc4-40/functions/decryptUserPasswordRc4_40.md +0 -38
- package/docs/crypto/types/README.md +0 -11
- package/docs/crypto/types/interfaces/Cipher.md +0 -39
- package/docs/crypto/utils/README.md +0 -13
- package/docs/crypto/utils/functions/int32ToLittleEndianBytes.md +0 -31
- package/docs/crypto/utils/functions/padPassword.md +0 -33
- package/docs/crypto/utils/functions/removePdfPasswordPadding.md +0 -32
- package/docs/filters/ascii85/README.md +0 -11
- package/docs/filters/ascii85/functions/ascii85.md +0 -27
- package/docs/filters/asciihex/README.md +0 -11
- package/docs/filters/asciihex/functions/asciiHex.md +0 -27
- package/docs/filters/flate/README.md +0 -11
- package/docs/filters/flate/functions/flate.md +0 -26
- package/docs/filters/lzw/README.md +0 -11
- package/docs/filters/lzw/functions/lzw.md +0 -27
- package/docs/filters/pass-through/README.md +0 -11
- package/docs/filters/pass-through/functions/passthroughFilter.md +0 -25
- package/docs/filters/runlength/README.md +0 -11
- package/docs/filters/runlength/functions/runLength.md +0 -27
- package/docs/filters/types/README.md +0 -19
- package/docs/filters/types/interfaces/PdfFilter.md +0 -39
- package/docs/filters/types/type-aliases/PdfStreamFilterType.md +0 -9
- package/docs/filters/types/variables/PDF_FILTER_TYPES.md +0 -51
- package/docs/index/README.md +0 -235
- package/docs/pdf/README.md +0 -31
- package/docs/pdf/errors/README.md +0 -11
- package/docs/pdf/errors/classes/FoundCompressedObjectError.md +0 -56
- package/docs/pdf/pdf-document/README.md +0 -11
- package/docs/pdf/pdf-document/classes/PdfDocument.md +0 -876
- package/docs/pdf/pdf-reader/README.md +0 -11
- package/docs/pdf/pdf-reader/classes/PdfReader.md +0 -82
- package/docs/pdf/pdf-revision/README.md +0 -11
- package/docs/pdf/pdf-revision/classes/PdfRevision.md +0 -508
- package/docs/pdf/pdf-xref-lookup/README.md +0 -11
- package/docs/pdf/pdf-xref-lookup/classes/PdfXrefLookup.md +0 -421
- package/docs/security/crypt-filters/aesv2/README.md +0 -11
- package/docs/security/crypt-filters/aesv2/classes/AesV2CryptFilter.md +0 -274
- package/docs/security/crypt-filters/aesv3/README.md +0 -11
- package/docs/security/crypt-filters/aesv3/classes/AesV3CryptFilter.md +0 -275
- package/docs/security/crypt-filters/base/README.md +0 -15
- package/docs/security/crypt-filters/base/classes/PdfCryptFilter.md +0 -221
- package/docs/security/crypt-filters/base/type-aliases/CryptFilterOptions.md +0 -43
- package/docs/security/crypt-filters/identity/README.md +0 -11
- package/docs/security/crypt-filters/identity/classes/IdentityCryptFilter.md +0 -249
- package/docs/security/crypt-filters/v2/README.md +0 -11
- package/docs/security/crypt-filters/v2/classes/V2CryptFilter.md +0 -279
- package/docs/security/handlers/base/README.md +0 -17
- package/docs/security/handlers/base/classes/PdfSecurityHandler.md +0 -384
- package/docs/security/handlers/base/classes/PdfStandardSecurityHandler.md +0 -694
- package/docs/security/handlers/base/type-aliases/PdfSecurityHandlerOptions.md +0 -27
- package/docs/security/handlers/base/type-aliases/PdfStandardSecurityHandlerOptions.md +0 -43
- package/docs/security/handlers/pubSec/README.md +0 -11
- package/docs/security/handlers/pubSec/classes/PdfPublicKeySecurityHandler.md +0 -503
- package/docs/security/handlers/utils/README.md +0 -14
- package/docs/security/handlers/utils/functions/createFromDictionary.md +0 -56
- package/docs/security/handlers/utils/functions/createFromEncryptionOptions.md +0 -40
- package/docs/security/handlers/utils/functions/createStandardSecurityHandlerFromDictionary.md +0 -55
- package/docs/security/handlers/utils/functions/getCryptFilter.md +0 -35
- package/docs/security/handlers/v1/README.md +0 -11
- package/docs/security/handlers/v1/classes/PdfV1SecurityHandler.md +0 -779
- package/docs/security/handlers/v2/README.md +0 -11
- package/docs/security/handlers/v2/classes/PdfV2SecurityHandler.md +0 -783
- package/docs/security/handlers/v4/README.md +0 -11
- package/docs/security/handlers/v4/classes/PdfV4SecurityHandler.md +0 -907
- package/docs/security/handlers/v5/README.md +0 -11
- package/docs/security/handlers/v5/classes/PdfV5SecurityHandler.md +0 -926
- package/docs/security/types/README.md +0 -19
- package/docs/security/types/type-aliases/CryptFilterType.md +0 -15
- package/docs/security/types/type-aliases/PdfCryptFilterDictionary.md +0 -12
- package/docs/security/types/type-aliases/PdfEncryptionAlgorithmOptions.md +0 -11
- package/docs/security/types/type-aliases/PdfEncryptionAlgorithmType.md +0 -17
- package/docs/security/types/type-aliases/PdfEncryptionDictionary.md +0 -13
- package/docs/security/types/type-aliases/PdfEncryptionDictionaryObject.md +0 -11
- package/docs/security/types/type-aliases/PdfEncryptionOptions.md +0 -90
- package/docs/security/types/type-aliases/PdfEncryptionRecipient.md +0 -24
- package/docs/security/types/type-aliases/PdfId.md +0 -13
- package/docs/signing/README.md +0 -127
- package/docs/signing/document-security-store/README.md +0 -19
- package/docs/signing/document-security-store/classes/PdfCertObject.md +0 -443
- package/docs/signing/document-security-store/classes/PdfCrlObject.md +0 -443
- package/docs/signing/document-security-store/classes/PdfDocumentSecurityStoreDictionary.md +0 -416
- package/docs/signing/document-security-store/classes/PdfDocumentSecurityStoreObject.md +0 -563
- package/docs/signing/document-security-store/classes/PdfOcspObject.md +0 -443
- package/docs/signing/document-security-store/type-aliases/PdfVriObject.md +0 -12
- package/docs/signing/signatures/README.md +0 -55
- package/docs/signing/signatures/adbe-pkcs7-detached/README.md +0 -11
- package/docs/signing/signatures/adbe-pkcs7-detached/classes/PdfAdbePkcs7DetachedSignatureObject.md +0 -669
- package/docs/signing/signatures/adbe-pkcs7-sha1/README.md +0 -11
- package/docs/signing/signatures/adbe-pkcs7-sha1/classes/PdfAdbePkcs7Sha1SignatureObject.md +0 -667
- package/docs/signing/signatures/adbe-x509-rsa-sha1/README.md +0 -11
- package/docs/signing/signatures/adbe-x509-rsa-sha1/classes/PdfAdbePkcsX509RsaSha1SignatureObject.md +0 -651
- package/docs/signing/signatures/base/README.md +0 -16
- package/docs/signing/signatures/base/classes/PdfSignatureDictionary.md +0 -420
- package/docs/signing/signatures/base/classes/PdfSignatureObject.md +0 -584
- package/docs/signing/signatures/base/type-aliases/PdfSignatureSignOptions.md +0 -51
- package/docs/signing/signatures/etsi-cades-detached/README.md +0 -11
- package/docs/signing/signatures/etsi-cades-detached/classes/PdfEtsiCadesDetachedSignatureObject.md +0 -693
- package/docs/signing/signatures/etsi-rfc3161/README.md +0 -11
- package/docs/signing/signatures/etsi-rfc3161/classes/PdfEtsiRfc3161SignatureObject.md +0 -614
- package/docs/signing/signer/README.md +0 -11
- package/docs/signing/signer/classes/PdfSigner.md +0 -58
- package/docs/signing/types/README.md +0 -16
- package/docs/signing/types/type-aliases/PdfSignatureDictionaryEntries.md +0 -95
- package/docs/signing/types/type-aliases/PdfSignatureSubType.md +0 -17
- package/docs/signing/types/type-aliases/PdfSignatureType.md +0 -14
- package/docs/signing/types/type-aliases/RevocationInfo.md +0 -43
- package/docs/signing/types/type-aliases/SignaturePolicyDocument.md +0 -35
- package/docs/signing/types/type-aliases/TimeStampAuthority.md +0 -35
- package/docs/signing/utils/README.md +0 -11
- package/docs/signing/utils/functions/fetchRevocationInfo.md +0 -70
- package/docs/types/README.md +0 -21
- package/docs/types/type-aliases/ByteArray.md +0 -9
- package/docs/types/type-aliases/ChangeType.md +0 -9
- package/docs/types/type-aliases/DecodeParms.md +0 -33
- package/docs/types/type-aliases/HashAlgorithm.md +0 -9
- package/docs/types/type-aliases/PdfEncryptionAlgorithm.md +0 -9
- package/docs/types/type-aliases/PdfPermissions.md +0 -63
- package/docs/types/type-aliases/PdfVersion.md +0 -9
- package/docs/types/variables/PERMISSION_FLAGS.md +0 -9
- package/docs/utils/IterableReadableStream/README.md +0 -11
- package/docs/utils/IterableReadableStream/classes/IterableReadableStream.md +0 -103
- package/docs/utils/algos/README.md +0 -28
- package/docs/utils/algos/functions/aes128CbcNoPaddingEncrypt.md +0 -43
- package/docs/utils/algos/functions/aes128cbcDecrypt.md +0 -47
- package/docs/utils/algos/functions/aes128cbcEncrypt.md +0 -47
- package/docs/utils/algos/functions/aes256CbcNoPaddingDecrypt.md +0 -43
- package/docs/utils/algos/functions/aes256CbcNoPaddingEncrypt.md +0 -43
- package/docs/utils/algos/functions/aes256cbcDecrypt.md +0 -43
- package/docs/utils/algos/functions/aes256cbcEncrypt.md +0 -43
- package/docs/utils/algos/functions/aes256ecbDecrypt.md +0 -41
- package/docs/utils/algos/functions/aes256ecbEncrypt.md +0 -41
- package/docs/utils/algos/functions/deflateData.md +0 -31
- package/docs/utils/algos/functions/getRandomBytes.md +0 -35
- package/docs/utils/algos/functions/hash.md +0 -41
- package/docs/utils/algos/functions/inflateData.md +0 -35
- package/docs/utils/algos/functions/md5.md +0 -31
- package/docs/utils/algos/functions/sha1.md +0 -31
- package/docs/utils/algos/functions/sha256.md +0 -31
- package/docs/utils/algos/functions/sha384.md +0 -31
- package/docs/utils/algos/functions/sha512.md +0 -31
- package/docs/utils/assert/README.md +0 -12
- package/docs/utils/assert/functions/assert.md +0 -39
- package/docs/utils/assert/functions/assertIfDefined.md +0 -46
- package/docs/utils/bytesToHex/README.md +0 -11
- package/docs/utils/bytesToHex/functions/bytesToHex.md +0 -31
- package/docs/utils/bytesToHexBytes/README.md +0 -11
- package/docs/utils/bytesToHexBytes/functions/bytesToHexBytes.md +0 -32
- package/docs/utils/bytesToString/README.md +0 -11
- package/docs/utils/bytesToString/functions/bytesToString.md +0 -31
- package/docs/utils/concatUint8Arrays/README.md +0 -11
- package/docs/utils/concatUint8Arrays/functions/concatUint8Arrays.md +0 -31
- package/docs/utils/escapeString/README.md +0 -11
- package/docs/utils/escapeString/functions/escapeString.md +0 -32
- package/docs/utils/hexBytesToBytes/README.md +0 -11
- package/docs/utils/hexBytesToBytes/functions/hexBytesToBytes.md +0 -33
- package/docs/utils/hexBytesToString/README.md +0 -11
- package/docs/utils/hexBytesToString/functions/hexBytesToString.md +0 -31
- package/docs/utils/hexToBytes/README.md +0 -11
- package/docs/utils/hexToBytes/functions/hexToBytes.md +0 -31
- package/docs/utils/padBytes/README.md +0 -11
- package/docs/utils/padBytes/functions/padBytes.md +0 -41
- package/docs/utils/predictors/README.md +0 -11
- package/docs/utils/predictors/classes/Predictor.md +0 -306
- package/docs/utils/replaceInBuffer/README.md +0 -11
- package/docs/utils/replaceInBuffer/functions/replaceInBuffer.md +0 -65
- package/docs/utils/stringToBytes/README.md +0 -11
- package/docs/utils/stringToBytes/functions/stringToBytes.md +0 -32
- package/docs/utils/stringToHexBytes/README.md +0 -11
- package/docs/utils/stringToHexBytes/functions/stringToHexBytes.md +0 -33
- package/docs/utils/unescapeString/README.md +0 -11
- package/docs/utils/unescapeString/functions/unescapeString.md +0 -34
- package/examples/001-create-pdf.ts +0 -112
- package/examples/002-create-encrypted-pdf.ts +0 -121
- package/examples/003-sign-pdf.ts +0 -347
- package/examples/004-incremental-update.ts +0 -206
- package/examples/005-modify-acroform.ts +0 -374
- package/examples/006-tokeniser-example.ts +0 -131
- package/examples/007-decoder-example.ts +0 -197
- package/packages/pdf-lite/README.md +0 -3
- package/packages/pdf-lite/node_modules/.bin/playwright +0 -16
- package/packages/pdf-lite/node_modules/.bin/tsc +0 -16
- package/packages/pdf-lite/node_modules/.bin/tsserver +0 -16
- package/packages/pdf-lite/node_modules/.bin/vitest +0 -16
- package/packages/pdf-lite/package.json +0 -68
- package/packages/pdf-lite/scripts/create-encryption-tests.sh +0 -41
- package/packages/pdf-lite/scripts/gen-signing-keys.sh +0 -290
- package/packages/pdf-lite/scripts/generate-all-signing-keys.sh +0 -70
- package/packages/pdf-lite/src/core/decoder.ts +0 -454
- package/packages/pdf-lite/src/core/index.ts +0 -2
- package/packages/pdf-lite/src/core/objects/pdf-array.ts +0 -54
- package/packages/pdf-lite/src/core/objects/pdf-boolean.ts +0 -19
- package/packages/pdf-lite/src/core/objects/pdf-comment.ts +0 -50
- package/packages/pdf-lite/src/core/objects/pdf-date.ts +0 -74
- package/packages/pdf-lite/src/core/objects/pdf-dictionary.ts +0 -171
- package/packages/pdf-lite/src/core/objects/pdf-hexadecimal.ts +0 -54
- package/packages/pdf-lite/src/core/objects/pdf-indirect-object.ts +0 -137
- package/packages/pdf-lite/src/core/objects/pdf-name.ts +0 -19
- package/packages/pdf-lite/src/core/objects/pdf-null.ts +0 -15
- package/packages/pdf-lite/src/core/objects/pdf-number.ts +0 -98
- package/packages/pdf-lite/src/core/objects/pdf-object-reference.ts +0 -30
- package/packages/pdf-lite/src/core/objects/pdf-object.ts +0 -107
- package/packages/pdf-lite/src/core/objects/pdf-start-xref.ts +0 -39
- package/packages/pdf-lite/src/core/objects/pdf-stream.ts +0 -687
- package/packages/pdf-lite/src/core/objects/pdf-string.ts +0 -38
- package/packages/pdf-lite/src/core/objects/pdf-trailer.ts +0 -57
- package/packages/pdf-lite/src/core/objects/pdf-xref-table.ts +0 -264
- package/packages/pdf-lite/src/core/streams/object-stream.ts +0 -20
- package/packages/pdf-lite/src/core/tokeniser.ts +0 -687
- package/packages/pdf-lite/src/core/tokens/boolean-token.ts +0 -20
- package/packages/pdf-lite/src/core/tokens/byte-offset-token.ts +0 -20
- package/packages/pdf-lite/src/core/tokens/comment-token.ts +0 -32
- package/packages/pdf-lite/src/core/tokens/end-array-token.ts +0 -10
- package/packages/pdf-lite/src/core/tokens/end-dictionary-token.ts +0 -10
- package/packages/pdf-lite/src/core/tokens/end-object-token.ts +0 -10
- package/packages/pdf-lite/src/core/tokens/end-stream-token.ts +0 -11
- package/packages/pdf-lite/src/core/tokens/hexadecimal-token.ts +0 -22
- package/packages/pdf-lite/src/core/tokens/name-token.ts +0 -19
- package/packages/pdf-lite/src/core/tokens/null-token.ts +0 -9
- package/packages/pdf-lite/src/core/tokens/number-token.ts +0 -164
- package/packages/pdf-lite/src/core/tokens/object-reference-token.ts +0 -24
- package/packages/pdf-lite/src/core/tokens/start-array-token.ts +0 -10
- package/packages/pdf-lite/src/core/tokens/start-dictionary-token.ts +0 -10
- package/packages/pdf-lite/src/core/tokens/start-object-token.ts +0 -28
- package/packages/pdf-lite/src/core/tokens/start-stream-token.ts +0 -52
- package/packages/pdf-lite/src/core/tokens/start-xref-token.ts +0 -10
- package/packages/pdf-lite/src/core/tokens/stream-chunk-token.ts +0 -8
- package/packages/pdf-lite/src/core/tokens/string-token.ts +0 -17
- package/packages/pdf-lite/src/core/tokens/token.ts +0 -43
- package/packages/pdf-lite/src/core/tokens/trailer-token.ts +0 -12
- package/packages/pdf-lite/src/core/tokens/whitespace-token.ts +0 -43
- package/packages/pdf-lite/src/core/tokens/xref-table-entry-token.ts +0 -65
- package/packages/pdf-lite/src/core/tokens/xref-table-section-start-token.ts +0 -31
- package/packages/pdf-lite/src/core/tokens/xref-table-start-token.ts +0 -13
- package/packages/pdf-lite/src/crypto/key-derivation/key-derivation-aes256.ts +0 -213
- package/packages/pdf-lite/src/crypto/types.ts +0 -6
- package/packages/pdf-lite/src/filters/lzw.ts +0 -144
- package/packages/pdf-lite/src/index.ts +0 -4
- package/packages/pdf-lite/src/pdf/index.ts +0 -4
- package/packages/pdf-lite/src/pdf/pdf-xref-lookup.ts +0 -527
- package/packages/pdf-lite/src/security/handlers/base.ts +0 -625
- package/packages/pdf-lite/src/security/handlers/pubSec.ts +0 -413
- package/packages/pdf-lite/src/security/handlers/utils.ts +0 -304
- package/packages/pdf-lite/src/security/handlers/v1.ts +0 -225
- package/packages/pdf-lite/src/security/handlers/v4.ts +0 -379
- package/packages/pdf-lite/src/security/handlers/v5.ts +0 -298
- package/packages/pdf-lite/src/signing/document-security-store.ts +0 -224
- package/packages/pdf-lite/src/signing/index.ts +0 -3
- package/packages/pdf-lite/src/signing/signatures/adbe-pkcs7-detached.ts +0 -154
- package/packages/pdf-lite/src/signing/signatures/adbe-pkcs7-sha1.ts +0 -161
- package/packages/pdf-lite/src/signing/signatures/adbe-x509-rsa-sha1.ts +0 -106
- package/packages/pdf-lite/src/signing/signatures/base.ts +0 -229
- package/packages/pdf-lite/src/signing/signatures/etsi-cades-detached.ts +0 -229
- package/packages/pdf-lite/src/signing/signatures/index.ts +0 -6
- package/packages/pdf-lite/src/signing/signer.ts +0 -120
- package/packages/pdf-lite/src/types.ts +0 -44
- package/packages/pdf-lite/src/utils/escapeString.ts +0 -49
- package/packages/pdf-lite/src/utils/unescapeString.ts +0 -123
- package/packages/pdf-lite/test/acceptance/__snapshots__/versions.node.test.ts.snap +0 -60766
- package/packages/pdf-lite/test/acceptance/fixtures/1.3/basic.pdf +0 -0
- package/packages/pdf-lite/test/acceptance/fixtures/1.4/basic-aes-128.pdf +0 -0
- package/packages/pdf-lite/test/acceptance/fixtures/1.4/basic-aes-256.pdf +0 -0
- package/packages/pdf-lite/test/acceptance/fixtures/1.4/basic-rc4-128.pdf +0 -0
- package/packages/pdf-lite/test/acceptance/fixtures/1.4/basic-rc4-40.pdf +0 -0
- package/packages/pdf-lite/test/acceptance/fixtures/1.4/basic.pdf +0 -0
- package/packages/pdf-lite/test/acceptance/fixtures/1.5/basic.pdf +0 -0
- package/packages/pdf-lite/test/acceptance/fixtures/1.6/basic.pdf +0 -0
- package/packages/pdf-lite/test/acceptance/fixtures/1.7/basic.pdf +0 -0
- package/packages/pdf-lite/test/acceptance/fixtures/2.0/basic-aes-128.pdf +0 -43
- package/packages/pdf-lite/test/acceptance/fixtures/2.0/basic-aes-256.pdf +0 -43
- package/packages/pdf-lite/test/acceptance/fixtures/2.0/basic-rc4-128.pdf +0 -43
- package/packages/pdf-lite/test/acceptance/fixtures/2.0/basic-rc4-40.pdf +0 -44
- package/packages/pdf-lite/test/acceptance/fixtures/2.0/basic.pdf +0 -79
- package/packages/pdf-lite/test/acceptance/versions.node.test.ts +0 -41
- package/packages/pdf-lite/test/unit/__snapshots__/decoder.node.test.ts.snap +0 -86947
- package/packages/pdf-lite/test/unit/__snapshots__/tokeniser.node.test.ts.snap +0 -131829
- package/packages/pdf-lite/test/unit/ciphers.test.ts +0 -61
- package/packages/pdf-lite/test/unit/decoder.node.test.ts +0 -21
- package/packages/pdf-lite/test/unit/decoder.test.ts +0 -567
- package/packages/pdf-lite/test/unit/filters.test.ts +0 -67
- package/packages/pdf-lite/test/unit/fixtures/basic.pdf +0 -0
- package/packages/pdf-lite/test/unit/fixtures/encrypted_v1/basic-aes-128.pdf +0 -0
- package/packages/pdf-lite/test/unit/fixtures/encrypted_v1/basic-aes-256.pdf +0 -0
- package/packages/pdf-lite/test/unit/fixtures/encrypted_v1/basic-rc4-128.pdf +0 -0
- package/packages/pdf-lite/test/unit/fixtures/encrypted_v1/basic-rc4-40.pdf +0 -43
- package/packages/pdf-lite/test/unit/fixtures/protectedAdobeLivecycle.pdf +0 -0
- package/packages/pdf-lite/test/unit/fixtures/rsa-2048/index.ts +0 -187
- package/packages/pdf-lite/test/unit/fixtures/template.pdf +0 -0
- package/packages/pdf-lite/test/unit/incremental-update.test.ts +0 -0
- package/packages/pdf-lite/test/unit/objects.test.ts +0 -0
- package/packages/pdf-lite/test/unit/pdf-document-signing.test.ts +0 -0
- package/packages/pdf-lite/test/unit/pdf-revision.test.ts +0 -195
- package/packages/pdf-lite/test/unit/pdf.browser.test.ts +0 -0
- package/packages/pdf-lite/test/unit/predictors.test.ts +0 -226
- package/packages/pdf-lite/test/unit/ref.test.ts +0 -158
- package/packages/pdf-lite/test/unit/security-handlers.test.ts +0 -645
- package/packages/pdf-lite/test/unit/serializer.test.ts +0 -81
- package/packages/pdf-lite/test/unit/signature-objects.test.ts +0 -814
- package/packages/pdf-lite/test/unit/string-escaping.test.ts +0 -84
- package/packages/pdf-lite/test/unit/tokeniser.node.test.ts +0 -38
- package/packages/pdf-lite/test/unit/tokeniser.test.ts +0 -1213
- package/packages/pdf-lite/test/unit/utils.test.ts +0 -248
- package/packages/pdf-lite/test/unit/xref-lookup.test.ts +0 -72
- package/packages/pdf-lite/tsconfig.json +0 -4
- package/packages/pdf-lite/tsconfig.prod.json +0 -8
- package/packages/pdf-lite/typedoc.json +0 -14
- package/packages/pdf-lite/vitest.config.ts +0 -43
- package/pnpm-workspace.yaml +0 -2
- package/renovate.json +0 -34
- package/scripts/build-examples.ts +0 -30
- package/scripts/bump-version.sh +0 -56
- package/scripts/gen-html-docs.sh +0 -21
- package/scripts/gen-md-docs.sh +0 -15
- package/scripts/prepare-release.sh +0 -33
- package/tsconfig.json +0 -22
- package/tsconfig.prod.json +0 -12
- package/typedoc.json +0 -34
|
@@ -1,37 +1,22 @@
|
|
|
1
|
-
import { PdfObject } from '../core/objects/pdf-object'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from '../
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from '../core/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { PdfRevision } from './pdf-revision'
|
|
21
|
-
import { PdfV5SecurityHandler } from '../security/handlers/v5'
|
|
22
|
-
import { PdfEncryptionDictionaryObject } from '../security/types'
|
|
23
|
-
import { PdfByteOffsetToken } from '../core/tokens/byte-offset-token'
|
|
24
|
-
import { PdfNumberToken } from '../core/tokens/number-token'
|
|
25
|
-
import { PdfXRefTableEntryToken } from '../core/tokens/xref-table-entry-token'
|
|
26
|
-
import { Ref } from '../core/ref'
|
|
27
|
-
import { PdfStartXRef } from '../core/objects/pdf-start-xref'
|
|
28
|
-
import { PdfTrailerEntries } from '../core/objects/pdf-trailer'
|
|
29
|
-
import { FoundCompressedObjectError } from './errors'
|
|
30
|
-
import { PdfDocumentSecurityStoreObject } from '../signing/document-security-store'
|
|
31
|
-
import { ByteArray } from '../types'
|
|
32
|
-
import { PdfReader } from './pdf-reader'
|
|
33
|
-
import { PdfSigner } from '../signing/signer'
|
|
34
|
-
|
|
1
|
+
import { PdfObject } from '../core/objects/pdf-object';
|
|
2
|
+
import { PdfStandardSecurityHandler, } from '../security/handlers/base';
|
|
3
|
+
import { createFromDictionary } from '../security/handlers/utils';
|
|
4
|
+
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object';
|
|
5
|
+
import { PdfComment } from '../core/objects/pdf-comment';
|
|
6
|
+
import { PdfWhitespaceToken } from '../core/tokens/whitespace-token';
|
|
7
|
+
import { PdfObjStream, PdfStream, PdfXRefStreamCompressedEntry, } from '../core/objects/pdf-stream';
|
|
8
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary';
|
|
9
|
+
import { PdfObjectReference } from '../core/objects/pdf-object-reference';
|
|
10
|
+
import { PdfTokenSerializer } from '../core/serializer';
|
|
11
|
+
import { PdfRevision } from './pdf-revision';
|
|
12
|
+
import { PdfV5SecurityHandler } from '../security/handlers/v5';
|
|
13
|
+
import { PdfByteOffsetToken } from '../core/tokens/byte-offset-token';
|
|
14
|
+
import { PdfNumberToken } from '../core/tokens/number-token';
|
|
15
|
+
import { PdfXRefTableEntryToken } from '../core/tokens/xref-table-entry-token';
|
|
16
|
+
import { PdfStartXRef } from '../core/objects/pdf-start-xref';
|
|
17
|
+
import { FoundCompressedObjectError } from './errors';
|
|
18
|
+
import { PdfReader } from './pdf-reader';
|
|
19
|
+
import { PdfSigner } from '../signing/signer';
|
|
35
20
|
/**
|
|
36
21
|
* Represents a PDF document with support for reading, writing, and modifying PDF files.
|
|
37
22
|
* Handles document structure, revisions, encryption, and digital signatures.
|
|
@@ -51,17 +36,15 @@ import { PdfSigner } from '../signing/signer'
|
|
|
51
36
|
*/
|
|
52
37
|
export class PdfDocument extends PdfObject {
|
|
53
38
|
/** PDF version comment header */
|
|
54
|
-
header
|
|
39
|
+
header = PdfComment.versionComment('1.7');
|
|
55
40
|
/** List of document revisions for incremental updates */
|
|
56
|
-
revisions
|
|
41
|
+
revisions;
|
|
57
42
|
/** Signer instance for digital signature operations */
|
|
58
|
-
signer
|
|
43
|
+
signer;
|
|
59
44
|
/** Security handler for encryption/decryption operations */
|
|
60
|
-
securityHandler
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
private toBeCommitted: PdfObject[] = []
|
|
64
|
-
|
|
45
|
+
securityHandler;
|
|
46
|
+
hasEncryptionDictionary = false;
|
|
47
|
+
toBeCommitted = [];
|
|
65
48
|
/**
|
|
66
49
|
* Creates a new PDF document instance.
|
|
67
50
|
*
|
|
@@ -73,41 +56,27 @@ export class PdfDocument extends PdfObject {
|
|
|
73
56
|
* @param options.securityHandler - Custom security handler for encryption
|
|
74
57
|
* @param options.signer - Custom signer for digital signatures
|
|
75
58
|
*/
|
|
76
|
-
constructor(options
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
password?: string
|
|
80
|
-
ownerPassword?: string
|
|
81
|
-
securityHandler?: PdfSecurityHandler
|
|
82
|
-
signer?: PdfSigner
|
|
83
|
-
}) {
|
|
84
|
-
super()
|
|
85
|
-
|
|
86
|
-
this.revisions = options?.revisions ?? [new PdfRevision()]
|
|
87
|
-
|
|
59
|
+
constructor(options) {
|
|
60
|
+
super();
|
|
61
|
+
this.revisions = options?.revisions ?? [new PdfRevision()];
|
|
88
62
|
if (options?.version instanceof PdfComment) {
|
|
89
|
-
this.header = options.version
|
|
90
|
-
}
|
|
91
|
-
|
|
63
|
+
this.header = options.version;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.setVersion(options?.version ?? '2.0');
|
|
92
67
|
}
|
|
93
|
-
|
|
94
68
|
this.securityHandler =
|
|
95
|
-
options?.securityHandler ?? this.getSecurityHandler()
|
|
96
|
-
|
|
69
|
+
options?.securityHandler ?? this.getSecurityHandler();
|
|
97
70
|
if (options?.password) {
|
|
98
|
-
this.setPassword(options.password)
|
|
71
|
+
this.setPassword(options.password);
|
|
99
72
|
}
|
|
100
|
-
|
|
101
73
|
if (options?.ownerPassword) {
|
|
102
|
-
this.setOwnerPassword(options.ownerPassword)
|
|
74
|
+
this.setOwnerPassword(options.ownerPassword);
|
|
103
75
|
}
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
|
|
107
|
-
this.linkRevisions()
|
|
108
|
-
this.calculateOffsets()
|
|
76
|
+
this.signer = options?.signer ?? new PdfSigner();
|
|
77
|
+
this.linkRevisions();
|
|
78
|
+
this.calculateOffsets();
|
|
109
79
|
}
|
|
110
|
-
|
|
111
80
|
/**
|
|
112
81
|
* Creates a PdfDocument from an array of PDF objects.
|
|
113
82
|
* Parses objects into revisions based on EOF comments.
|
|
@@ -115,390 +84,296 @@ export class PdfDocument extends PdfObject {
|
|
|
115
84
|
* @param objects - Array of PDF objects to construct the document from
|
|
116
85
|
* @returns A new PdfDocument instance
|
|
117
86
|
*/
|
|
118
|
-
static fromObjects(objects
|
|
119
|
-
let header
|
|
120
|
-
const revisions
|
|
121
|
-
let currentObjects
|
|
122
|
-
|
|
87
|
+
static fromObjects(objects) {
|
|
88
|
+
let header;
|
|
89
|
+
const revisions = [];
|
|
90
|
+
let currentObjects = [];
|
|
123
91
|
for (const obj of objects) {
|
|
124
92
|
if (obj instanceof PdfComment && obj.isVersionComment()) {
|
|
125
|
-
header = obj
|
|
126
|
-
continue
|
|
93
|
+
header = obj;
|
|
94
|
+
continue;
|
|
127
95
|
}
|
|
128
|
-
|
|
129
|
-
currentObjects.push(obj)
|
|
96
|
+
currentObjects.push(obj);
|
|
130
97
|
if (obj instanceof PdfComment && obj.isEOFComment()) {
|
|
131
|
-
revisions.push(new PdfRevision({ objects: currentObjects }))
|
|
132
|
-
currentObjects = []
|
|
98
|
+
revisions.push(new PdfRevision({ objects: currentObjects }));
|
|
99
|
+
currentObjects = [];
|
|
133
100
|
}
|
|
134
101
|
}
|
|
135
|
-
|
|
136
102
|
if (currentObjects.length > 0) {
|
|
137
|
-
revisions.push(new PdfRevision({ objects: currentObjects }))
|
|
103
|
+
revisions.push(new PdfRevision({ objects: currentObjects }));
|
|
138
104
|
}
|
|
139
|
-
|
|
140
|
-
return new PdfDocument({ revisions, version: header })
|
|
105
|
+
return new PdfDocument({ revisions, version: header });
|
|
141
106
|
}
|
|
142
|
-
|
|
143
107
|
/**
|
|
144
108
|
* Starts a new revision for incremental updates.
|
|
145
109
|
* Creates a new revision linked to the previous one.
|
|
146
110
|
*
|
|
147
111
|
* @returns The document instance for method chaining
|
|
148
112
|
*/
|
|
149
|
-
startNewRevision()
|
|
150
|
-
const newRevision = new PdfRevision({ prev: this.latestRevision })
|
|
151
|
-
this.revisions.push(newRevision)
|
|
152
|
-
|
|
153
|
-
const lastStartXRef = this.objects.findLast(
|
|
154
|
-
(x) => x instanceof PdfStartXRef,
|
|
155
|
-
)
|
|
113
|
+
startNewRevision() {
|
|
114
|
+
const newRevision = new PdfRevision({ prev: this.latestRevision });
|
|
115
|
+
this.revisions.push(newRevision);
|
|
116
|
+
const lastStartXRef = this.objects.findLast((x) => x instanceof PdfStartXRef);
|
|
156
117
|
if (lastStartXRef) {
|
|
157
|
-
newRevision.xref.offset = lastStartXRef.offset.ref
|
|
118
|
+
newRevision.xref.offset = lastStartXRef.offset.ref;
|
|
158
119
|
}
|
|
159
|
-
|
|
160
|
-
return this
|
|
120
|
+
return this;
|
|
161
121
|
}
|
|
162
|
-
|
|
163
122
|
/**
|
|
164
123
|
* Adds objects to the document's latest revision.
|
|
165
124
|
* Automatically starts a new revision if the current one is locked.
|
|
166
125
|
*
|
|
167
126
|
* @param objects - PDF objects to add to the document
|
|
168
127
|
*/
|
|
169
|
-
add(...objects
|
|
128
|
+
add(...objects) {
|
|
170
129
|
if (this.latestRevision.locked) {
|
|
171
|
-
this.startNewRevision()
|
|
130
|
+
this.startNewRevision();
|
|
172
131
|
}
|
|
173
|
-
|
|
174
132
|
for (const obj of objects) {
|
|
175
|
-
this.toBeCommitted.push(obj)
|
|
176
|
-
this.latestRevision.addObject(obj)
|
|
133
|
+
this.toBeCommitted.push(obj);
|
|
134
|
+
this.latestRevision.addObject(obj);
|
|
177
135
|
}
|
|
178
136
|
}
|
|
179
|
-
|
|
180
137
|
/**
|
|
181
138
|
* Gets the latest (most recent) revision of the document.
|
|
182
139
|
*
|
|
183
140
|
* @returns The latest PdfRevision
|
|
184
141
|
* @throws Error if the revision for the last StartXRef cannot be found
|
|
185
142
|
*/
|
|
186
|
-
get latestRevision()
|
|
187
|
-
const lastStartXRef = this.objects.findLast(
|
|
188
|
-
(x) => x instanceof PdfStartXRef,
|
|
189
|
-
)
|
|
143
|
+
get latestRevision() {
|
|
144
|
+
const lastStartXRef = this.objects.findLast((x) => x instanceof PdfStartXRef);
|
|
190
145
|
if (!lastStartXRef) {
|
|
191
|
-
return this.revisions[this.revisions.length - 1]
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.revisions.find(
|
|
196
|
-
(rev) => rev.xref.offset === lastStartXRef.offset.ref,
|
|
197
|
-
) ??
|
|
198
|
-
this.revisions.find((rev) =>
|
|
199
|
-
rev.xref.offset.equals(lastStartXRef.offset.value),
|
|
200
|
-
)
|
|
146
|
+
return this.revisions[this.revisions.length - 1];
|
|
147
|
+
}
|
|
148
|
+
const revision = this.revisions.find((rev) => rev.xref.offset === lastStartXRef.offset.ref) ??
|
|
149
|
+
this.revisions.find((rev) => rev.xref.offset.equals(lastStartXRef.offset.value));
|
|
201
150
|
if (!revision) {
|
|
202
|
-
throw new Error('Cannot find revision for last StartXRef')
|
|
151
|
+
throw new Error('Cannot find revision for last StartXRef');
|
|
203
152
|
}
|
|
204
|
-
|
|
205
|
-
return revision
|
|
153
|
+
return revision;
|
|
206
154
|
}
|
|
207
|
-
|
|
208
155
|
/**
|
|
209
156
|
* Gets the cross-reference lookup table for the latest revision.
|
|
210
157
|
*
|
|
211
158
|
* @returns The PdfXrefLookup for the latest revision
|
|
212
159
|
*/
|
|
213
|
-
get xrefLookup()
|
|
214
|
-
return this.latestRevision.xref
|
|
160
|
+
get xrefLookup() {
|
|
161
|
+
return this.latestRevision.xref;
|
|
215
162
|
}
|
|
216
|
-
|
|
217
163
|
/**
|
|
218
164
|
* Gets the trailer dictionary from the cross-reference lookup.
|
|
219
165
|
*
|
|
220
166
|
* @returns The trailer dictionary containing document metadata references
|
|
221
167
|
*/
|
|
222
|
-
get trailerDict()
|
|
223
|
-
return this.xrefLookup.trailerDict
|
|
168
|
+
get trailerDict() {
|
|
169
|
+
return this.xrefLookup.trailerDict;
|
|
224
170
|
}
|
|
225
|
-
|
|
226
171
|
/**
|
|
227
172
|
* Gets all objects across all revisions in the document.
|
|
228
173
|
*
|
|
229
174
|
* @returns A readonly array of all PDF objects
|
|
230
175
|
*/
|
|
231
|
-
get objects()
|
|
232
|
-
return this.revisions.flatMap((rev) => rev.objects)
|
|
176
|
+
get objects() {
|
|
177
|
+
return this.revisions.flatMap((rev) => rev.objects);
|
|
233
178
|
}
|
|
234
|
-
|
|
235
179
|
/**
|
|
236
180
|
* Gets the encryption dictionary from the document if present.
|
|
237
181
|
*
|
|
238
182
|
* @returns The encryption dictionary object or undefined if not encrypted
|
|
239
183
|
* @throws Error if the encryption dictionary reference points to a non-dictionary object
|
|
240
184
|
*/
|
|
241
|
-
get encryptionDictionary()
|
|
185
|
+
get encryptionDictionary() {
|
|
242
186
|
const encryptionDictionaryRef = this.trailerDict
|
|
243
187
|
.get('Encrypt')
|
|
244
|
-
?.as(PdfObjectReference)
|
|
245
|
-
|
|
188
|
+
?.as(PdfObjectReference);
|
|
246
189
|
if (!encryptionDictionaryRef) {
|
|
247
|
-
return undefined
|
|
190
|
+
return undefined;
|
|
248
191
|
}
|
|
249
|
-
|
|
250
|
-
const encryptionDictObject = this.findUncompressedObject(
|
|
251
|
-
encryptionDictionaryRef,
|
|
252
|
-
)
|
|
253
|
-
|
|
192
|
+
const encryptionDictObject = this.findUncompressedObject(encryptionDictionaryRef);
|
|
254
193
|
if (!(encryptionDictObject?.content instanceof PdfDictionary)) {
|
|
255
|
-
throw new Error(
|
|
256
|
-
`Encryption dictionary object ${encryptionDictionaryRef.objectNumber} ${encryptionDictionaryRef.generationNumber} is not a dictionary, it is a ${encryptionDictObject?.content.objectType}`,
|
|
257
|
-
)
|
|
194
|
+
throw new Error(`Encryption dictionary object ${encryptionDictionaryRef.objectNumber} ${encryptionDictionaryRef.generationNumber} is not a dictionary, it is a ${encryptionDictObject?.content.objectType}`);
|
|
258
195
|
}
|
|
259
|
-
|
|
260
|
-
encryptionDictObject
|
|
261
|
-
return encryptionDictObject as PdfEncryptionDictionaryObject
|
|
196
|
+
encryptionDictObject.encryptable = false;
|
|
197
|
+
return encryptionDictObject;
|
|
262
198
|
}
|
|
263
|
-
|
|
264
199
|
/**
|
|
265
200
|
* Gets the document catalog (root) dictionary.
|
|
266
201
|
*
|
|
267
202
|
* @returns The root dictionary or undefined if not found
|
|
268
203
|
* @throws Error if the Root reference points to a non-dictionary object
|
|
269
204
|
*/
|
|
270
|
-
get rootDictionary()
|
|
271
|
-
const rootRef = this.trailerDict.get('Root')?.as(PdfObjectReference)
|
|
272
|
-
|
|
205
|
+
get rootDictionary() {
|
|
206
|
+
const rootRef = this.trailerDict.get('Root')?.as(PdfObjectReference);
|
|
273
207
|
if (!rootRef) {
|
|
274
|
-
return undefined
|
|
208
|
+
return undefined;
|
|
275
209
|
}
|
|
276
|
-
|
|
277
|
-
const rootObject = this.findUncompressedObject(rootRef)
|
|
278
|
-
|
|
210
|
+
const rootObject = this.findUncompressedObject(rootRef);
|
|
279
211
|
if (!(rootObject?.content instanceof PdfDictionary)) {
|
|
280
|
-
throw new Error(
|
|
281
|
-
`Root object ${rootRef.objectNumber} ${rootRef.generationNumber} is not a dictionary, it is a ${rootObject?.content.objectType}`,
|
|
282
|
-
)
|
|
212
|
+
throw new Error(`Root object ${rootRef.objectNumber} ${rootRef.generationNumber} is not a dictionary, it is a ${rootObject?.content.objectType}`);
|
|
283
213
|
}
|
|
284
|
-
|
|
285
|
-
return rootObject.content
|
|
214
|
+
return rootObject.content;
|
|
286
215
|
}
|
|
287
|
-
|
|
288
216
|
/**
|
|
289
217
|
* Gets the reference to the metadata stream from the document catalog.
|
|
290
218
|
*
|
|
291
219
|
* @returns The metadata stream reference or undefined if not present
|
|
292
220
|
*/
|
|
293
|
-
get metadataStreamReference()
|
|
294
|
-
const root = this.rootDictionary
|
|
221
|
+
get metadataStreamReference() {
|
|
222
|
+
const root = this.rootDictionary;
|
|
295
223
|
if (!root) {
|
|
296
|
-
return
|
|
224
|
+
return;
|
|
297
225
|
}
|
|
298
|
-
|
|
299
|
-
const metadataRef = root.get('Metadata')?.as(PdfObjectReference)
|
|
300
|
-
|
|
226
|
+
const metadataRef = root.get('Metadata')?.as(PdfObjectReference);
|
|
301
227
|
if (!metadataRef) {
|
|
302
|
-
return
|
|
228
|
+
return;
|
|
303
229
|
}
|
|
304
|
-
|
|
305
|
-
return metadataRef
|
|
230
|
+
return metadataRef;
|
|
306
231
|
}
|
|
307
|
-
|
|
308
|
-
private getSecurityHandler(): PdfSecurityHandler | undefined {
|
|
232
|
+
getSecurityHandler() {
|
|
309
233
|
const encryptionDictionaryRef = this.trailerDict
|
|
310
234
|
.get('Encrypt')
|
|
311
|
-
?.as(PdfObjectReference)
|
|
312
|
-
|
|
235
|
+
?.as(PdfObjectReference);
|
|
313
236
|
if (!encryptionDictionaryRef) {
|
|
314
|
-
return undefined
|
|
237
|
+
return undefined;
|
|
315
238
|
}
|
|
316
|
-
|
|
317
|
-
const encryptionDictObject = this.findUncompressedObject(
|
|
318
|
-
encryptionDictionaryRef,
|
|
319
|
-
)
|
|
320
|
-
|
|
239
|
+
const encryptionDictObject = this.findUncompressedObject(encryptionDictionaryRef);
|
|
321
240
|
if (!(encryptionDictObject?.content instanceof PdfDictionary)) {
|
|
322
|
-
throw new Error(
|
|
323
|
-
`Encryption dictionary object ${encryptionDictionaryRef.objectNumber} ${encryptionDictionaryRef.generationNumber} is not a dictionary, it is a ${encryptionDictObject?.content.objectType}`,
|
|
324
|
-
)
|
|
241
|
+
throw new Error(`Encryption dictionary object ${encryptionDictionaryRef.objectNumber} ${encryptionDictionaryRef.generationNumber} is not a dictionary, it is a ${encryptionDictObject?.content.objectType}`);
|
|
325
242
|
}
|
|
326
|
-
|
|
327
|
-
this.hasEncryptionDictionary = true
|
|
243
|
+
this.hasEncryptionDictionary = true;
|
|
328
244
|
return createFromDictionary(encryptionDictObject.content, {
|
|
329
245
|
documentId: this.trailerDict.get('ID'),
|
|
330
|
-
})
|
|
246
|
+
});
|
|
331
247
|
}
|
|
332
|
-
|
|
333
|
-
private initSecurityHandler(options: {
|
|
334
|
-
password?: string
|
|
335
|
-
ownerPassword?: string
|
|
336
|
-
}): void {
|
|
248
|
+
initSecurityHandler(options) {
|
|
337
249
|
if (this.securityHandler instanceof PdfStandardSecurityHandler) {
|
|
338
|
-
const documentId = this.trailerDict.get('ID')
|
|
250
|
+
const documentId = this.trailerDict.get('ID');
|
|
339
251
|
options.password &&
|
|
340
|
-
this.securityHandler.setPassword(options.password)
|
|
252
|
+
this.securityHandler.setPassword(options.password);
|
|
341
253
|
options.ownerPassword &&
|
|
342
|
-
this.securityHandler.setOwnerPassword(options.ownerPassword)
|
|
343
|
-
documentId && this.securityHandler.setDocumentId(documentId)
|
|
344
|
-
|
|
345
|
-
return
|
|
254
|
+
this.securityHandler.setOwnerPassword(options.ownerPassword);
|
|
255
|
+
documentId && this.securityHandler.setDocumentId(documentId);
|
|
256
|
+
return;
|
|
346
257
|
}
|
|
347
|
-
|
|
348
258
|
this.securityHandler = new PdfV5SecurityHandler({
|
|
349
259
|
password: options.password,
|
|
350
260
|
ownerPassword: options.ownerPassword,
|
|
351
|
-
})
|
|
261
|
+
});
|
|
352
262
|
}
|
|
353
|
-
|
|
354
263
|
/**
|
|
355
264
|
* Sets the user password for document encryption.
|
|
356
265
|
*
|
|
357
266
|
* @param password - The user password to set
|
|
358
267
|
* @throws Error if the security handler doesn't support password setting
|
|
359
268
|
*/
|
|
360
|
-
setPassword(password
|
|
269
|
+
setPassword(password) {
|
|
361
270
|
if (this.securityHandler instanceof PdfStandardSecurityHandler) {
|
|
362
|
-
this.securityHandler.setPassword(password)
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
)
|
|
271
|
+
this.securityHandler.setPassword(password);
|
|
272
|
+
}
|
|
273
|
+
else if (!this.securityHandler) {
|
|
274
|
+
this.initSecurityHandler({ password });
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
throw new Error('Setting password is only supported for Standard Security Handler');
|
|
369
278
|
}
|
|
370
279
|
}
|
|
371
|
-
|
|
372
280
|
/**
|
|
373
281
|
* Sets the owner password for document encryption.
|
|
374
282
|
*
|
|
375
283
|
* @param ownerPassword - The owner password to set
|
|
376
284
|
* @throws Error if the security handler doesn't support password setting
|
|
377
285
|
*/
|
|
378
|
-
setOwnerPassword(ownerPassword
|
|
286
|
+
setOwnerPassword(ownerPassword) {
|
|
379
287
|
if (this.securityHandler instanceof PdfStandardSecurityHandler) {
|
|
380
|
-
this.securityHandler.setOwnerPassword(ownerPassword)
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
)
|
|
288
|
+
this.securityHandler.setOwnerPassword(ownerPassword);
|
|
289
|
+
}
|
|
290
|
+
else if (!this.securityHandler) {
|
|
291
|
+
this.initSecurityHandler({ ownerPassword });
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
throw new Error('Setting ownerPassword is only supported for Standard Security Handler');
|
|
387
295
|
}
|
|
388
296
|
}
|
|
389
|
-
|
|
390
297
|
/**
|
|
391
298
|
* Checks if a PDF object exists in the document.
|
|
392
299
|
*
|
|
393
300
|
* @param obj - The PDF object to check
|
|
394
301
|
* @returns True if the object exists in the document
|
|
395
302
|
*/
|
|
396
|
-
hasObject(obj
|
|
397
|
-
return this.objects.includes(obj)
|
|
303
|
+
hasObject(obj) {
|
|
304
|
+
return this.objects.includes(obj);
|
|
398
305
|
}
|
|
399
|
-
|
|
400
|
-
private isObjectEncryptable(obj: PdfIndirectObject): boolean {
|
|
306
|
+
isObjectEncryptable(obj) {
|
|
401
307
|
if (!this.securityHandler) {
|
|
402
|
-
return false
|
|
308
|
+
return false;
|
|
403
309
|
}
|
|
404
|
-
|
|
405
310
|
if (!obj.isEncryptable()) {
|
|
406
|
-
return false
|
|
311
|
+
return false;
|
|
407
312
|
}
|
|
408
|
-
|
|
409
313
|
if (obj.matchesReference(this.encryptionDictionary?.reference)) {
|
|
410
|
-
return false
|
|
314
|
+
return false;
|
|
411
315
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
obj.matchesReference(this.metadataStreamReference)
|
|
416
|
-
) {
|
|
417
|
-
return false
|
|
316
|
+
if (!this.securityHandler.encryptMetadata &&
|
|
317
|
+
obj.matchesReference(this.metadataStreamReference)) {
|
|
318
|
+
return false;
|
|
418
319
|
}
|
|
419
|
-
|
|
420
|
-
return true
|
|
320
|
+
return true;
|
|
421
321
|
}
|
|
422
|
-
|
|
423
322
|
/**
|
|
424
323
|
* Decrypts all encrypted objects in the document.
|
|
425
324
|
* Removes the security handler and encryption dictionary after decryption.
|
|
426
325
|
*/
|
|
427
|
-
async decrypt()
|
|
326
|
+
async decrypt() {
|
|
428
327
|
if (!this.securityHandler) {
|
|
429
|
-
return
|
|
328
|
+
return;
|
|
430
329
|
}
|
|
431
|
-
|
|
432
330
|
for (const object of this.objects) {
|
|
433
331
|
if (!(object instanceof PdfIndirectObject)) {
|
|
434
|
-
continue
|
|
332
|
+
continue;
|
|
435
333
|
}
|
|
436
|
-
|
|
437
334
|
if (!this.isObjectEncryptable(object)) {
|
|
438
|
-
continue
|
|
335
|
+
continue;
|
|
439
336
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
this.hasEncryptionDictionary = false
|
|
446
|
-
|
|
447
|
-
const encryptionDict = this.encryptionDictionary
|
|
448
|
-
|
|
337
|
+
await this.securityHandler.decryptObject(object);
|
|
338
|
+
}
|
|
339
|
+
this.securityHandler = undefined;
|
|
340
|
+
this.hasEncryptionDictionary = false;
|
|
341
|
+
const encryptionDict = this.encryptionDictionary;
|
|
449
342
|
if (encryptionDict) {
|
|
450
|
-
await this.deleteObject(encryptionDict)
|
|
343
|
+
await this.deleteObject(encryptionDict);
|
|
451
344
|
}
|
|
452
|
-
|
|
453
|
-
await this.update()
|
|
345
|
+
await this.update();
|
|
454
346
|
}
|
|
455
|
-
|
|
456
347
|
/**
|
|
457
348
|
* Encrypts all objects in the document using the security handler.
|
|
458
349
|
* Creates and adds an encryption dictionary to all revisions.
|
|
459
350
|
*/
|
|
460
|
-
async encrypt()
|
|
461
|
-
this.initSecurityHandler({})
|
|
462
|
-
|
|
463
|
-
await this.securityHandler!.write()
|
|
464
|
-
|
|
351
|
+
async encrypt() {
|
|
352
|
+
this.initSecurityHandler({});
|
|
353
|
+
await this.securityHandler.write();
|
|
465
354
|
for (const object of this.objects) {
|
|
466
355
|
if (!(object instanceof PdfIndirectObject)) {
|
|
467
|
-
continue
|
|
356
|
+
continue;
|
|
468
357
|
}
|
|
469
|
-
|
|
470
358
|
if (!this.isObjectEncryptable(object)) {
|
|
471
|
-
continue
|
|
359
|
+
continue;
|
|
472
360
|
}
|
|
473
|
-
|
|
474
|
-
await this.securityHandler!.encryptObject(object)
|
|
361
|
+
await this.securityHandler.encryptObject(object);
|
|
475
362
|
}
|
|
476
|
-
|
|
477
363
|
const encryptionDictObject = new PdfIndirectObject({
|
|
478
|
-
content: this.securityHandler
|
|
364
|
+
content: this.securityHandler.dict,
|
|
479
365
|
encryptable: false,
|
|
480
|
-
})
|
|
481
|
-
|
|
366
|
+
});
|
|
482
367
|
for (const revision of this.revisions) {
|
|
483
|
-
revision.xref.trailerDict.set(
|
|
484
|
-
'Encrypt',
|
|
485
|
-
encryptionDictObject.reference,
|
|
486
|
-
)
|
|
487
|
-
|
|
368
|
+
revision.xref.trailerDict.set('Encrypt', encryptionDictObject.reference);
|
|
488
369
|
if (!revision.xref.trailerDict.get('ID')) {
|
|
489
|
-
revision.xref.trailerDict.set(
|
|
490
|
-
'ID',
|
|
491
|
-
this.securityHandler!.getDocumentId(),
|
|
492
|
-
)
|
|
370
|
+
revision.xref.trailerDict.set('ID', this.securityHandler.getDocumentId());
|
|
493
371
|
}
|
|
494
372
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
this.
|
|
498
|
-
|
|
499
|
-
await this.update()
|
|
373
|
+
await this.commit(encryptionDictObject);
|
|
374
|
+
this.hasEncryptionDictionary = true;
|
|
375
|
+
await this.update();
|
|
500
376
|
}
|
|
501
|
-
|
|
502
377
|
/**
|
|
503
378
|
* Finds a compressed object by its object number within an object stream.
|
|
504
379
|
*
|
|
@@ -506,50 +381,29 @@ export class PdfDocument extends PdfObject {
|
|
|
506
381
|
* @returns The found indirect object or undefined if not found
|
|
507
382
|
* @throws Error if the object cannot be found in the expected object stream
|
|
508
383
|
*/
|
|
509
|
-
async findCompressedObject(
|
|
510
|
-
options
|
|
511
|
-
| {
|
|
512
|
-
objectNumber: number
|
|
513
|
-
generationNumber?: number
|
|
514
|
-
}
|
|
515
|
-
| PdfObjectReference,
|
|
516
|
-
): Promise<PdfIndirectObject | undefined> {
|
|
517
|
-
const xrefEntry = this.xrefLookup.getObject(options.objectNumber)
|
|
518
|
-
|
|
384
|
+
async findCompressedObject(options) {
|
|
385
|
+
const xrefEntry = this.xrefLookup.getObject(options.objectNumber);
|
|
519
386
|
if (!(xrefEntry instanceof PdfXRefStreamCompressedEntry)) {
|
|
520
|
-
throw new Error(
|
|
521
|
-
'Cannot find object inside object stream via PdfDocument.findObject',
|
|
522
|
-
)
|
|
387
|
+
throw new Error('Cannot find object inside object stream via PdfDocument.findObject');
|
|
523
388
|
}
|
|
524
|
-
|
|
525
389
|
const objectStreamIndirect = this.findUncompressedObject({
|
|
526
390
|
objectNumber: xrefEntry.objectStreamNumber.value,
|
|
527
|
-
})
|
|
528
|
-
|
|
391
|
+
});
|
|
529
392
|
if (!objectStreamIndirect) {
|
|
530
|
-
throw new Error(
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
this.securityHandler &&
|
|
537
|
-
this.isObjectEncryptable(objectStreamIndirect)
|
|
538
|
-
) {
|
|
539
|
-
await this.securityHandler.decryptObject(objectStreamIndirect)
|
|
540
|
-
}
|
|
541
|
-
|
|
393
|
+
throw new Error(`Cannot find object stream ${xrefEntry.objectStreamNumber.value} for object ${options.objectNumber}`);
|
|
394
|
+
}
|
|
395
|
+
if (this.securityHandler &&
|
|
396
|
+
this.isObjectEncryptable(objectStreamIndirect)) {
|
|
397
|
+
await this.securityHandler.decryptObject(objectStreamIndirect);
|
|
398
|
+
}
|
|
542
399
|
const objectStream = objectStreamIndirect.content
|
|
543
400
|
.as(PdfStream)
|
|
544
|
-
.parseAs(PdfObjStream)
|
|
545
|
-
|
|
401
|
+
.parseAs(PdfObjStream);
|
|
546
402
|
const decompressedObject = objectStream.getObject({
|
|
547
403
|
objectNumber: options.objectNumber,
|
|
548
|
-
})
|
|
549
|
-
|
|
550
|
-
return decompressedObject
|
|
404
|
+
});
|
|
405
|
+
return decompressedObject;
|
|
551
406
|
}
|
|
552
|
-
|
|
553
407
|
/**
|
|
554
408
|
* Finds an uncompressed indirect object by its object number.
|
|
555
409
|
*
|
|
@@ -557,40 +411,22 @@ export class PdfDocument extends PdfObject {
|
|
|
557
411
|
* @returns The found indirect object or undefined if not found
|
|
558
412
|
* @throws FoundCompressedObjectError if the object is compressed (in an object stream)
|
|
559
413
|
*/
|
|
560
|
-
findUncompressedObject(
|
|
561
|
-
options
|
|
562
|
-
| {
|
|
563
|
-
objectNumber: number
|
|
564
|
-
generationNumber?: number
|
|
565
|
-
}
|
|
566
|
-
| PdfObjectReference,
|
|
567
|
-
): PdfIndirectObject | undefined {
|
|
568
|
-
const xrefEntry = this.xrefLookup.getObject(options.objectNumber)
|
|
569
|
-
|
|
414
|
+
findUncompressedObject(options) {
|
|
415
|
+
const xrefEntry = this.xrefLookup.getObject(options.objectNumber);
|
|
570
416
|
if (xrefEntry instanceof PdfXRefStreamCompressedEntry) {
|
|
571
|
-
throw new FoundCompressedObjectError(
|
|
572
|
-
`TODO: Cannot find object ${options.objectNumber} inside object stream via PdfDocument.findObject`,
|
|
573
|
-
)
|
|
417
|
+
throw new FoundCompressedObjectError(`TODO: Cannot find object ${options.objectNumber} inside object stream via PdfDocument.findObject`);
|
|
574
418
|
}
|
|
575
|
-
|
|
576
|
-
if (
|
|
577
|
-
!xrefEntry ||
|
|
419
|
+
if (!xrefEntry ||
|
|
578
420
|
(options.generationNumber !== undefined &&
|
|
579
|
-
xrefEntry.generationNumber.value !== options.generationNumber)
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
obj.objectNumber === options.objectNumber &&
|
|
588
|
-
(options.generationNumber === undefined ||
|
|
589
|
-
obj.generationNumber === options.generationNumber) &&
|
|
590
|
-
obj.offset.equals(xrefEntry.byteOffset.ref),
|
|
591
|
-
) as PdfIndirectObject | undefined
|
|
421
|
+
xrefEntry.generationNumber.value !== options.generationNumber)) {
|
|
422
|
+
return undefined;
|
|
423
|
+
}
|
|
424
|
+
return this.objects.find((obj) => obj instanceof PdfIndirectObject &&
|
|
425
|
+
obj.objectNumber === options.objectNumber &&
|
|
426
|
+
(options.generationNumber === undefined ||
|
|
427
|
+
obj.generationNumber === options.generationNumber) &&
|
|
428
|
+
obj.offset.equals(xrefEntry.byteOffset.ref));
|
|
592
429
|
}
|
|
593
|
-
|
|
594
430
|
/**
|
|
595
431
|
* Reads and optionally decrypts an object by its object number.
|
|
596
432
|
* Handles both compressed and uncompressed objects.
|
|
@@ -601,140 +437,110 @@ export class PdfDocument extends PdfObject {
|
|
|
601
437
|
* @param options.allowUnindexed - If true, searches unindexed objects as fallback
|
|
602
438
|
* @returns A cloned and decrypted copy of the object, or undefined if not found
|
|
603
439
|
*/
|
|
604
|
-
async readObject(options
|
|
605
|
-
|
|
606
|
-
generationNumber?: number
|
|
607
|
-
allowUnindexed?: boolean
|
|
608
|
-
}): Promise<PdfIndirectObject | undefined> {
|
|
609
|
-
let foundObject: PdfIndirectObject | undefined
|
|
610
|
-
|
|
440
|
+
async readObject(options) {
|
|
441
|
+
let foundObject;
|
|
611
442
|
try {
|
|
612
|
-
foundObject = this.findUncompressedObject(options)
|
|
613
|
-
}
|
|
443
|
+
foundObject = this.findUncompressedObject(options);
|
|
444
|
+
}
|
|
445
|
+
catch (e) {
|
|
614
446
|
if (e instanceof FoundCompressedObjectError) {
|
|
615
|
-
foundObject = await this.findCompressedObject(options)
|
|
616
|
-
}
|
|
617
|
-
|
|
447
|
+
foundObject = await this.findCompressedObject(options);
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
throw e;
|
|
618
451
|
}
|
|
619
452
|
}
|
|
620
|
-
|
|
621
453
|
if (!foundObject && options.allowUnindexed) {
|
|
622
|
-
foundObject = this.objects.find(
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
obj.
|
|
626
|
-
|
|
627
|
-
obj.generationNumber === options.generationNumber),
|
|
628
|
-
) as PdfIndirectObject | undefined
|
|
629
|
-
}
|
|
630
|
-
|
|
454
|
+
foundObject = this.objects.find((obj) => obj instanceof PdfIndirectObject &&
|
|
455
|
+
obj.objectNumber === options.objectNumber &&
|
|
456
|
+
(options.generationNumber === undefined ||
|
|
457
|
+
obj.generationNumber === options.generationNumber));
|
|
458
|
+
}
|
|
631
459
|
if (!foundObject) {
|
|
632
|
-
return undefined
|
|
460
|
+
return undefined;
|
|
633
461
|
}
|
|
634
|
-
|
|
635
462
|
if (this.securityHandler && this.isObjectEncryptable(foundObject)) {
|
|
636
|
-
foundObject = foundObject.clone()
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
foundObject = foundObject.clone() // Clone to prevent modifications in locked revisions
|
|
463
|
+
foundObject = foundObject.clone();
|
|
464
|
+
await this.securityHandler.decryptObject(foundObject);
|
|
465
|
+
}
|
|
466
|
+
else if (this.isIncremental()) {
|
|
467
|
+
foundObject = foundObject.clone(); // Clone to prevent modifications in locked revisions
|
|
641
468
|
}
|
|
642
|
-
|
|
643
|
-
return foundObject
|
|
469
|
+
return foundObject;
|
|
644
470
|
}
|
|
645
471
|
/**
|
|
646
472
|
* Deletes an object from all revisions in the document.
|
|
647
473
|
*
|
|
648
474
|
* @param obj - The PDF object to delete
|
|
649
475
|
*/
|
|
650
|
-
async deleteObject(obj
|
|
651
|
-
if (!obj)
|
|
652
|
-
|
|
476
|
+
async deleteObject(obj) {
|
|
477
|
+
if (!obj)
|
|
478
|
+
return;
|
|
653
479
|
for (const revision of this.revisions) {
|
|
654
|
-
revision.deleteObject(obj)
|
|
480
|
+
revision.deleteObject(obj);
|
|
655
481
|
}
|
|
656
|
-
|
|
657
|
-
await this.update()
|
|
482
|
+
await this.update();
|
|
658
483
|
}
|
|
659
|
-
|
|
660
484
|
/**
|
|
661
485
|
* Sets the PDF version for the document.
|
|
662
486
|
*
|
|
663
487
|
* @param version - The PDF version string (e.g., '1.7', '2.0')
|
|
664
488
|
* @throws Error if attempting to change version after objects have been added in incremental mode
|
|
665
489
|
*/
|
|
666
|
-
setVersion(version
|
|
490
|
+
setVersion(version) {
|
|
667
491
|
if (this.revisions[0].locked) {
|
|
668
|
-
throw new Error(
|
|
669
|
-
'Cannot change PDF version in incremental mode after objects have been added',
|
|
670
|
-
)
|
|
492
|
+
throw new Error('Cannot change PDF version in incremental mode after objects have been added');
|
|
671
493
|
}
|
|
672
|
-
|
|
673
|
-
this.header = PdfComment.versionComment(version)
|
|
494
|
+
this.header = PdfComment.versionComment(version);
|
|
674
495
|
}
|
|
675
|
-
|
|
676
496
|
/**
|
|
677
497
|
* Sets whether the document should use incremental updates.
|
|
678
498
|
* When true, locks all existing revisions to preserve original content.
|
|
679
499
|
*
|
|
680
500
|
* @param value - True to enable incremental mode, false to disable
|
|
681
501
|
*/
|
|
682
|
-
setIncremental(value
|
|
502
|
+
setIncremental(value) {
|
|
683
503
|
for (const revision of this.revisions) {
|
|
684
|
-
revision.locked = value
|
|
504
|
+
revision.locked = value;
|
|
685
505
|
}
|
|
686
506
|
}
|
|
687
|
-
|
|
688
507
|
/**
|
|
689
508
|
* Checks if the document is in incremental mode.
|
|
690
509
|
*
|
|
691
510
|
* @returns True if all revisions are locked for incremental updates
|
|
692
511
|
*/
|
|
693
|
-
isIncremental()
|
|
694
|
-
return this.latestRevision.locked
|
|
512
|
+
isIncremental() {
|
|
513
|
+
return this.latestRevision.locked;
|
|
695
514
|
}
|
|
696
|
-
|
|
697
515
|
/**
|
|
698
516
|
* Commits pending objects to the document.
|
|
699
517
|
* Adds objects, applies encryption if configured, and updates the document structure.
|
|
700
518
|
*
|
|
701
519
|
* @param newObjects - Additional objects to add before committing
|
|
702
520
|
*/
|
|
703
|
-
async commit(...newObjects
|
|
704
|
-
this.add(...newObjects)
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
this.toBeCommitted = []
|
|
708
|
-
|
|
521
|
+
async commit(...newObjects) {
|
|
522
|
+
this.add(...newObjects);
|
|
523
|
+
const queue = this.toBeCommitted.slice();
|
|
524
|
+
this.toBeCommitted = [];
|
|
709
525
|
for (const newObject of queue) {
|
|
710
|
-
if (
|
|
711
|
-
this.securityHandler &&
|
|
526
|
+
if (this.securityHandler &&
|
|
712
527
|
newObject instanceof PdfIndirectObject &&
|
|
713
|
-
this.isObjectEncryptable(newObject)
|
|
714
|
-
|
|
715
|
-
await this.securityHandler.write()
|
|
716
|
-
|
|
528
|
+
this.isObjectEncryptable(newObject)) {
|
|
529
|
+
await this.securityHandler.write();
|
|
717
530
|
if (!this.hasEncryptionDictionary) {
|
|
718
531
|
const encryptionDictObject = new PdfIndirectObject({
|
|
719
|
-
content: this.securityHandler
|
|
532
|
+
content: this.securityHandler.dict,
|
|
720
533
|
encryptable: false,
|
|
721
|
-
})
|
|
722
|
-
|
|
723
|
-
this.
|
|
724
|
-
this.
|
|
725
|
-
'Encrypt',
|
|
726
|
-
encryptionDictObject.reference,
|
|
727
|
-
)
|
|
728
|
-
this.hasEncryptionDictionary = true
|
|
534
|
+
});
|
|
535
|
+
this.latestRevision.addObject(encryptionDictObject);
|
|
536
|
+
this.trailerDict.set('Encrypt', encryptionDictObject.reference);
|
|
537
|
+
this.hasEncryptionDictionary = true;
|
|
729
538
|
}
|
|
730
|
-
|
|
731
|
-
await this.securityHandler.encryptObject(newObject)
|
|
539
|
+
await this.securityHandler.encryptObject(newObject);
|
|
732
540
|
}
|
|
733
541
|
}
|
|
734
|
-
|
|
735
|
-
await this.update()
|
|
542
|
+
await this.update();
|
|
736
543
|
}
|
|
737
|
-
|
|
738
544
|
/**
|
|
739
545
|
* Sets the Document Security Store (DSS) for the document.
|
|
740
546
|
* Used for long-term validation of digital signatures.
|
|
@@ -742,183 +548,141 @@ export class PdfDocument extends PdfObject {
|
|
|
742
548
|
* @param dss - The Document Security Store object to set
|
|
743
549
|
* @throws Error if the document has no root dictionary
|
|
744
550
|
*/
|
|
745
|
-
async setDocumentSecurityStore(
|
|
746
|
-
|
|
747
|
-
): Promise<void> {
|
|
748
|
-
let rootDictionary = this.rootDictionary
|
|
551
|
+
async setDocumentSecurityStore(dss) {
|
|
552
|
+
let rootDictionary = this.rootDictionary;
|
|
749
553
|
if (!rootDictionary) {
|
|
750
|
-
throw new Error('Cannot set DSS - document has no root dictionary')
|
|
554
|
+
throw new Error('Cannot set DSS - document has no root dictionary');
|
|
751
555
|
}
|
|
752
|
-
rootDictionary.set('DSS', dss.reference)
|
|
753
|
-
|
|
556
|
+
rootDictionary.set('DSS', dss.reference);
|
|
754
557
|
if (!this.hasObject(dss)) {
|
|
755
|
-
await this.commit(dss)
|
|
558
|
+
await this.commit(dss);
|
|
756
559
|
}
|
|
757
560
|
}
|
|
758
|
-
|
|
759
561
|
/**
|
|
760
562
|
* Returns tokens paired with their source objects.
|
|
761
563
|
* Useful for debugging and analysis of document structure.
|
|
762
564
|
*
|
|
763
565
|
* @returns Array of token-object pairs
|
|
764
566
|
*/
|
|
765
|
-
tokensWithObjects()
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
object: PdfObject | undefined
|
|
772
|
-
}[] = this.objects.flatMap((obj) => {
|
|
773
|
-
const tokens = obj.toTokens()
|
|
774
|
-
if (
|
|
775
|
-
tokens.length > 0 &&
|
|
776
|
-
!(tokens[tokens.length - 1] instanceof PdfWhitespaceToken)
|
|
777
|
-
) {
|
|
778
|
-
tokens.push(PdfWhitespaceToken.NEWLINE)
|
|
567
|
+
tokensWithObjects() {
|
|
568
|
+
const documentTokens = this.objects.flatMap((obj) => {
|
|
569
|
+
const tokens = obj.toTokens();
|
|
570
|
+
if (tokens.length > 0 &&
|
|
571
|
+
!(tokens[tokens.length - 1] instanceof PdfWhitespaceToken)) {
|
|
572
|
+
tokens.push(PdfWhitespaceToken.NEWLINE);
|
|
779
573
|
}
|
|
780
|
-
return tokens.map((token) => ({ token, object: obj }))
|
|
781
|
-
})
|
|
782
|
-
|
|
574
|
+
return tokens.map((token) => ({ token, object: obj }));
|
|
575
|
+
});
|
|
783
576
|
const headerTokens = this.header
|
|
784
577
|
.toTokens()
|
|
785
|
-
.map((token) => ({ token, object: this.header }))
|
|
786
|
-
|
|
787
|
-
documentTokens
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
private linkRevisions(): void {
|
|
797
|
-
const xrefLookups = this.revisions.map((rev) => rev.xref)
|
|
798
|
-
const indirectObjects = this.objects.filter(
|
|
799
|
-
(x) => x instanceof PdfIndirectObject,
|
|
800
|
-
)
|
|
801
|
-
|
|
578
|
+
.map((token) => ({ token, object: this.header }));
|
|
579
|
+
documentTokens.unshift(...headerTokens);
|
|
580
|
+
return documentTokens;
|
|
581
|
+
}
|
|
582
|
+
tokenize() {
|
|
583
|
+
return this.tokensWithObjects().map(({ token }) => token);
|
|
584
|
+
}
|
|
585
|
+
linkRevisions() {
|
|
586
|
+
const xrefLookups = this.revisions.map((rev) => rev.xref);
|
|
587
|
+
const indirectObjects = this.objects.filter((x) => x instanceof PdfIndirectObject);
|
|
802
588
|
for (const revision of this.revisions) {
|
|
803
|
-
revision.xref.linkPrev(xrefLookups)
|
|
804
|
-
revision.xref.linkIndirectObjects(indirectObjects)
|
|
589
|
+
revision.xref.linkPrev(xrefLookups);
|
|
590
|
+
revision.xref.linkIndirectObjects(indirectObjects);
|
|
805
591
|
}
|
|
806
592
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
const
|
|
810
|
-
number,
|
|
811
|
-
{
|
|
812
|
-
main?: Ref<number>
|
|
813
|
-
others?: Set<Ref<number>>
|
|
814
|
-
}
|
|
815
|
-
>()
|
|
816
|
-
|
|
817
|
-
const tokens = this.toTokens()
|
|
818
|
-
|
|
593
|
+
linkOffsets() {
|
|
594
|
+
const refMap = new Map();
|
|
595
|
+
const tokens = this.toTokens();
|
|
819
596
|
for (let i = 0; i < tokens.length; i++) {
|
|
820
|
-
const token = tokens[i]
|
|
821
|
-
let main
|
|
822
|
-
let other
|
|
823
|
-
|
|
597
|
+
const token = tokens[i];
|
|
598
|
+
let main;
|
|
599
|
+
let other;
|
|
824
600
|
if (token instanceof PdfByteOffsetToken) {
|
|
825
|
-
main = token.value
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
601
|
+
main = token.value;
|
|
602
|
+
}
|
|
603
|
+
else if (token instanceof PdfXRefTableEntryToken) {
|
|
604
|
+
other = token.offset.ref;
|
|
605
|
+
}
|
|
606
|
+
else if (token instanceof PdfNumberToken && token.isByteToken) {
|
|
607
|
+
other = token.ref;
|
|
830
608
|
}
|
|
831
|
-
|
|
832
609
|
if (!other && !main) {
|
|
833
|
-
continue
|
|
610
|
+
continue;
|
|
834
611
|
}
|
|
835
|
-
|
|
836
|
-
const id = (main ?? other)!.resolve()
|
|
612
|
+
const id = (main ?? other).resolve();
|
|
837
613
|
if (!refMap.has(id)) {
|
|
838
|
-
refMap.set(id, { main: main, others: new Set
|
|
614
|
+
refMap.set(id, { main: main, others: new Set() });
|
|
839
615
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
if (other)
|
|
616
|
+
if (main)
|
|
617
|
+
refMap.get(id).main = main;
|
|
618
|
+
if (other)
|
|
619
|
+
refMap.get(id).others.add(other);
|
|
843
620
|
}
|
|
844
|
-
|
|
845
621
|
for (const [, { main, others }] of refMap) {
|
|
846
|
-
if (!main)
|
|
847
|
-
|
|
622
|
+
if (!main)
|
|
623
|
+
continue;
|
|
848
624
|
for (const other of others ?? []) {
|
|
849
|
-
other.update(main)
|
|
625
|
+
other.update(main);
|
|
850
626
|
}
|
|
851
627
|
}
|
|
852
628
|
}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
serializer.
|
|
857
|
-
|
|
858
|
-
this.linkOffsets()
|
|
629
|
+
calculateOffsets() {
|
|
630
|
+
const serializer = new PdfTokenSerializer();
|
|
631
|
+
serializer.feed(...this.toTokens());
|
|
632
|
+
serializer.calculateOffsets();
|
|
633
|
+
this.linkOffsets();
|
|
859
634
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
let modified = false
|
|
635
|
+
updateRevisions() {
|
|
636
|
+
let modified = false;
|
|
863
637
|
this.revisions.forEach((rev, i) => {
|
|
864
638
|
if (rev.isModified()) {
|
|
865
|
-
modified = true
|
|
639
|
+
modified = true;
|
|
866
640
|
}
|
|
867
|
-
|
|
868
641
|
if (modified) {
|
|
869
|
-
rev.update()
|
|
642
|
+
rev.update();
|
|
870
643
|
}
|
|
871
|
-
})
|
|
644
|
+
});
|
|
872
645
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
this.
|
|
876
|
-
this.
|
|
877
|
-
await this.signer?.sign(this)
|
|
646
|
+
async update() {
|
|
647
|
+
this.calculateOffsets();
|
|
648
|
+
this.updateRevisions();
|
|
649
|
+
await this.signer?.sign(this);
|
|
878
650
|
}
|
|
879
|
-
|
|
880
651
|
/**
|
|
881
652
|
* Serializes the document to a byte array.
|
|
882
653
|
*
|
|
883
654
|
* @returns The PDF document as a Uint8Array
|
|
884
655
|
*/
|
|
885
|
-
toBytes()
|
|
886
|
-
this.calculateOffsets()
|
|
887
|
-
this.updateRevisions()
|
|
888
|
-
const serializer = new PdfTokenSerializer()
|
|
889
|
-
serializer.feed(...this.toTokens())
|
|
890
|
-
return serializer.toBytes()
|
|
891
|
-
}
|
|
892
|
-
|
|
656
|
+
toBytes() {
|
|
657
|
+
this.calculateOffsets();
|
|
658
|
+
this.updateRevisions();
|
|
659
|
+
const serializer = new PdfTokenSerializer();
|
|
660
|
+
serializer.feed(...this.toTokens());
|
|
661
|
+
return serializer.toBytes();
|
|
662
|
+
}
|
|
893
663
|
/**
|
|
894
664
|
* Creates a deep copy of the document.
|
|
895
665
|
*
|
|
896
666
|
* @returns A cloned PdfDocument instance
|
|
897
667
|
*/
|
|
898
|
-
clone()
|
|
899
|
-
const clonedRevisions = this.revisions.map((rev) => rev.clone())
|
|
668
|
+
clone() {
|
|
669
|
+
const clonedRevisions = this.revisions.map((rev) => rev.clone());
|
|
900
670
|
return new PdfDocument({
|
|
901
671
|
revisions: clonedRevisions,
|
|
902
672
|
version: this.header.clone(),
|
|
903
673
|
securityHandler: this.securityHandler,
|
|
904
|
-
})
|
|
674
|
+
});
|
|
905
675
|
}
|
|
906
|
-
|
|
907
676
|
/**
|
|
908
677
|
* Creates a PdfDocument from a byte stream.
|
|
909
678
|
*
|
|
910
679
|
* @param input - Async or sync iterable of byte arrays
|
|
911
680
|
* @returns A promise that resolves to the parsed PdfDocument
|
|
912
681
|
*/
|
|
913
|
-
static fromBytes(
|
|
914
|
-
input
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
isModified(): boolean {
|
|
920
|
-
return (
|
|
921
|
-
super.isModified() || this.revisions.some((rev) => rev.isModified())
|
|
922
|
-
)
|
|
682
|
+
static fromBytes(input) {
|
|
683
|
+
return PdfReader.fromBytes(input);
|
|
684
|
+
}
|
|
685
|
+
isModified() {
|
|
686
|
+
return (super.isModified() || this.revisions.some((rev) => rev.isModified()));
|
|
923
687
|
}
|
|
924
688
|
}
|