@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,363 +0,0 @@
|
|
|
1
|
-
import PDFCrossRefSection from '../document/PDFCrossRefSection';
|
|
2
|
-
import PDFHeader from '../document/PDFHeader';
|
|
3
|
-
import PDFTrailer from '../document/PDFTrailer';
|
|
4
|
-
import {
|
|
5
|
-
MissingKeywordError,
|
|
6
|
-
MissingPDFHeaderError,
|
|
7
|
-
PDFInvalidObjectParsingError,
|
|
8
|
-
ReparseError,
|
|
9
|
-
StalledParserError,
|
|
10
|
-
} from '../errors';
|
|
11
|
-
import PDFDict from '../objects/PDFDict';
|
|
12
|
-
import PDFInvalidObject from '../objects/PDFInvalidObject';
|
|
13
|
-
import PDFName from '../objects/PDFName';
|
|
14
|
-
import PDFObject from '../objects/PDFObject';
|
|
15
|
-
import PDFRawStream from '../objects/PDFRawStream';
|
|
16
|
-
import PDFRef from '../objects/PDFRef';
|
|
17
|
-
import ByteStream from './ByteStream';
|
|
18
|
-
import PDFObjectParser from './PDFObjectParser';
|
|
19
|
-
import PDFObjectStreamParser from './PDFObjectStreamParser';
|
|
20
|
-
import PDFXRefStreamParser from './PDFXRefStreamParser';
|
|
21
|
-
import PDFContext from '../PDFContext';
|
|
22
|
-
import CharCodes from '../syntax/CharCodes';
|
|
23
|
-
import { Keywords } from '../syntax/Keywords';
|
|
24
|
-
import { IsDigit } from '../syntax/Numeric';
|
|
25
|
-
import { waitForTick } from '../../utils';
|
|
26
|
-
import { CipherTransformFactory } from '../crypto';
|
|
27
|
-
|
|
28
|
-
class PDFParser extends PDFObjectParser {
|
|
29
|
-
static forBytesWithOptions = (
|
|
30
|
-
pdfBytes: Uint8Array,
|
|
31
|
-
objectsPerTick?: number,
|
|
32
|
-
throwOnInvalidObject?: boolean,
|
|
33
|
-
capNumbers?: boolean,
|
|
34
|
-
cryptoFactory?: CipherTransformFactory,
|
|
35
|
-
) => new PDFParser(pdfBytes, objectsPerTick, throwOnInvalidObject, capNumbers, cryptoFactory);
|
|
36
|
-
|
|
37
|
-
private readonly objectsPerTick: number;
|
|
38
|
-
private readonly throwOnInvalidObject: boolean;
|
|
39
|
-
private alreadyParsed = false;
|
|
40
|
-
private parsedObjects = 0;
|
|
41
|
-
|
|
42
|
-
constructor(
|
|
43
|
-
pdfBytes: Uint8Array,
|
|
44
|
-
objectsPerTick = Infinity,
|
|
45
|
-
throwOnInvalidObject = false,
|
|
46
|
-
capNumbers = false,
|
|
47
|
-
cryptoFactory?: CipherTransformFactory,
|
|
48
|
-
) {
|
|
49
|
-
super(ByteStream.of(pdfBytes), PDFContext.create(), capNumbers, cryptoFactory);
|
|
50
|
-
this.objectsPerTick = objectsPerTick;
|
|
51
|
-
this.throwOnInvalidObject = throwOnInvalidObject;
|
|
52
|
-
this.context.isDecrypted = !!cryptoFactory?.encryptionKey;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async parseDocument(): Promise<PDFContext> {
|
|
56
|
-
if (this.alreadyParsed) {
|
|
57
|
-
throw new ReparseError('PDFParser', 'parseDocument');
|
|
58
|
-
}
|
|
59
|
-
this.alreadyParsed = true;
|
|
60
|
-
|
|
61
|
-
this.context.header = this.parseHeader();
|
|
62
|
-
|
|
63
|
-
let prevOffset;
|
|
64
|
-
while (!this.bytes.done()) {
|
|
65
|
-
await this.parseDocumentSection();
|
|
66
|
-
const offset = this.bytes.offset();
|
|
67
|
-
if (offset === prevOffset) {
|
|
68
|
-
throw new StalledParserError(this.bytes.position());
|
|
69
|
-
}
|
|
70
|
-
prevOffset = offset;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.maybeRecoverRoot();
|
|
74
|
-
|
|
75
|
-
if (this.context.lookup(PDFRef.of(0))) {
|
|
76
|
-
console.warn('Removing parsed object: 0 0 R');
|
|
77
|
-
this.context.delete(PDFRef.of(0));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return this.context;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private maybeRecoverRoot(): void {
|
|
84
|
-
const isValidCatalog = (obj?: PDFObject) =>
|
|
85
|
-
obj instanceof PDFDict && obj.lookup(PDFName.of('Type')) === PDFName.of('Catalog');
|
|
86
|
-
|
|
87
|
-
const catalog = this.context.lookup(this.context.trailerInfo.Root);
|
|
88
|
-
|
|
89
|
-
if (!isValidCatalog(catalog)) {
|
|
90
|
-
const indirectObjects = this.context.enumerateIndirectObjects();
|
|
91
|
-
for (let idx = 0, len = indirectObjects.length; idx < len; idx++) {
|
|
92
|
-
const [ref, object] = indirectObjects[idx];
|
|
93
|
-
if (isValidCatalog(object)) {
|
|
94
|
-
this.context.trailerInfo.Root = ref;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private parseHeader(): PDFHeader {
|
|
101
|
-
while (!this.bytes.done()) {
|
|
102
|
-
if (this.matchKeyword(Keywords.header)) {
|
|
103
|
-
const major = this.parseRawInt();
|
|
104
|
-
this.bytes.assertNext(CharCodes.Period);
|
|
105
|
-
const minor = this.parseRawInt();
|
|
106
|
-
const header = PDFHeader.forVersion(major, minor);
|
|
107
|
-
this.skipBinaryHeaderComment();
|
|
108
|
-
return header;
|
|
109
|
-
}
|
|
110
|
-
this.bytes.next();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
throw new MissingPDFHeaderError(this.bytes.position());
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private parseIndirectObjectHeader(): PDFRef {
|
|
117
|
-
this.skipWhitespaceAndComments();
|
|
118
|
-
const objectNumber = this.parseRawInt();
|
|
119
|
-
|
|
120
|
-
this.skipWhitespaceAndComments();
|
|
121
|
-
const generationNumber = this.parseRawInt();
|
|
122
|
-
|
|
123
|
-
this.skipWhitespaceAndComments();
|
|
124
|
-
if (!this.matchKeyword(Keywords.obj)) {
|
|
125
|
-
throw new MissingKeywordError(this.bytes.position(), Keywords.obj);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return PDFRef.of(objectNumber, generationNumber);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private matchIndirectObjectHeader(): boolean {
|
|
132
|
-
const initialOffset = this.bytes.offset();
|
|
133
|
-
try {
|
|
134
|
-
this.parseIndirectObjectHeader();
|
|
135
|
-
return true;
|
|
136
|
-
} catch {
|
|
137
|
-
this.bytes.moveTo(initialOffset);
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
private shouldWaitForTick = () => {
|
|
143
|
-
this.parsedObjects += 1;
|
|
144
|
-
return this.parsedObjects % this.objectsPerTick === 0;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
private async parseIndirectObject(): Promise<PDFRef> {
|
|
148
|
-
const ref = this.parseIndirectObjectHeader();
|
|
149
|
-
|
|
150
|
-
this.skipWhitespaceAndComments();
|
|
151
|
-
const object = this.parseObject(ref);
|
|
152
|
-
|
|
153
|
-
this.skipWhitespaceAndComments();
|
|
154
|
-
// if (!this.matchKeyword(Keywords.endobj)) {
|
|
155
|
-
// throw new MissingKeywordError(this.bytes.position(), Keywords.endobj);
|
|
156
|
-
// }
|
|
157
|
-
|
|
158
|
-
// TODO: Log a warning if this fails...
|
|
159
|
-
this.matchKeyword(Keywords.endobj);
|
|
160
|
-
|
|
161
|
-
if (
|
|
162
|
-
object instanceof PDFRawStream &&
|
|
163
|
-
object.dict.lookup(PDFName.of('Type')) === PDFName.of('ObjStm')
|
|
164
|
-
) {
|
|
165
|
-
await PDFObjectStreamParser.forStream(object, this.shouldWaitForTick).parseIntoContext();
|
|
166
|
-
} else if (
|
|
167
|
-
object instanceof PDFRawStream &&
|
|
168
|
-
object.dict.lookup(PDFName.of('Type')) === PDFName.of('XRef')
|
|
169
|
-
) {
|
|
170
|
-
PDFXRefStreamParser.forStream(object).parseIntoContext();
|
|
171
|
-
} else {
|
|
172
|
-
this.context.assign(ref, object);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return ref;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// TODO: Improve and clean this up
|
|
179
|
-
private tryToParseInvalidIndirectObject() {
|
|
180
|
-
const startPos = this.bytes.position();
|
|
181
|
-
|
|
182
|
-
const msg = `Trying to parse invalid object: ${JSON.stringify(startPos)})`;
|
|
183
|
-
if (this.throwOnInvalidObject) throw new Error(msg);
|
|
184
|
-
console.warn(msg);
|
|
185
|
-
|
|
186
|
-
const ref = this.parseIndirectObjectHeader();
|
|
187
|
-
|
|
188
|
-
console.warn(`Invalid object ref: ${ref}`);
|
|
189
|
-
|
|
190
|
-
this.skipWhitespaceAndComments();
|
|
191
|
-
const start = this.bytes.offset();
|
|
192
|
-
|
|
193
|
-
let failed = true;
|
|
194
|
-
while (!this.bytes.done()) {
|
|
195
|
-
if (this.matchKeyword(Keywords.endobj)) {
|
|
196
|
-
failed = false;
|
|
197
|
-
}
|
|
198
|
-
if (!failed) break;
|
|
199
|
-
this.bytes.next();
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (failed) throw new PDFInvalidObjectParsingError(startPos);
|
|
203
|
-
|
|
204
|
-
const end = this.bytes.offset() - Keywords.endobj.length;
|
|
205
|
-
|
|
206
|
-
const object = PDFInvalidObject.of(this.bytes.slice(start, end));
|
|
207
|
-
this.context.assign(ref, object);
|
|
208
|
-
|
|
209
|
-
return ref;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
private async parseIndirectObjects(): Promise<void> {
|
|
213
|
-
this.skipWhitespaceAndComments();
|
|
214
|
-
|
|
215
|
-
while (!this.bytes.done() && IsDigit[this.bytes.peek()]) {
|
|
216
|
-
const initialOffset = this.bytes.offset();
|
|
217
|
-
|
|
218
|
-
try {
|
|
219
|
-
await this.parseIndirectObject();
|
|
220
|
-
} catch {
|
|
221
|
-
// TODO: Add tracing/logging mechanism to track when this happens!
|
|
222
|
-
this.bytes.moveTo(initialOffset);
|
|
223
|
-
this.tryToParseInvalidIndirectObject();
|
|
224
|
-
}
|
|
225
|
-
this.skipWhitespaceAndComments();
|
|
226
|
-
|
|
227
|
-
// TODO: Can this be done only when needed, to avoid harming performance?
|
|
228
|
-
this.skipJibberish();
|
|
229
|
-
|
|
230
|
-
if (this.shouldWaitForTick()) await waitForTick();
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
private maybeParseCrossRefSection(): PDFCrossRefSection | void {
|
|
235
|
-
this.skipWhitespaceAndComments();
|
|
236
|
-
if (!this.matchKeyword(Keywords.xref)) return;
|
|
237
|
-
this.skipWhitespaceAndComments();
|
|
238
|
-
|
|
239
|
-
let objectNumber = -1;
|
|
240
|
-
const xref = PDFCrossRefSection.createEmpty();
|
|
241
|
-
|
|
242
|
-
while (!this.bytes.done() && IsDigit[this.bytes.peek()]) {
|
|
243
|
-
const firstInt = this.parseRawInt();
|
|
244
|
-
this.skipWhitespaceAndComments();
|
|
245
|
-
|
|
246
|
-
const secondInt = this.parseRawInt();
|
|
247
|
-
this.skipWhitespaceAndComments();
|
|
248
|
-
|
|
249
|
-
const byte = this.bytes.peek();
|
|
250
|
-
if (byte === CharCodes.n || byte === CharCodes.f) {
|
|
251
|
-
const ref = PDFRef.of(objectNumber, secondInt);
|
|
252
|
-
if (this.bytes.next() === CharCodes.n) {
|
|
253
|
-
xref.addEntry(ref, firstInt);
|
|
254
|
-
} else {
|
|
255
|
-
// this.context.delete(ref);
|
|
256
|
-
xref.addDeletedEntry(ref, firstInt);
|
|
257
|
-
}
|
|
258
|
-
objectNumber += 1;
|
|
259
|
-
} else {
|
|
260
|
-
objectNumber = firstInt;
|
|
261
|
-
}
|
|
262
|
-
this.skipWhitespaceAndComments();
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return xref;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
private maybeParseTrailerDict(): void {
|
|
269
|
-
this.skipWhitespaceAndComments();
|
|
270
|
-
if (!this.matchKeyword(Keywords.trailer)) return;
|
|
271
|
-
this.skipWhitespaceAndComments();
|
|
272
|
-
|
|
273
|
-
const dict = this.parseDict();
|
|
274
|
-
|
|
275
|
-
const { context } = this;
|
|
276
|
-
context.trailerInfo = {
|
|
277
|
-
Root: dict.get(PDFName.of('Root')) || context.trailerInfo.Root,
|
|
278
|
-
Encrypt: dict.get(PDFName.of('Encrypt')) || context.trailerInfo.Encrypt,
|
|
279
|
-
Info: dict.get(PDFName.of('Info')) || context.trailerInfo.Info,
|
|
280
|
-
ID: dict.get(PDFName.of('ID')) || context.trailerInfo.ID,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
private maybeParseTrailer(): PDFTrailer | void {
|
|
285
|
-
this.skipWhitespaceAndComments();
|
|
286
|
-
if (!this.matchKeyword(Keywords.startxref)) return;
|
|
287
|
-
this.skipWhitespaceAndComments();
|
|
288
|
-
|
|
289
|
-
const offset = this.parseRawInt();
|
|
290
|
-
|
|
291
|
-
this.skipWhitespace();
|
|
292
|
-
this.matchKeyword(Keywords.eof);
|
|
293
|
-
this.skipWhitespaceAndComments();
|
|
294
|
-
this.matchKeyword(Keywords.eof);
|
|
295
|
-
this.skipWhitespaceAndComments();
|
|
296
|
-
|
|
297
|
-
return PDFTrailer.forLastCrossRefSectionOffset(offset);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
private async parseDocumentSection(): Promise<void> {
|
|
301
|
-
await this.parseIndirectObjects();
|
|
302
|
-
this.maybeParseCrossRefSection();
|
|
303
|
-
this.maybeParseTrailerDict();
|
|
304
|
-
this.maybeParseTrailer();
|
|
305
|
-
|
|
306
|
-
// TODO: Can this be done only when needed, to avoid harming performance?
|
|
307
|
-
this.skipJibberish();
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* This operation is not necessary for valid PDF files. But some invalid PDFs
|
|
312
|
-
* contain jibberish in between indirect objects. This method is designed to
|
|
313
|
-
* skip past that jibberish, should it exist, until it reaches the next
|
|
314
|
-
* indirect object header, an xref table section, or the file trailer.
|
|
315
|
-
*/
|
|
316
|
-
private skipJibberish(): void {
|
|
317
|
-
this.skipWhitespaceAndComments();
|
|
318
|
-
while (!this.bytes.done()) {
|
|
319
|
-
const initialOffset = this.bytes.offset();
|
|
320
|
-
const byte = this.bytes.peek();
|
|
321
|
-
const isAlphaNumeric = byte >= CharCodes.Space && byte <= CharCodes.Tilde;
|
|
322
|
-
if (isAlphaNumeric) {
|
|
323
|
-
if (
|
|
324
|
-
this.matchKeyword(Keywords.xref) ||
|
|
325
|
-
this.matchKeyword(Keywords.trailer) ||
|
|
326
|
-
this.matchKeyword(Keywords.startxref) ||
|
|
327
|
-
this.matchIndirectObjectHeader()
|
|
328
|
-
) {
|
|
329
|
-
this.bytes.moveTo(initialOffset);
|
|
330
|
-
break;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
this.bytes.next();
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Skips the binary comment following a PDF header. The specification
|
|
339
|
-
* defines this binary comment (section 7.5.2 File Header) as a sequence of 4
|
|
340
|
-
* or more bytes that are 128 or greater, and which are preceded by a "%".
|
|
341
|
-
*
|
|
342
|
-
* This would imply that to strip out this binary comment, we could check for
|
|
343
|
-
* a sequence of bytes starting with "%", and remove all subsequent bytes that
|
|
344
|
-
* are 128 or greater. This works for many documents that properly comply with
|
|
345
|
-
* the spec. But in the wild, there are PDFs that omit the leading "%", and
|
|
346
|
-
* include bytes that are less than 128 (e.g. 0 or 1). So in order to parse
|
|
347
|
-
* these headers correctly, we just throw out all bytes leading up to the
|
|
348
|
-
* first indirect object header.
|
|
349
|
-
*/
|
|
350
|
-
private skipBinaryHeaderComment(): void {
|
|
351
|
-
this.skipWhitespaceAndComments();
|
|
352
|
-
try {
|
|
353
|
-
const initialOffset = this.bytes.offset();
|
|
354
|
-
this.parseIndirectObjectHeader();
|
|
355
|
-
this.bytes.moveTo(initialOffset);
|
|
356
|
-
} catch {
|
|
357
|
-
this.bytes.next();
|
|
358
|
-
this.skipWhitespaceAndComments();
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export default PDFParser;
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { ReparseError } from '../errors';
|
|
2
|
-
import PDFArray from '../objects/PDFArray';
|
|
3
|
-
import PDFDict from '../objects/PDFDict';
|
|
4
|
-
import PDFName from '../objects/PDFName';
|
|
5
|
-
import PDFNumber from '../objects/PDFNumber';
|
|
6
|
-
import PDFRawStream from '../objects/PDFRawStream';
|
|
7
|
-
import PDFRef from '../objects/PDFRef';
|
|
8
|
-
import ByteStream from './ByteStream';
|
|
9
|
-
import PDFContext from '../PDFContext';
|
|
10
|
-
|
|
11
|
-
export interface Entry {
|
|
12
|
-
ref: PDFRef;
|
|
13
|
-
offset: number;
|
|
14
|
-
deleted: boolean;
|
|
15
|
-
inObjectStream: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
class PDFXRefStreamParser {
|
|
19
|
-
static forStream = (rawStream: PDFRawStream) => new PDFXRefStreamParser(rawStream);
|
|
20
|
-
|
|
21
|
-
private alreadyParsed: boolean;
|
|
22
|
-
|
|
23
|
-
private readonly dict: PDFDict;
|
|
24
|
-
private readonly context: PDFContext;
|
|
25
|
-
private readonly bytes: ByteStream;
|
|
26
|
-
private readonly subsections: {
|
|
27
|
-
firstObjectNumber: number;
|
|
28
|
-
length: number;
|
|
29
|
-
}[];
|
|
30
|
-
private readonly byteWidths: [number, number, number];
|
|
31
|
-
|
|
32
|
-
constructor(rawStream: PDFRawStream) {
|
|
33
|
-
this.alreadyParsed = false;
|
|
34
|
-
|
|
35
|
-
this.dict = rawStream.dict;
|
|
36
|
-
this.bytes = ByteStream.fromPDFRawStream(rawStream);
|
|
37
|
-
this.context = this.dict.context;
|
|
38
|
-
|
|
39
|
-
const Size = this.dict.lookup(PDFName.of('Size'), PDFNumber);
|
|
40
|
-
|
|
41
|
-
const Index = this.dict.lookup(PDFName.of('Index'));
|
|
42
|
-
if (Index instanceof PDFArray) {
|
|
43
|
-
this.subsections = [];
|
|
44
|
-
for (let idx = 0, len = Index.size(); idx < len; idx += 2) {
|
|
45
|
-
const firstObjectNumber = Index.lookup(idx + 0, PDFNumber).asNumber();
|
|
46
|
-
const length = Index.lookup(idx + 1, PDFNumber).asNumber();
|
|
47
|
-
this.subsections.push({ firstObjectNumber, length });
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
this.subsections = [{ firstObjectNumber: 0, length: Size.asNumber() }];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const W = this.dict.lookup(PDFName.of('W'), PDFArray);
|
|
54
|
-
this.byteWidths = [-1, -1, -1];
|
|
55
|
-
for (let idx = 0, len = W.size(); idx < len; idx++) {
|
|
56
|
-
this.byteWidths[idx] = W.lookup(idx, PDFNumber).asNumber();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
parseIntoContext(): Entry[] {
|
|
61
|
-
if (this.alreadyParsed) {
|
|
62
|
-
throw new ReparseError('PDFXRefStreamParser', 'parseIntoContext');
|
|
63
|
-
}
|
|
64
|
-
this.alreadyParsed = true;
|
|
65
|
-
|
|
66
|
-
this.context.trailerInfo = {
|
|
67
|
-
Root: this.dict.get(PDFName.of('Root')),
|
|
68
|
-
Encrypt: this.dict.get(PDFName.of('Encrypt')),
|
|
69
|
-
Info: this.dict.get(PDFName.of('Info')),
|
|
70
|
-
ID: this.dict.get(PDFName.of('ID')),
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const entries = this.parseEntries();
|
|
74
|
-
|
|
75
|
-
// for (let idx = 0, len = entries.length; idx < len; idx++) {
|
|
76
|
-
// const entry = entries[idx];
|
|
77
|
-
// if (entry.deleted) this.context.delete(entry.ref);
|
|
78
|
-
// }
|
|
79
|
-
|
|
80
|
-
return entries;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private parseEntries(): Entry[] {
|
|
84
|
-
const entries = [];
|
|
85
|
-
const [typeFieldWidth, offsetFieldWidth, genFieldWidth] = this.byteWidths;
|
|
86
|
-
|
|
87
|
-
for (
|
|
88
|
-
let subsectionIdx = 0, subsectionLen = this.subsections.length;
|
|
89
|
-
subsectionIdx < subsectionLen;
|
|
90
|
-
subsectionIdx++
|
|
91
|
-
) {
|
|
92
|
-
const { firstObjectNumber, length } = this.subsections[subsectionIdx];
|
|
93
|
-
|
|
94
|
-
for (let objIdx = 0; objIdx < length; objIdx++) {
|
|
95
|
-
let type = 0;
|
|
96
|
-
for (let idx = 0, len = typeFieldWidth; idx < len; idx++) {
|
|
97
|
-
type = (type << 8) | this.bytes.next();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
let offset = 0;
|
|
101
|
-
for (let idx = 0, len = offsetFieldWidth; idx < len; idx++) {
|
|
102
|
-
offset = (offset << 8) | this.bytes.next();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
let generationNumber = 0;
|
|
106
|
-
for (let idx = 0, len = genFieldWidth; idx < len; idx++) {
|
|
107
|
-
generationNumber = (generationNumber << 8) | this.bytes.next();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// When the `type` field is absent, it defaults to 1
|
|
111
|
-
if (typeFieldWidth === 0) type = 1;
|
|
112
|
-
|
|
113
|
-
const objectNumber = firstObjectNumber + objIdx;
|
|
114
|
-
const entry = {
|
|
115
|
-
ref: PDFRef.of(objectNumber, generationNumber),
|
|
116
|
-
offset,
|
|
117
|
-
deleted: type === 0,
|
|
118
|
-
inObjectStream: type === 2,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
entries.push(entry);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return entries;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export default PDFXRefStreamParser;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2012 Mozilla Foundation
|
|
3
|
-
*
|
|
4
|
-
* The Ascii85Stream class contained in this file is a TypeScript port of the
|
|
5
|
-
* JavaScript Ascii85Stream class in Mozilla's pdf.js project, made available
|
|
6
|
-
* under the Apache 2.0 open source license.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import DecodeStream from './DecodeStream';
|
|
10
|
-
import { StreamType } from './Stream';
|
|
11
|
-
|
|
12
|
-
const isSpace = (ch: number) => ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
|
|
13
|
-
|
|
14
|
-
class Ascii85Stream extends DecodeStream {
|
|
15
|
-
private stream: StreamType;
|
|
16
|
-
private input: Uint8Array;
|
|
17
|
-
|
|
18
|
-
constructor(stream: StreamType, maybeLength?: number) {
|
|
19
|
-
super(maybeLength);
|
|
20
|
-
|
|
21
|
-
this.stream = stream;
|
|
22
|
-
this.input = new Uint8Array(5);
|
|
23
|
-
|
|
24
|
-
// Most streams increase in size when decoded, but Ascii85 streams
|
|
25
|
-
// typically shrink by ~20%.
|
|
26
|
-
if (maybeLength) {
|
|
27
|
-
maybeLength = 0.8 * maybeLength;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
protected readBlock() {
|
|
32
|
-
const TILDA_CHAR = 0x7e; // '~'
|
|
33
|
-
const Z_LOWER_CHAR = 0x7a; // 'z'
|
|
34
|
-
const EOF = -1;
|
|
35
|
-
|
|
36
|
-
const stream = this.stream;
|
|
37
|
-
|
|
38
|
-
let c = stream.getByte();
|
|
39
|
-
while (isSpace(c)) {
|
|
40
|
-
c = stream.getByte();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (c === EOF || c === TILDA_CHAR) {
|
|
44
|
-
this.eof = true;
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const bufferLength = this.bufferLength;
|
|
49
|
-
let buffer;
|
|
50
|
-
let i;
|
|
51
|
-
|
|
52
|
-
// special code for z
|
|
53
|
-
if (c === Z_LOWER_CHAR) {
|
|
54
|
-
buffer = this.ensureBuffer(bufferLength + 4);
|
|
55
|
-
for (i = 0; i < 4; ++i) {
|
|
56
|
-
buffer[bufferLength + i] = 0;
|
|
57
|
-
}
|
|
58
|
-
this.bufferLength += 4;
|
|
59
|
-
} else {
|
|
60
|
-
const input = this.input;
|
|
61
|
-
input[0] = c;
|
|
62
|
-
for (i = 1; i < 5; ++i) {
|
|
63
|
-
c = stream.getByte();
|
|
64
|
-
while (isSpace(c)) {
|
|
65
|
-
c = stream.getByte();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
input[i] = c;
|
|
69
|
-
|
|
70
|
-
if (c === EOF || c === TILDA_CHAR) {
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
buffer = this.ensureBuffer(bufferLength + i - 1);
|
|
75
|
-
this.bufferLength += i - 1;
|
|
76
|
-
|
|
77
|
-
// partial ending;
|
|
78
|
-
if (i < 5) {
|
|
79
|
-
for (; i < 5; ++i) {
|
|
80
|
-
input[i] = 0x21 + 84;
|
|
81
|
-
}
|
|
82
|
-
this.eof = true;
|
|
83
|
-
}
|
|
84
|
-
let t = 0;
|
|
85
|
-
for (i = 0; i < 5; ++i) {
|
|
86
|
-
t = t * 85 + (input[i] - 0x21);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
for (i = 3; i >= 0; --i) {
|
|
90
|
-
buffer[bufferLength + i] = t & 0xff;
|
|
91
|
-
t >>= 8;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export default Ascii85Stream;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2012 Mozilla Foundation
|
|
3
|
-
*
|
|
4
|
-
* The AsciiHexStream class contained in this file is a TypeScript port of the
|
|
5
|
-
* JavaScript AsciiHexStream class in Mozilla's pdf.js project, made available
|
|
6
|
-
* under the Apache 2.0 open source license.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import DecodeStream from './DecodeStream';
|
|
10
|
-
import { StreamType } from './Stream';
|
|
11
|
-
|
|
12
|
-
class AsciiHexStream extends DecodeStream {
|
|
13
|
-
private stream: StreamType;
|
|
14
|
-
private firstDigit: number;
|
|
15
|
-
|
|
16
|
-
constructor(stream: StreamType, maybeLength?: number) {
|
|
17
|
-
super(maybeLength);
|
|
18
|
-
|
|
19
|
-
this.stream = stream;
|
|
20
|
-
|
|
21
|
-
this.firstDigit = -1;
|
|
22
|
-
|
|
23
|
-
// Most streams increase in size when decoded, but AsciiHex streams shrink
|
|
24
|
-
// by 50%.
|
|
25
|
-
if (maybeLength) {
|
|
26
|
-
maybeLength = 0.5 * maybeLength;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected readBlock() {
|
|
31
|
-
const UPSTREAM_BLOCK_SIZE = 8000;
|
|
32
|
-
const bytes = this.stream.getBytes(UPSTREAM_BLOCK_SIZE);
|
|
33
|
-
if (!bytes.length) {
|
|
34
|
-
this.eof = true;
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const maxDecodeLength = (bytes.length + 1) >> 1;
|
|
39
|
-
const buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
|
|
40
|
-
let bufferLength = this.bufferLength;
|
|
41
|
-
|
|
42
|
-
let firstDigit = this.firstDigit;
|
|
43
|
-
for (let i = 0, ii = bytes.length; i < ii; i++) {
|
|
44
|
-
const ch = bytes[i];
|
|
45
|
-
let digit;
|
|
46
|
-
if (ch >= 0x30 && ch <= 0x39) {
|
|
47
|
-
// '0'-'9'
|
|
48
|
-
digit = ch & 0x0f;
|
|
49
|
-
} else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
|
|
50
|
-
// 'A'-'Z', 'a'-'z'
|
|
51
|
-
digit = (ch & 0x0f) + 9;
|
|
52
|
-
} else if (ch === 0x3e) {
|
|
53
|
-
// '>'
|
|
54
|
-
this.eof = true;
|
|
55
|
-
break;
|
|
56
|
-
} else {
|
|
57
|
-
// probably whitespace
|
|
58
|
-
continue; // ignoring
|
|
59
|
-
}
|
|
60
|
-
if (firstDigit < 0) {
|
|
61
|
-
firstDigit = digit;
|
|
62
|
-
} else {
|
|
63
|
-
buffer[bufferLength++] = (firstDigit << 4) | digit;
|
|
64
|
-
firstDigit = -1;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (firstDigit >= 0 && this.eof) {
|
|
68
|
-
// incomplete byte
|
|
69
|
-
buffer[bufferLength++] = firstDigit << 4;
|
|
70
|
-
firstDigit = -1;
|
|
71
|
-
}
|
|
72
|
-
this.firstDigit = firstDigit;
|
|
73
|
-
this.bufferLength = bufferLength;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export default AsciiHexStream;
|