@pdfme/pdf-lib 6.0.3-dev.0 → 6.0.4-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src/api/Embeddable.ts → dist/api/Embeddable.d.ts} +1 -1
- package/dist/api/PDFDocument.d.ts +778 -0
- package/dist/api/PDFDocumentOptions.d.ts +38 -0
- package/dist/api/PDFEmbeddedFile.d.ts +38 -0
- package/dist/api/PDFEmbeddedPage.d.ts +73 -0
- package/dist/api/PDFFont.d.ts +94 -0
- package/dist/api/PDFImage.d.ts +95 -0
- package/dist/api/PDFJavaScript.d.ts +38 -0
- package/dist/api/PDFPage.d.ts +910 -0
- package/dist/api/PDFPageOptions.d.ts +172 -0
- package/dist/api/StandardFonts.d.ts +16 -0
- package/dist/api/colors.d.ts +34 -0
- package/dist/api/errors.d.ts +42 -0
- package/dist/api/form/PDFButton.d.ts +137 -0
- package/dist/api/form/PDFCheckBox.d.ts +142 -0
- package/dist/api/form/PDFDropdown.d.ts +402 -0
- package/dist/api/form/PDFField.d.ts +203 -0
- package/dist/api/form/PDFForm.d.ts +411 -0
- package/dist/api/form/PDFOptionList.d.ts +335 -0
- package/dist/api/form/PDFRadioGroup.d.ts +252 -0
- package/dist/api/form/PDFSignature.d.ts +29 -0
- package/dist/api/form/PDFTextField.d.ts +537 -0
- package/dist/api/form/appearances.d.ts +41 -0
- package/dist/api/image/alignment.d.ts +5 -0
- package/dist/api/objects.d.ts +4 -0
- package/dist/api/operations.d.ts +226 -0
- package/dist/api/operators.d.ts +90 -0
- package/dist/api/rotations.d.ts +38 -0
- package/dist/api/sizes.d.ts +52 -0
- package/dist/api/svg.d.ts +70 -0
- package/dist/api/svgPath.d.ts +2 -0
- package/dist/api/text/alignment.d.ts +5 -0
- package/dist/api/text/layout.d.ts +54 -0
- package/dist/core/PDFContext.d.ts +84 -0
- package/dist/core/PDFObjectCopier.d.ts +37 -0
- package/dist/core/acroform/PDFAcroButton.d.ts +21 -0
- package/dist/core/acroform/PDFAcroCheckBox.d.ts +13 -0
- package/dist/core/acroform/PDFAcroChoice.d.ts +20 -0
- package/dist/core/acroform/PDFAcroComboBox.d.ts +9 -0
- package/dist/core/acroform/PDFAcroField.d.ts +36 -0
- package/dist/core/acroform/PDFAcroForm.d.ts +20 -0
- package/dist/core/acroform/PDFAcroListBox.d.ts +9 -0
- package/dist/core/acroform/PDFAcroNonTerminal.d.ts +13 -0
- package/dist/core/acroform/PDFAcroPushButton.d.ts +9 -0
- package/dist/core/acroform/PDFAcroRadioButton.d.ts +13 -0
- package/{src/core/acroform/PDFAcroSignature.ts → dist/core/acroform/PDFAcroSignature.d.ts} +2 -4
- package/dist/core/acroform/PDFAcroTerminal.d.ts +16 -0
- package/dist/core/acroform/PDFAcroText.d.ts +22 -0
- package/dist/core/acroform/flags.d.ts +141 -0
- package/dist/core/acroform/utils.d.ts +6 -0
- package/dist/core/annotation/AppearanceCharacteristics.d.ts +33 -0
- package/dist/core/annotation/BorderStyle.d.ts +11 -0
- package/dist/core/annotation/PDFAnnotation.d.ts +51 -0
- package/dist/core/annotation/PDFWidgetAnnotation.d.ts +26 -0
- package/dist/core/annotation/flags.d.ts +79 -0
- package/dist/core/crypto.d.ts +95 -0
- package/dist/core/document/PDFCrossRefSection.d.ts +27 -0
- package/dist/core/document/PDFHeader.d.ts +10 -0
- package/dist/core/document/PDFTrailer.d.ts +9 -0
- package/dist/core/document/PDFTrailerDict.d.ts +10 -0
- package/dist/core/embedders/CMap.d.ts +3 -0
- package/dist/core/embedders/CustomFontEmbedder.d.ts +44 -0
- package/dist/core/embedders/CustomFontSubsetEmbedder.d.ts +20 -0
- package/dist/core/embedders/FileEmbedder.d.ts +33 -0
- package/dist/core/embedders/FontFlags.d.ts +13 -0
- package/dist/core/embedders/JavaScriptEmbedder.d.ts +10 -0
- package/dist/core/embedders/JpegEmbedder.d.ts +23 -0
- package/dist/core/embedders/PDFPageEmbedder.d.ts +37 -0
- package/dist/core/embedders/PngEmbedder.d.ts +19 -0
- package/dist/core/embedders/StandardFontEmbedder.d.ts +36 -0
- package/dist/core/errors.d.ts +94 -0
- package/{src/core/index.ts → dist/core/index.d.ts} +1 -17
- package/dist/core/interactive/ViewerPreferences.d.ts +347 -0
- package/dist/core/objects/PDFArray.d.ts +63 -0
- package/dist/core/objects/PDFBool.d.ts +13 -0
- package/dist/core/objects/PDFDict.d.ts +62 -0
- package/dist/core/objects/PDFHexString.d.ts +16 -0
- package/dist/core/objects/PDFInvalidObject.d.ts +11 -0
- package/dist/core/objects/PDFName.d.ts +41 -0
- package/dist/core/objects/PDFNull.d.ts +10 -0
- package/dist/core/objects/PDFNumber.d.ts +15 -0
- package/dist/core/objects/PDFObject.d.ts +8 -0
- package/dist/core/objects/PDFRawStream.d.ts +16 -0
- package/dist/core/objects/PDFRef.d.ts +13 -0
- package/dist/core/objects/PDFStream.d.ts +16 -0
- package/dist/core/objects/PDFString.d.ts +16 -0
- package/dist/core/operators/PDFOperator.d.ts +19 -0
- package/dist/core/operators/PDFOperatorNames.d.ts +76 -0
- package/dist/core/parser/BaseParser.d.ts +14 -0
- package/dist/core/parser/ByteStream.d.ts +26 -0
- package/dist/core/parser/PDFObjectParser.d.ts +31 -0
- package/dist/core/parser/PDFObjectStreamParser.d.ts +13 -0
- package/dist/core/parser/PDFParser.d.ts +46 -0
- package/dist/core/parser/PDFXRefStreamParser.d.ts +21 -0
- package/dist/core/streams/Ascii85Stream.d.ts +9 -0
- package/dist/core/streams/AsciiHexStream.d.ts +9 -0
- package/dist/core/streams/DecodeStream.d.ts +26 -0
- package/dist/core/streams/DecryptStream.d.ts +12 -0
- package/dist/core/streams/FlateStream.d.ts +13 -0
- package/dist/core/streams/LZWStream.d.ts +12 -0
- package/dist/core/streams/RunLengthStream.d.ts +8 -0
- package/dist/core/streams/Stream.d.ts +34 -0
- package/dist/core/streams/decode.d.ts +3 -0
- package/dist/core/structures/PDFCatalog.d.ts +27 -0
- package/dist/core/structures/PDFContentStream.d.ts +15 -0
- package/dist/core/structures/PDFCrossRefStream.d.ts +53 -0
- package/dist/core/structures/PDFFlateStream.d.ts +13 -0
- package/dist/core/structures/PDFObjectStream.d.ts +20 -0
- package/dist/core/structures/PDFPageLeaf.d.ts +54 -0
- package/dist/core/structures/PDFPageTree.d.ts +41 -0
- package/dist/core/syntax/CharCodes.d.ts +61 -0
- package/dist/core/syntax/Delimiters.d.ts +1 -0
- package/dist/core/syntax/Irregular.d.ts +1 -0
- package/dist/core/syntax/Keywords.d.ts +22 -0
- package/dist/core/syntax/Numeric.d.ts +3 -0
- package/dist/core/syntax/Whitespace.d.ts +1 -0
- package/dist/core/writers/PDFStreamWriter.d.ts +19 -0
- package/dist/core/writers/PDFWriter.d.ts +29 -0
- package/dist/index.js +19124 -0
- package/dist/index.js.map +1 -0
- package/dist/types/fontkit.d.ts +597 -0
- package/{src/types/index.ts → dist/types/index.d.ts} +8 -13
- package/{src/types/matrix.ts → dist/types/matrix.d.ts} +1 -2
- package/dist/utils/Cache.d.ts +10 -0
- package/dist/utils/arrays.d.ts +16 -0
- package/dist/utils/async.d.ts +5 -0
- package/dist/utils/base64.d.ts +10 -0
- package/dist/utils/elements/Arc.d.ts +22 -0
- package/dist/utils/elements/Circle.d.ts +14 -0
- package/dist/utils/elements/Ellipse.d.ts +20 -0
- package/dist/utils/elements/GraphElement.d.ts +6 -0
- package/dist/utils/elements/Line.d.ts +23 -0
- package/dist/utils/elements/Plot.d.ts +11 -0
- package/dist/utils/elements/Point.d.ts +18 -0
- package/dist/utils/elements/Rectangle.d.ts +21 -0
- package/dist/utils/elements/Segment.d.ts +19 -0
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/intersections.d.ts +9 -0
- package/dist/utils/maths.d.ts +45 -0
- package/dist/utils/numbers.d.ts +23 -0
- package/dist/utils/objects.d.ts +15 -0
- package/dist/utils/pdfDocEncoding.d.ts +7 -0
- package/dist/utils/png.d.ts +17 -0
- package/dist/utils/rng.d.ts +13 -0
- package/dist/utils/strings.d.ts +25 -0
- package/{src/utils/unicode.ts → dist/utils/unicode.d.ts} +8 -195
- package/dist/utils/validators.d.ts +26 -0
- package/package.json +6 -1
- package/__tests__/api/PDFDocument.spec.ts +0 -576
- package/__tests__/api/PDFImage.spec.ts +0 -60
- package/__tests__/api/PDFPage.spec.ts +0 -151
- package/__tests__/api/form/PDFCheckBox.spec.ts +0 -71
- package/__tests__/api/form/PDFDropdown.spec.ts +0 -118
- package/__tests__/api/form/PDFForm.spec.ts +0 -370
- package/__tests__/api/form/PDFOptionList.spec.ts +0 -104
- package/__tests__/api/form/PDFRadioGroup.spec.ts +0 -183
- package/__tests__/api/form/PDFTextField.spec.ts +0 -148
- package/__tests__/api/svgPath.spec.ts +0 -153
- package/__tests__/api/text/layout.spec.ts +0 -166
- package/__tests__/core/PDFContext.spec.ts +0 -194
- package/__tests__/core/PDFObjectCopier.spec.ts +0 -421
- package/__tests__/core/acroform/PDFAcroField.spec.ts +0 -98
- package/__tests__/core/acroform/PDFAcroTerminal.spec.ts +0 -39
- package/__tests__/core/annotation/PDFWidgetAnnotation.spec.ts +0 -40
- package/__tests__/core/document/PDFCrossRefSection.spec.ts +0 -88
- package/__tests__/core/document/PDFHeader.spec.ts +0 -22
- package/__tests__/core/document/PDFTrailer.spec.ts +0 -28
- package/__tests__/core/document/PDFTrailerDict.spec.ts +0 -24
- package/__tests__/core/embedders/CMap.spec.ts +0 -47
- package/__tests__/core/embedders/CustomFontEmbedder.spec.ts +0 -96
- package/__tests__/core/embedders/CustomFontSubsetEmbedder.spec.ts +0 -62
- package/__tests__/core/embedders/FileEmbedder.spec.ts +0 -54
- package/__tests__/core/embedders/JpegEmbedder.spec.ts +0 -67
- package/__tests__/core/embedders/PDFPageEmbedder.spec.ts +0 -65
- package/__tests__/core/embedders/PngEmbedder.spec.ts +0 -87
- package/__tests__/core/embedders/StandardFontEmbedder.spec.ts +0 -79
- package/__tests__/core/embedders/data/SourceHanSerifJP-Regular.otf.cmap +0 -16096
- package/__tests__/core/embedders/data/Ubuntu-R.ttf.cmap +0 -1211
- package/__tests__/core/objects/PDFArray.spec.ts +0 -134
- package/__tests__/core/objects/PDFBool.spec.ts +0 -42
- package/__tests__/core/objects/PDFDict.spec.ts +0 -195
- package/__tests__/core/objects/PDFHexString.spec.ts +0 -168
- package/__tests__/core/objects/PDFInvalidObject.spec.ts +0 -32
- package/__tests__/core/objects/PDFName.spec.ts +0 -122
- package/__tests__/core/objects/PDFNull.spec.ts +0 -30
- package/__tests__/core/objects/PDFNumber.spec.ts +0 -50
- package/__tests__/core/objects/PDFObject.spec.ts +0 -29
- package/__tests__/core/objects/PDFRawStream.spec.ts +0 -45
- package/__tests__/core/objects/PDFRef.spec.ts +0 -60
- package/__tests__/core/objects/PDFString.spec.ts +0 -237
- package/__tests__/core/operators/PDFOperator.spec.ts +0 -77
- package/__tests__/core/parser/PDFObjectParser.spec.ts +0 -730
- package/__tests__/core/parser/PDFObjectStreamParser.spec.ts +0 -158
- package/__tests__/core/parser/PDFParser.spec.ts +0 -398
- package/__tests__/core/parser/PDFXRefStreamParser.spec.ts +0 -187
- package/__tests__/core/parser/data/object-stream-invalid +0 -2
- package/__tests__/core/parser/data/object-stream1 +0 -16
- package/__tests__/core/parser/data/object-stream2 +0 -10
- package/__tests__/core/parser/data/object-stream3 +0 -0
- package/__tests__/core/parser/data/object-stream4 +0 -0
- package/__tests__/core/parser/data/xref-stream1 +0 -0
- package/__tests__/core/parser/data/xref-stream2 +0 -0
- package/__tests__/core/parser/data/xref-stream3 +0 -0
- package/__tests__/core/parser/data/xref-stream4 +0 -0
- package/__tests__/core/streams/Ascii85Stream.spec.ts +0 -20
- package/__tests__/core/streams/AsciiHexStream.spec.ts +0 -20
- package/__tests__/core/streams/FlateStream.spec.ts +0 -20
- package/__tests__/core/streams/LZWStream.spec.ts +0 -20
- package/__tests__/core/streams/RunLengthStream.spec.ts +0 -20
- package/__tests__/core/streams/Stream.spec.ts +0 -128
- package/__tests__/core/streams/data/ascii85/1.decoded +0 -0
- package/__tests__/core/streams/data/ascii85/1.encoded +0 -43
- package/__tests__/core/streams/data/asciihex/1.decoded +0 -1
- package/__tests__/core/streams/data/asciihex/1.encoded +0 -1
- package/__tests__/core/streams/data/asciihex/2.decoded +0 -7
- package/__tests__/core/streams/data/asciihex/2.encoded +0 -1
- package/__tests__/core/streams/data/flate/1.corrupt.encoded +0 -1
- package/__tests__/core/streams/data/flate/1.decoded +0 -0
- package/__tests__/core/streams/data/flate/1.encoded +0 -2
- package/__tests__/core/streams/data/flate/2.decoded +0 -33
- package/__tests__/core/streams/data/flate/2.encoded +0 -0
- package/__tests__/core/streams/data/flate/3.decoded +0 -15
- package/__tests__/core/streams/data/flate/3.encoded +0 -0
- package/__tests__/core/streams/data/flate/4.decoded +0 -16
- package/__tests__/core/streams/data/flate/4.encoded +0 -0
- package/__tests__/core/streams/data/flate/5.decoded +0 -0
- package/__tests__/core/streams/data/flate/5.encoded +0 -0
- package/__tests__/core/streams/data/flate/6.decoded +0 -17
- package/__tests__/core/streams/data/flate/6.encoded +0 -0
- package/__tests__/core/streams/data/flate/7.decoded +0 -20
- package/__tests__/core/streams/data/flate/7.encoded +0 -1
- package/__tests__/core/streams/data/lzw/1.decoded +0 -0
- package/__tests__/core/streams/data/lzw/1.encoded +0 -0
- package/__tests__/core/streams/data/lzw/2.decoded +0 -0
- package/__tests__/core/streams/data/lzw/2.encoded +0 -0
- package/__tests__/core/streams/data/lzw/3.decoded +0 -14
- package/__tests__/core/streams/data/lzw/3.encoded +0 -2
- package/__tests__/core/streams/data/lzw/4.decoded +0 -14
- package/__tests__/core/streams/data/lzw/4.encoded +0 -2
- package/__tests__/core/streams/data/runlength/1.decoded +0 -1
- package/__tests__/core/streams/data/runlength/1.encoded +0 -1
- package/__tests__/core/streams/data/runlength/2.decoded +0 -1
- package/__tests__/core/streams/data/runlength/2.encoded +0 -1
- package/__tests__/core/streams/data/runlength/3.decoded +0 -0
- package/__tests__/core/streams/data/runlength/3.encoded +0 -0
- package/__tests__/core/streams/data/runlength/4.decoded +0 -1
- package/__tests__/core/streams/data/runlength/4.encoded +0 -1
- package/__tests__/core/streams/data/runlength/5.decoded +0 -1
- package/__tests__/core/streams/data/runlength/5.encoded +0 -1
- package/__tests__/core/streams/data/runlength/empty.encoded +0 -1
- package/__tests__/core/structures/PDFCatalog.spec.ts +0 -108
- package/__tests__/core/structures/PDFContentStream.spec.ts +0 -117
- package/__tests__/core/structures/PDFCrossRefStream.spec.ts +0 -145
- package/__tests__/core/structures/PDFObjectStream.spec.ts +0 -138
- package/__tests__/core/structures/PDFPageLeaf.spec.ts +0 -355
- package/__tests__/core/structures/PDFPageTree.spec.ts +0 -592
- package/__tests__/core/writers/PDFStreamWriter.spec.ts +0 -71
- package/__tests__/core/writers/PDFWriter.spec.ts +0 -144
- package/__tests__/core/writers/data/stream-writer-1.pdf +0 -0
- package/__tests__/index.test.ts +0 -12
- package/__tests__/utils/base64.spec.ts +0 -61
- package/__tests__/utils/data/simple.pdf +0 -201
- package/__tests__/utils/data/simple.pdf.base64 +0 -1
- package/__tests__/utils/pdfDocEncoding.spec.ts +0 -82
- package/__tests__/utils/png.spec.ts +0 -53
- package/__tests__/utils/rng.spec.ts +0 -14
- package/__tests__/utils/strings.spec.ts +0 -98
- package/__tests__/utils/unicode.spec.ts +0 -337
- package/assets/fonts/source_hans_jp/SourceHanSerifJP-Regular.otf +0 -0
- package/assets/fonts/ubuntu/Ubuntu-B.ttf +0 -0
- package/assets/fonts/ubuntu/Ubuntu-R.ttf +0 -0
- package/assets/images/cat_riding_unicorn.jpg +0 -0
- package/assets/images/cmyk_colorspace.jpg +0 -0
- package/assets/images/greyscale_bird.png +0 -0
- package/assets/images/minions_banana_alpha.png +0 -0
- package/assets/images/minions_banana_no_alpha.png +0 -0
- package/assets/images/minions_laughing.jpg +0 -0
- package/assets/pdfs/bixby_guide.pdf +0 -0
- package/assets/pdfs/encrypted_new.pdf +0 -0
- package/assets/pdfs/encrypted_old.pdf +0 -0
- package/assets/pdfs/fancy_fields.pdf +0 -0
- package/assets/pdfs/giraffe.pdf +0 -0
- package/assets/pdfs/invalid_root_ref.pdf +0 -0
- package/assets/pdfs/just_metadata.pdf +0 -49
- package/assets/pdfs/missing_endobj_keyword.pdf +0 -70
- package/assets/pdfs/missing_xref_trailer_dict.pdf +0 -141
- package/assets/pdfs/normal.pdf +0 -0
- package/assets/pdfs/pdf20examples/PDF 2.0 with offset start.pdf +0 -179
- package/assets/pdfs/stuff_following_header.pdf +0 -0
- package/assets/pdfs/us_constitution.pdf +0 -0
- package/assets/pdfs/with_comments.pdf +0 -0
- package/assets/pdfs/with_invalid_objects.pdf +0 -53
- package/assets/pdfs/with_invalid_stream_EOL.pdf +0 -0
- package/assets/pdfs/with_null_parent_entry.pdf +0 -0
- package/assets/pdfs/with_signature.pdf +0 -0
- package/assets/pdfs/with_update_sections.pdf +0 -0
- package/assets/pdfs/with_viewer_prefs.pdf +0 -0
- package/assets/pdfs/with_xfa_fields.pdf +0 -0
- package/src/api/PDFDocument.ts +0 -1389
- package/src/api/PDFDocumentOptions.ts +0 -45
- package/src/api/PDFEmbeddedFile.ts +0 -87
- package/src/api/PDFEmbeddedPage.ts +0 -100
- package/src/api/PDFFont.ts +0 -149
- package/src/api/PDFImage.ts +0 -143
- package/src/api/PDFJavaScript.ts +0 -75
- package/src/api/PDFPage.ts +0 -1604
- package/src/api/PDFPageOptions.ts +0 -175
- package/src/api/StandardFonts.ts +0 -16
- package/src/api/colors.ts +0 -109
- package/src/api/errors.ts +0 -110
- package/src/api/form/PDFButton.ts +0 -242
- package/src/api/form/PDFCheckBox.ts +0 -247
- package/src/api/form/PDFDropdown.ts +0 -637
- package/src/api/form/PDFField.ts +0 -491
- package/src/api/form/PDFForm.ts +0 -842
- package/src/api/form/PDFOptionList.ts +0 -555
- package/src/api/form/PDFRadioGroup.ts +0 -455
- package/src/api/form/PDFSignature.ts +0 -44
- package/src/api/form/PDFTextField.ts +0 -811
- package/src/api/form/appearances.ts +0 -655
- package/src/api/image/alignment.ts +0 -5
- package/src/api/objects.ts +0 -10
- package/src/api/operations.ts +0 -873
- package/src/api/operators.ts +0 -335
- package/src/api/rotations.ts +0 -84
- package/src/api/sizes.ts +0 -52
- package/src/api/svg.ts +0 -888
- package/src/api/svgPath.ts +0 -460
- package/src/api/text/alignment.ts +0 -5
- package/src/api/text/layout.ts +0 -328
- package/src/core/PDFContext.ts +0 -274
- package/src/core/PDFObjectCopier.ts +0 -142
- package/src/core/acroform/PDFAcroButton.ts +0 -104
- package/src/core/acroform/PDFAcroCheckBox.ts +0 -48
- package/src/core/acroform/PDFAcroChoice.ts +0 -143
- package/src/core/acroform/PDFAcroComboBox.ts +0 -21
- package/src/core/acroform/PDFAcroField.ts +0 -168
- package/src/core/acroform/PDFAcroForm.ts +0 -96
- package/src/core/acroform/PDFAcroListBox.ts +0 -19
- package/src/core/acroform/PDFAcroNonTerminal.ts +0 -33
- package/src/core/acroform/PDFAcroPushButton.ts +0 -21
- package/src/core/acroform/PDFAcroRadioButton.ts +0 -57
- package/src/core/acroform/PDFAcroTerminal.ts +0 -70
- package/src/core/acroform/PDFAcroText.ts +0 -76
- package/src/core/acroform/flags.ts +0 -162
- package/src/core/acroform/utils.ts +0 -129
- package/src/core/annotation/AppearanceCharacteristics.ts +0 -133
- package/src/core/annotation/BorderStyle.ts +0 -31
- package/src/core/annotation/PDFAnnotation.ts +0 -148
- package/src/core/annotation/PDFWidgetAnnotation.ts +0 -111
- package/src/core/annotation/flags.ts +0 -90
- package/src/core/crypto.ts +0 -1844
- package/src/core/document/PDFCrossRefSection.ts +0 -161
- package/src/core/document/PDFHeader.ts +0 -48
- package/src/core/document/PDFTrailer.ts +0 -48
- package/src/core/document/PDFTrailerDict.ts +0 -39
- package/src/core/embedders/CMap.ts +0 -65
- package/src/core/embedders/CustomFontEmbedder.ts +0 -237
- package/src/core/embedders/CustomFontSubsetEmbedder.ts +0 -89
- package/src/core/embedders/FileEmbedder.ts +0 -77
- package/src/core/embedders/FontFlags.ts +0 -45
- package/src/core/embedders/JavaScriptEmbedder.ts +0 -34
- package/src/core/embedders/JpegEmbedder.ts +0 -118
- package/src/core/embedders/PDFPageEmbedder.ts +0 -139
- package/src/core/embedders/PngEmbedder.ts +0 -69
- package/src/core/embedders/StandardFontEmbedder.ts +0 -121
- package/src/core/errors.ts +0 -226
- package/src/core/interactive/ViewerPreferences.ts +0 -565
- package/src/core/objects/PDFArray.ts +0 -179
- package/src/core/objects/PDFBool.ts +0 -53
- package/src/core/objects/PDFDict.ts +0 -220
- package/src/core/objects/PDFHexString.ts +0 -94
- package/src/core/objects/PDFInvalidObject.ts +0 -34
- package/src/core/objects/PDFName.ts +0 -152
- package/src/core/objects/PDFNull.ts +0 -30
- package/src/core/objects/PDFNumber.ts +0 -44
- package/src/core/objects/PDFObject.ts +0 -22
- package/src/core/objects/PDFRawStream.ts +0 -41
- package/src/core/objects/PDFRef.ts +0 -51
- package/src/core/objects/PDFStream.ts +0 -87
- package/src/core/objects/PDFString.ts +0 -118
- package/src/core/operators/PDFOperator.ts +0 -72
- package/src/core/operators/PDFOperatorNames.ts +0 -92
- package/src/core/parser/BaseParser.ts +0 -119
- package/src/core/parser/ByteStream.ts +0 -76
- package/src/core/parser/PDFObjectParser.ts +0 -302
- package/src/core/parser/PDFObjectStreamParser.ts +0 -65
- package/src/core/parser/PDFParser.ts +0 -363
- package/src/core/parser/PDFXRefStreamParser.ts +0 -129
- package/src/core/streams/Ascii85Stream.ts +0 -97
- package/src/core/streams/AsciiHexStream.ts +0 -77
- package/src/core/streams/DecodeStream.ts +0 -188
- package/src/core/streams/DecryptStream.ts +0 -49
- package/src/core/streams/FlateStream.ts +0 -397
- package/src/core/streams/LZWStream.ts +0 -157
- package/src/core/streams/RunLengthStream.ts +0 -55
- package/src/core/streams/Stream.ts +0 -126
- package/src/core/streams/decode.ts +0 -70
- package/src/core/structures/PDFCatalog.ts +0 -81
- package/src/core/structures/PDFContentStream.ts +0 -58
- package/src/core/structures/PDFCrossRefStream.ts +0 -238
- package/src/core/structures/PDFFlateStream.ts +0 -40
- package/src/core/structures/PDFObjectStream.ts +0 -91
- package/src/core/structures/PDFPageLeaf.ts +0 -244
- package/src/core/structures/PDFPageTree.ts +0 -192
- package/src/core/syntax/CharCodes.ts +0 -62
- package/src/core/syntax/Delimiters.ts +0 -14
- package/src/core/syntax/Irregular.ts +0 -10
- package/src/core/syntax/Keywords.ts +0 -57
- package/src/core/syntax/Numeric.ts +0 -26
- package/src/core/syntax/Whitespace.ts +0 -10
- package/src/core/writers/PDFStreamWriter.ts +0 -114
- package/src/core/writers/PDFWriter.ts +0 -146
- package/src/types/fontkit.ts +0 -643
- package/src/utils/Cache.ts +0 -26
- package/src/utils/arrays.ts +0 -153
- package/src/utils/async.ts +0 -8
- package/src/utils/base64.ts +0 -98
- package/src/utils/elements/Arc.ts +0 -97
- package/src/utils/elements/Circle.ts +0 -47
- package/src/utils/elements/Ellipse.ts +0 -117
- package/src/utils/elements/GraphElement.ts +0 -14
- package/src/utils/elements/Line.ts +0 -83
- package/src/utils/elements/Plot.ts +0 -50
- package/src/utils/elements/Point.ts +0 -37
- package/src/utils/elements/Rectangle.ts +0 -65
- package/src/utils/elements/Segment.ts +0 -81
- package/src/utils/errors.ts +0 -3
- package/src/utils/intersections.ts +0 -237
- package/src/utils/maths.ts +0 -96
- package/src/utils/numbers.ts +0 -55
- package/src/utils/objects.ts +0 -13
- package/src/utils/pdfDocEncoding.ts +0 -69
- package/src/utils/png.ts +0 -100
- package/src/utils/rng.ts +0 -21
- package/src/utils/strings.ts +0 -191
- package/src/utils/validators.ts +0 -192
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -15
- package/vite.config.mts +0 -39
- /package/{src/api/form/index.ts → dist/api/form/index.d.ts} +0 -0
- /package/{src/api/image/index.ts → dist/api/image/index.d.ts} +0 -0
- /package/{src/api/index.ts → dist/api/index.d.ts} +0 -0
- /package/{src/api/text/index.ts → dist/api/text/index.d.ts} +0 -0
- /package/{src/core/acroform/index.ts → dist/core/acroform/index.d.ts} +0 -0
- /package/{src/core/annotation/index.ts → dist/core/annotation/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/utils/elements/index.ts → dist/utils/elements/index.d.ts} +0 -0
- /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
enum PDFOperatorNames {
|
|
2
|
-
// Non Stroking Color Operators
|
|
3
|
-
NonStrokingColor = 'sc',
|
|
4
|
-
NonStrokingColorN = 'scn',
|
|
5
|
-
NonStrokingColorRgb = 'rg',
|
|
6
|
-
NonStrokingColorGray = 'g',
|
|
7
|
-
NonStrokingColorCmyk = 'k',
|
|
8
|
-
NonStrokingColorspace = 'cs',
|
|
9
|
-
|
|
10
|
-
// Stroking Color Operators
|
|
11
|
-
StrokingColor = 'SC',
|
|
12
|
-
StrokingColorN = 'SCN',
|
|
13
|
-
StrokingColorRgb = 'RG',
|
|
14
|
-
StrokingColorGray = 'G',
|
|
15
|
-
StrokingColorCmyk = 'K',
|
|
16
|
-
StrokingColorspace = 'CS',
|
|
17
|
-
|
|
18
|
-
// Marked Content Operators
|
|
19
|
-
BeginMarkedContentSequence = 'BDC',
|
|
20
|
-
BeginMarkedContent = 'BMC',
|
|
21
|
-
EndMarkedContent = 'EMC',
|
|
22
|
-
MarkedContentPointWithProps = 'DP',
|
|
23
|
-
MarkedContentPoint = 'MP',
|
|
24
|
-
DrawObject = 'Do',
|
|
25
|
-
|
|
26
|
-
// Graphics State Operators
|
|
27
|
-
ConcatTransformationMatrix = 'cm',
|
|
28
|
-
PopGraphicsState = 'Q',
|
|
29
|
-
PushGraphicsState = 'q',
|
|
30
|
-
SetFlatness = 'i',
|
|
31
|
-
SetGraphicsStateParams = 'gs',
|
|
32
|
-
SetLineCapStyle = 'J',
|
|
33
|
-
SetLineDashPattern = 'd',
|
|
34
|
-
SetLineJoinStyle = 'j',
|
|
35
|
-
SetLineMiterLimit = 'M',
|
|
36
|
-
SetLineWidth = 'w',
|
|
37
|
-
SetTextMatrix = 'Tm',
|
|
38
|
-
SetRenderingIntent = 'ri',
|
|
39
|
-
|
|
40
|
-
// Graphics Operators
|
|
41
|
-
AppendRectangle = 're',
|
|
42
|
-
BeginInlineImage = 'BI',
|
|
43
|
-
BeginInlineImageData = 'ID',
|
|
44
|
-
EndInlineImage = 'EI',
|
|
45
|
-
ClipEvenOdd = 'W*',
|
|
46
|
-
ClipNonZero = 'W',
|
|
47
|
-
CloseAndStroke = 's',
|
|
48
|
-
CloseFillEvenOddAndStroke = 'b*',
|
|
49
|
-
CloseFillNonZeroAndStroke = 'b',
|
|
50
|
-
ClosePath = 'h',
|
|
51
|
-
AppendBezierCurve = 'c',
|
|
52
|
-
CurveToReplicateFinalPoint = 'y',
|
|
53
|
-
CurveToReplicateInitialPoint = 'v',
|
|
54
|
-
EndPath = 'n',
|
|
55
|
-
FillEvenOddAndStroke = 'B*',
|
|
56
|
-
FillEvenOdd = 'f*',
|
|
57
|
-
FillNonZeroAndStroke = 'B',
|
|
58
|
-
FillNonZero = 'f',
|
|
59
|
-
LegacyFillNonZero = 'F',
|
|
60
|
-
LineTo = 'l',
|
|
61
|
-
MoveTo = 'm',
|
|
62
|
-
ShadingFill = 'sh',
|
|
63
|
-
StrokePath = 'S',
|
|
64
|
-
|
|
65
|
-
// Text Operators
|
|
66
|
-
BeginText = 'BT',
|
|
67
|
-
EndText = 'ET',
|
|
68
|
-
MoveText = 'Td',
|
|
69
|
-
MoveTextSetLeading = 'TD',
|
|
70
|
-
NextLine = 'T*',
|
|
71
|
-
SetCharacterSpacing = 'Tc',
|
|
72
|
-
SetFontAndSize = 'Tf',
|
|
73
|
-
SetTextHorizontalScaling = 'Tz',
|
|
74
|
-
SetTextLineHeight = 'TL',
|
|
75
|
-
SetTextRenderingMode = 'Tr',
|
|
76
|
-
SetTextRise = 'Ts',
|
|
77
|
-
SetWordSpacing = 'Tw',
|
|
78
|
-
ShowText = 'Tj',
|
|
79
|
-
ShowTextAdjusted = 'TJ',
|
|
80
|
-
ShowTextLine = "'", // tslint:disable-line quotemark
|
|
81
|
-
ShowTextLineAndSpace = '"',
|
|
82
|
-
|
|
83
|
-
// Type3 Font Operators
|
|
84
|
-
Type3D0 = 'd0',
|
|
85
|
-
Type3D1 = 'd1',
|
|
86
|
-
|
|
87
|
-
// Compatibility Section Operators
|
|
88
|
-
BeginCompatibilitySection = 'BX',
|
|
89
|
-
EndCompatibilitySection = 'EX',
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export default PDFOperatorNames;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { NumberParsingError } from '../errors';
|
|
2
|
-
import ByteStream from '../parser/ByteStream';
|
|
3
|
-
import CharCodes from '../syntax/CharCodes';
|
|
4
|
-
import { IsDigit, IsNumeric } from '../syntax/Numeric';
|
|
5
|
-
import { IsWhitespace } from '../syntax/Whitespace';
|
|
6
|
-
import { charFromCode } from '../../utils';
|
|
7
|
-
|
|
8
|
-
const { Newline, CarriageReturn } = CharCodes;
|
|
9
|
-
|
|
10
|
-
// TODO: Throw error if eof is reached before finishing object parse...
|
|
11
|
-
class BaseParser {
|
|
12
|
-
protected readonly bytes: ByteStream;
|
|
13
|
-
protected readonly capNumbers: boolean;
|
|
14
|
-
|
|
15
|
-
constructor(bytes: ByteStream, capNumbers = false) {
|
|
16
|
-
this.bytes = bytes;
|
|
17
|
-
this.capNumbers = capNumbers;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
protected parseRawInt(): number {
|
|
21
|
-
let value = '';
|
|
22
|
-
|
|
23
|
-
while (!this.bytes.done()) {
|
|
24
|
-
const byte = this.bytes.peek();
|
|
25
|
-
if (!IsDigit[byte]) break;
|
|
26
|
-
value += charFromCode(this.bytes.next());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const numberValue = Number(value);
|
|
30
|
-
|
|
31
|
-
if (!value || !isFinite(numberValue)) {
|
|
32
|
-
throw new NumberParsingError(this.bytes.position(), value);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return numberValue;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// TODO: Maybe handle exponential format?
|
|
39
|
-
// TODO: Compare performance of string concatenation to charFromCode(...bytes)
|
|
40
|
-
protected parseRawNumber(): number {
|
|
41
|
-
let value = '';
|
|
42
|
-
|
|
43
|
-
// Parse integer-part, the leading (+ | - | . | 0-9)
|
|
44
|
-
while (!this.bytes.done()) {
|
|
45
|
-
const byte = this.bytes.peek();
|
|
46
|
-
if (!IsNumeric[byte]) break;
|
|
47
|
-
value += charFromCode(this.bytes.next());
|
|
48
|
-
if (byte === CharCodes.Period) break;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Parse decimal-part, the trailing (0-9)
|
|
52
|
-
while (!this.bytes.done()) {
|
|
53
|
-
const byte = this.bytes.peek();
|
|
54
|
-
if (!IsDigit[byte]) break;
|
|
55
|
-
value += charFromCode(this.bytes.next());
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const numberValue = Number(value);
|
|
59
|
-
|
|
60
|
-
if (!value || !isFinite(numberValue)) {
|
|
61
|
-
throw new NumberParsingError(this.bytes.position(), value);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (numberValue > Number.MAX_SAFE_INTEGER) {
|
|
65
|
-
if (this.capNumbers) {
|
|
66
|
-
const msg = `Parsed number that is too large for some PDF readers: ${value}, using Number.MAX_SAFE_INTEGER instead.`;
|
|
67
|
-
console.warn(msg);
|
|
68
|
-
return Number.MAX_SAFE_INTEGER;
|
|
69
|
-
} else {
|
|
70
|
-
const msg = `Parsed number that is too large for some PDF readers: ${value}, not capping.`;
|
|
71
|
-
console.warn(msg);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return numberValue;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
protected skipWhitespace(): void {
|
|
79
|
-
while (!this.bytes.done() && IsWhitespace[this.bytes.peek()]) {
|
|
80
|
-
this.bytes.next();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
protected skipLine(): void {
|
|
85
|
-
while (!this.bytes.done()) {
|
|
86
|
-
const byte = this.bytes.peek();
|
|
87
|
-
if (byte === Newline || byte === CarriageReturn) return;
|
|
88
|
-
this.bytes.next();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
protected skipComment(): boolean {
|
|
93
|
-
if (this.bytes.peek() !== CharCodes.Percent) return false;
|
|
94
|
-
while (!this.bytes.done()) {
|
|
95
|
-
const byte = this.bytes.peek();
|
|
96
|
-
if (byte === Newline || byte === CarriageReturn) return true;
|
|
97
|
-
this.bytes.next();
|
|
98
|
-
}
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
protected skipWhitespaceAndComments(): void {
|
|
103
|
-
this.skipWhitespace();
|
|
104
|
-
while (this.skipComment()) this.skipWhitespace();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
protected matchKeyword(keyword: number[]): boolean {
|
|
108
|
-
const initialOffset = this.bytes.offset();
|
|
109
|
-
for (let idx = 0, len = keyword.length; idx < len; idx++) {
|
|
110
|
-
if (this.bytes.done() || this.bytes.next() !== keyword[idx]) {
|
|
111
|
-
this.bytes.moveTo(initialOffset);
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export default BaseParser;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { NextByteAssertionError } from '../errors';
|
|
2
|
-
import PDFRawStream from '../objects/PDFRawStream';
|
|
3
|
-
import { decodePDFRawStream } from '../streams/decode';
|
|
4
|
-
import CharCodes from '../syntax/CharCodes';
|
|
5
|
-
|
|
6
|
-
// TODO: See how line/col tracking affects performance
|
|
7
|
-
class ByteStream {
|
|
8
|
-
static of = (bytes: Uint8Array) => new ByteStream(bytes);
|
|
9
|
-
|
|
10
|
-
static fromPDFRawStream = (rawStream: PDFRawStream) =>
|
|
11
|
-
ByteStream.of(decodePDFRawStream(rawStream).decode());
|
|
12
|
-
|
|
13
|
-
private readonly bytes: Uint8Array;
|
|
14
|
-
private readonly length: number;
|
|
15
|
-
|
|
16
|
-
private idx = 0;
|
|
17
|
-
private line = 0;
|
|
18
|
-
private column = 0;
|
|
19
|
-
|
|
20
|
-
constructor(bytes: Uint8Array) {
|
|
21
|
-
this.bytes = bytes;
|
|
22
|
-
this.length = this.bytes.length;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
moveTo(offset: number): void {
|
|
26
|
-
this.idx = offset;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
next(): number {
|
|
30
|
-
const byte = this.bytes[this.idx++];
|
|
31
|
-
if (byte === CharCodes.Newline) {
|
|
32
|
-
this.line += 1;
|
|
33
|
-
this.column = 0;
|
|
34
|
-
} else {
|
|
35
|
-
this.column += 1;
|
|
36
|
-
}
|
|
37
|
-
return byte;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
assertNext(expected: number): number {
|
|
41
|
-
if (this.peek() !== expected) {
|
|
42
|
-
throw new NextByteAssertionError(this.position(), expected, this.peek());
|
|
43
|
-
}
|
|
44
|
-
return this.next();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
peek(): number {
|
|
48
|
-
return this.bytes[this.idx];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
peekAhead(steps: number) {
|
|
52
|
-
return this.bytes[this.idx + steps];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
peekAt(offset: number) {
|
|
56
|
-
return this.bytes[offset];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
done(): boolean {
|
|
60
|
-
return this.idx >= this.length;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
offset(): number {
|
|
64
|
-
return this.idx;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
slice(start: number, end: number): Uint8Array {
|
|
68
|
-
return this.bytes.slice(start, end);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
position(): { line: number; column: number; offset: number } {
|
|
72
|
-
return { line: this.line, column: this.column, offset: this.idx };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export default ByteStream;
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PDFObjectParsingError,
|
|
3
|
-
PDFStreamParsingError,
|
|
4
|
-
Position,
|
|
5
|
-
UnbalancedParenthesisError,
|
|
6
|
-
} from '../errors';
|
|
7
|
-
import PDFArray from '../objects/PDFArray';
|
|
8
|
-
import PDFBool from '../objects/PDFBool';
|
|
9
|
-
import PDFDict, { DictMap } from '../objects/PDFDict';
|
|
10
|
-
import PDFHexString from '../objects/PDFHexString';
|
|
11
|
-
import PDFName from '../objects/PDFName';
|
|
12
|
-
import PDFNull from '../objects/PDFNull';
|
|
13
|
-
import PDFNumber from '../objects/PDFNumber';
|
|
14
|
-
import PDFObject from '../objects/PDFObject';
|
|
15
|
-
import PDFRawStream from '../objects/PDFRawStream';
|
|
16
|
-
import PDFRef from '../objects/PDFRef';
|
|
17
|
-
import PDFStream from '../objects/PDFStream';
|
|
18
|
-
import PDFString from '../objects/PDFString';
|
|
19
|
-
import BaseParser from './BaseParser';
|
|
20
|
-
import ByteStream from './ByteStream';
|
|
21
|
-
import PDFContext from '../PDFContext';
|
|
22
|
-
import PDFCatalog from '../structures/PDFCatalog';
|
|
23
|
-
import PDFPageLeaf from '../structures/PDFPageLeaf';
|
|
24
|
-
import PDFPageTree from '../structures/PDFPageTree';
|
|
25
|
-
import CharCodes from '../syntax/CharCodes';
|
|
26
|
-
import { IsDelimiter } from '../syntax/Delimiters';
|
|
27
|
-
import { Keywords } from '../syntax/Keywords';
|
|
28
|
-
import { IsDigit, IsNumeric } from '../syntax/Numeric';
|
|
29
|
-
import { IsWhitespace } from '../syntax/Whitespace';
|
|
30
|
-
import { charFromCode } from '../../utils';
|
|
31
|
-
import { CipherTransformFactory } from '../crypto';
|
|
32
|
-
|
|
33
|
-
// TODO: Throw error if eof is reached before finishing object parse...
|
|
34
|
-
class PDFObjectParser extends BaseParser {
|
|
35
|
-
static forBytes = (bytes: Uint8Array, context: PDFContext, capNumbers?: boolean) =>
|
|
36
|
-
new PDFObjectParser(ByteStream.of(bytes), context, capNumbers);
|
|
37
|
-
|
|
38
|
-
static forByteStream = (byteStream: ByteStream, context: PDFContext, capNumbers = false) =>
|
|
39
|
-
new PDFObjectParser(byteStream, context, capNumbers);
|
|
40
|
-
|
|
41
|
-
protected readonly context: PDFContext;
|
|
42
|
-
private readonly cryptoFactory?: CipherTransformFactory;
|
|
43
|
-
|
|
44
|
-
constructor(
|
|
45
|
-
byteStream: ByteStream,
|
|
46
|
-
context: PDFContext,
|
|
47
|
-
capNumbers = false,
|
|
48
|
-
cryptoFactory?: CipherTransformFactory,
|
|
49
|
-
) {
|
|
50
|
-
super(byteStream, capNumbers);
|
|
51
|
-
this.context = context;
|
|
52
|
-
this.cryptoFactory = cryptoFactory;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// TODO: Is it possible to reduce duplicate parsing for ref lookaheads?
|
|
56
|
-
parseObject(ref?: PDFRef): PDFObject {
|
|
57
|
-
this.skipWhitespaceAndComments();
|
|
58
|
-
|
|
59
|
-
if (this.matchKeyword(Keywords.true)) return PDFBool.True;
|
|
60
|
-
if (this.matchKeyword(Keywords.false)) return PDFBool.False;
|
|
61
|
-
if (this.matchKeyword(Keywords.null)) return PDFNull;
|
|
62
|
-
|
|
63
|
-
const byte = this.bytes.peek();
|
|
64
|
-
|
|
65
|
-
if (byte === CharCodes.LessThan && this.bytes.peekAhead(1) === CharCodes.LessThan) {
|
|
66
|
-
return this.parseDictOrStream(ref);
|
|
67
|
-
}
|
|
68
|
-
if (byte === CharCodes.LessThan) return this.parseHexString(ref);
|
|
69
|
-
if (byte === CharCodes.LeftParen) return this.parseString(ref);
|
|
70
|
-
if (byte === CharCodes.ForwardSlash) return this.parseName();
|
|
71
|
-
if (byte === CharCodes.LeftSquareBracket) return this.parseArray(ref);
|
|
72
|
-
if (IsNumeric[byte]) return this.parseNumberOrRef();
|
|
73
|
-
|
|
74
|
-
throw new PDFObjectParsingError(this.bytes.position(), byte);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
protected parseNumberOrRef(): PDFNumber | PDFRef {
|
|
78
|
-
const firstNum = this.parseRawNumber();
|
|
79
|
-
this.skipWhitespaceAndComments();
|
|
80
|
-
|
|
81
|
-
const lookaheadStart = this.bytes.offset();
|
|
82
|
-
if (IsDigit[this.bytes.peek()]) {
|
|
83
|
-
const secondNum = this.parseRawNumber();
|
|
84
|
-
this.skipWhitespaceAndComments();
|
|
85
|
-
if (this.bytes.peek() === CharCodes.R) {
|
|
86
|
-
this.bytes.assertNext(CharCodes.R);
|
|
87
|
-
return PDFRef.of(firstNum, secondNum);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
this.bytes.moveTo(lookaheadStart);
|
|
92
|
-
return PDFNumber.of(firstNum);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// TODO: Maybe update PDFHexString.of() logic to remove whitespace and validate input?
|
|
96
|
-
protected parseHexString(ref?: PDFRef): PDFHexString {
|
|
97
|
-
let value = '';
|
|
98
|
-
|
|
99
|
-
this.bytes.assertNext(CharCodes.LessThan);
|
|
100
|
-
while (!this.bytes.done() && this.bytes.peek() !== CharCodes.GreaterThan) {
|
|
101
|
-
value += charFromCode(this.bytes.next());
|
|
102
|
-
}
|
|
103
|
-
this.bytes.assertNext(CharCodes.GreaterThan);
|
|
104
|
-
|
|
105
|
-
if (this.cryptoFactory && ref) {
|
|
106
|
-
const transformer = this.cryptoFactory.createCipherTransform(
|
|
107
|
-
ref.objectNumber,
|
|
108
|
-
ref.generationNumber,
|
|
109
|
-
);
|
|
110
|
-
const arr = transformer.decryptBytes(PDFHexString.of(value).asBytes());
|
|
111
|
-
value = arr.reduce(
|
|
112
|
-
(str: string, byte: number) => str + byte.toString(16).padStart(2, '0'),
|
|
113
|
-
'',
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return PDFHexString.of(value);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
protected parseString(ref?: PDFRef): PDFString {
|
|
121
|
-
let nestingLvl = 0;
|
|
122
|
-
let isEscaped = false;
|
|
123
|
-
let value = '';
|
|
124
|
-
|
|
125
|
-
while (!this.bytes.done()) {
|
|
126
|
-
const byte = this.bytes.next();
|
|
127
|
-
value += charFromCode(byte);
|
|
128
|
-
|
|
129
|
-
// Check for unescaped parenthesis
|
|
130
|
-
if (!isEscaped) {
|
|
131
|
-
if (byte === CharCodes.LeftParen) nestingLvl += 1;
|
|
132
|
-
if (byte === CharCodes.RightParen) nestingLvl -= 1;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Track whether current character is being escaped or not
|
|
136
|
-
if (byte === CharCodes.BackSlash) {
|
|
137
|
-
isEscaped = !isEscaped;
|
|
138
|
-
} else if (isEscaped) {
|
|
139
|
-
isEscaped = false;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Once (if) the unescaped parenthesis balance out, return their contents
|
|
143
|
-
if (nestingLvl === 0) {
|
|
144
|
-
let actualValue = value.substring(1, value.length - 1);
|
|
145
|
-
|
|
146
|
-
if (this.cryptoFactory && ref) {
|
|
147
|
-
const transformer = this.cryptoFactory.createCipherTransform(
|
|
148
|
-
ref.objectNumber,
|
|
149
|
-
ref.generationNumber,
|
|
150
|
-
);
|
|
151
|
-
actualValue = transformer.decryptString(actualValue);
|
|
152
|
-
}
|
|
153
|
-
// Remove the outer parens so they aren't part of the contents
|
|
154
|
-
return PDFString.of(actualValue);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
throw new UnbalancedParenthesisError(this.bytes.position());
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// TODO: Compare performance of string concatenation to charFromCode(...bytes)
|
|
162
|
-
// TODO: Maybe preallocate small Uint8Array if can use charFromCode?
|
|
163
|
-
protected parseName(): PDFName {
|
|
164
|
-
this.bytes.assertNext(CharCodes.ForwardSlash);
|
|
165
|
-
|
|
166
|
-
let name = '';
|
|
167
|
-
while (!this.bytes.done()) {
|
|
168
|
-
const byte = this.bytes.peek();
|
|
169
|
-
if (IsWhitespace[byte] || IsDelimiter[byte]) break;
|
|
170
|
-
name += charFromCode(byte);
|
|
171
|
-
this.bytes.next();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return PDFName.of(name);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
protected parseArray(ref?: PDFRef): PDFArray {
|
|
178
|
-
this.bytes.assertNext(CharCodes.LeftSquareBracket);
|
|
179
|
-
this.skipWhitespaceAndComments();
|
|
180
|
-
|
|
181
|
-
const pdfArray = PDFArray.withContext(this.context);
|
|
182
|
-
while (this.bytes.peek() !== CharCodes.RightSquareBracket) {
|
|
183
|
-
const element = this.parseObject(ref);
|
|
184
|
-
pdfArray.push(element);
|
|
185
|
-
this.skipWhitespaceAndComments();
|
|
186
|
-
}
|
|
187
|
-
this.bytes.assertNext(CharCodes.RightSquareBracket);
|
|
188
|
-
return pdfArray;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
protected parseDict(ref?: PDFRef): PDFDict {
|
|
192
|
-
this.bytes.assertNext(CharCodes.LessThan);
|
|
193
|
-
this.bytes.assertNext(CharCodes.LessThan);
|
|
194
|
-
this.skipWhitespaceAndComments();
|
|
195
|
-
|
|
196
|
-
const dict: DictMap = new Map();
|
|
197
|
-
|
|
198
|
-
while (
|
|
199
|
-
!this.bytes.done() &&
|
|
200
|
-
this.bytes.peek() !== CharCodes.GreaterThan &&
|
|
201
|
-
this.bytes.peekAhead(1) !== CharCodes.GreaterThan
|
|
202
|
-
) {
|
|
203
|
-
const key = this.parseName();
|
|
204
|
-
const value = this.parseObject(ref);
|
|
205
|
-
dict.set(key, value);
|
|
206
|
-
this.skipWhitespaceAndComments();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this.skipWhitespaceAndComments();
|
|
210
|
-
this.bytes.assertNext(CharCodes.GreaterThan);
|
|
211
|
-
this.bytes.assertNext(CharCodes.GreaterThan);
|
|
212
|
-
|
|
213
|
-
const Type = dict.get(PDFName.of('Type'));
|
|
214
|
-
|
|
215
|
-
if (Type === PDFName.of('Catalog')) {
|
|
216
|
-
return PDFCatalog.fromMapWithContext(dict, this.context);
|
|
217
|
-
} else if (Type === PDFName.of('Pages')) {
|
|
218
|
-
return PDFPageTree.fromMapWithContext(dict, this.context);
|
|
219
|
-
} else if (Type === PDFName.of('Page')) {
|
|
220
|
-
return PDFPageLeaf.fromMapWithContext(dict, this.context);
|
|
221
|
-
} else {
|
|
222
|
-
return PDFDict.fromMapWithContext(dict, this.context);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
protected parseDictOrStream(ref?: PDFRef): PDFDict | PDFStream {
|
|
227
|
-
const startPos = this.bytes.position();
|
|
228
|
-
|
|
229
|
-
const dict = this.parseDict(ref);
|
|
230
|
-
|
|
231
|
-
this.skipWhitespaceAndComments();
|
|
232
|
-
|
|
233
|
-
if (
|
|
234
|
-
!this.matchKeyword(Keywords.streamEOF1) &&
|
|
235
|
-
!this.matchKeyword(Keywords.streamEOF2) &&
|
|
236
|
-
!this.matchKeyword(Keywords.streamEOF3) &&
|
|
237
|
-
!this.matchKeyword(Keywords.streamEOF4) &&
|
|
238
|
-
!this.matchKeyword(Keywords.stream)
|
|
239
|
-
) {
|
|
240
|
-
return dict;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const start = this.bytes.offset();
|
|
244
|
-
let end: number;
|
|
245
|
-
|
|
246
|
-
const Length = dict.get(PDFName.of('Length'));
|
|
247
|
-
if (Length instanceof PDFNumber) {
|
|
248
|
-
end = start + Length.asNumber();
|
|
249
|
-
this.bytes.moveTo(end);
|
|
250
|
-
this.skipWhitespaceAndComments();
|
|
251
|
-
if (!this.matchKeyword(Keywords.endstream)) {
|
|
252
|
-
this.bytes.moveTo(start);
|
|
253
|
-
end = this.findEndOfStreamFallback(startPos);
|
|
254
|
-
}
|
|
255
|
-
} else {
|
|
256
|
-
end = this.findEndOfStreamFallback(startPos);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
let contents = this.bytes.slice(start, end);
|
|
260
|
-
|
|
261
|
-
if (this.cryptoFactory && ref) {
|
|
262
|
-
const transform = this.cryptoFactory.createCipherTransform(
|
|
263
|
-
ref.objectNumber,
|
|
264
|
-
ref.generationNumber,
|
|
265
|
-
);
|
|
266
|
-
contents = transform.decryptBytes(contents);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return PDFRawStream.of(dict, contents);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
protected findEndOfStreamFallback(startPos: Position) {
|
|
273
|
-
// Move to end of stream, while handling nested streams
|
|
274
|
-
let nestingLvl = 1;
|
|
275
|
-
let end = this.bytes.offset();
|
|
276
|
-
|
|
277
|
-
while (!this.bytes.done()) {
|
|
278
|
-
end = this.bytes.offset();
|
|
279
|
-
|
|
280
|
-
if (this.matchKeyword(Keywords.stream)) {
|
|
281
|
-
nestingLvl += 1;
|
|
282
|
-
} else if (
|
|
283
|
-
this.matchKeyword(Keywords.EOF1endstream) ||
|
|
284
|
-
this.matchKeyword(Keywords.EOF2endstream) ||
|
|
285
|
-
this.matchKeyword(Keywords.EOF3endstream) ||
|
|
286
|
-
this.matchKeyword(Keywords.endstream)
|
|
287
|
-
) {
|
|
288
|
-
nestingLvl -= 1;
|
|
289
|
-
} else {
|
|
290
|
-
this.bytes.next();
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (nestingLvl === 0) break;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (nestingLvl !== 0) throw new PDFStreamParsingError(startPos);
|
|
297
|
-
|
|
298
|
-
return end;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export default PDFObjectParser;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { ReparseError } from '../errors';
|
|
2
|
-
import PDFName from '../objects/PDFName';
|
|
3
|
-
import PDFNumber from '../objects/PDFNumber';
|
|
4
|
-
import PDFRawStream from '../objects/PDFRawStream';
|
|
5
|
-
import PDFRef from '../objects/PDFRef';
|
|
6
|
-
import ByteStream from './ByteStream';
|
|
7
|
-
import PDFObjectParser from './PDFObjectParser';
|
|
8
|
-
import { waitForTick } from '../../utils';
|
|
9
|
-
|
|
10
|
-
class PDFObjectStreamParser extends PDFObjectParser {
|
|
11
|
-
static forStream = (rawStream: PDFRawStream, shouldWaitForTick?: () => boolean) =>
|
|
12
|
-
new PDFObjectStreamParser(rawStream, shouldWaitForTick);
|
|
13
|
-
|
|
14
|
-
private alreadyParsed: boolean;
|
|
15
|
-
private readonly shouldWaitForTick: () => boolean;
|
|
16
|
-
private readonly firstOffset: number;
|
|
17
|
-
private readonly objectCount: number;
|
|
18
|
-
|
|
19
|
-
constructor(rawStream: PDFRawStream, shouldWaitForTick?: () => boolean) {
|
|
20
|
-
super(ByteStream.fromPDFRawStream(rawStream), rawStream.dict.context);
|
|
21
|
-
|
|
22
|
-
const { dict } = rawStream;
|
|
23
|
-
|
|
24
|
-
this.alreadyParsed = false;
|
|
25
|
-
this.shouldWaitForTick = shouldWaitForTick || (() => false);
|
|
26
|
-
this.firstOffset = dict.lookup(PDFName.of('First'), PDFNumber).asNumber();
|
|
27
|
-
this.objectCount = dict.lookup(PDFName.of('N'), PDFNumber).asNumber();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async parseIntoContext(): Promise<void> {
|
|
31
|
-
if (this.alreadyParsed) {
|
|
32
|
-
throw new ReparseError('PDFObjectStreamParser', 'parseIntoContext');
|
|
33
|
-
}
|
|
34
|
-
this.alreadyParsed = true;
|
|
35
|
-
|
|
36
|
-
const offsetsAndObjectNumbers = this.parseOffsetsAndObjectNumbers();
|
|
37
|
-
for (let idx = 0, len = offsetsAndObjectNumbers.length; idx < len; idx++) {
|
|
38
|
-
const { objectNumber, offset } = offsetsAndObjectNumbers[idx];
|
|
39
|
-
this.bytes.moveTo(this.firstOffset + offset);
|
|
40
|
-
const ref = PDFRef.of(objectNumber, 0);
|
|
41
|
-
const object = this.parseObject(ref);
|
|
42
|
-
this.context.assign(ref, object);
|
|
43
|
-
if (this.shouldWaitForTick()) await waitForTick();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private parseOffsetsAndObjectNumbers(): {
|
|
48
|
-
objectNumber: number;
|
|
49
|
-
offset: number;
|
|
50
|
-
}[] {
|
|
51
|
-
const offsetsAndObjectNumbers = [];
|
|
52
|
-
for (let idx = 0, len = this.objectCount; idx < len; idx++) {
|
|
53
|
-
this.skipWhitespaceAndComments();
|
|
54
|
-
const objectNumber = this.parseRawInt();
|
|
55
|
-
|
|
56
|
-
this.skipWhitespaceAndComments();
|
|
57
|
-
const offset = this.parseRawInt();
|
|
58
|
-
|
|
59
|
-
offsetsAndObjectNumbers.push({ objectNumber, offset });
|
|
60
|
-
}
|
|
61
|
-
return offsetsAndObjectNumbers;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default PDFObjectStreamParser;
|