@pdfme/pdf-lib 6.0.3 → 6.0.5-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,192 +0,0 @@
|
|
|
1
|
-
import PDFArray from '../objects/PDFArray';
|
|
2
|
-
import PDFDict, { DictMap } from '../objects/PDFDict';
|
|
3
|
-
import PDFName from '../objects/PDFName';
|
|
4
|
-
import PDFNumber from '../objects/PDFNumber';
|
|
5
|
-
import PDFRef from '../objects/PDFRef';
|
|
6
|
-
import PDFContext from '../PDFContext';
|
|
7
|
-
import PDFPageLeaf from './PDFPageLeaf';
|
|
8
|
-
import { InvalidTargetIndexError, CorruptPageTreeError } from '../errors';
|
|
9
|
-
|
|
10
|
-
export type TreeNode = PDFPageTree | PDFPageLeaf;
|
|
11
|
-
|
|
12
|
-
class PDFPageTree extends PDFDict {
|
|
13
|
-
static withContext = (context: PDFContext, parent?: PDFRef) => {
|
|
14
|
-
const dict = new Map();
|
|
15
|
-
dict.set(PDFName.of('Type'), PDFName.of('Pages'));
|
|
16
|
-
dict.set(PDFName.of('Kids'), context.obj([]));
|
|
17
|
-
dict.set(PDFName.of('Count'), context.obj(0));
|
|
18
|
-
if (parent) dict.set(PDFName.of('Parent'), parent);
|
|
19
|
-
return new PDFPageTree(dict, context);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
static fromMapWithContext = (map: DictMap, context: PDFContext) => new PDFPageTree(map, context);
|
|
23
|
-
|
|
24
|
-
Parent(): PDFPageTree | undefined {
|
|
25
|
-
return this.lookup(PDFName.of('Parent')) as PDFPageTree | undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
Kids(): PDFArray {
|
|
29
|
-
return this.lookup(PDFName.of('Kids'), PDFArray);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
Count(): PDFNumber {
|
|
33
|
-
return this.lookup(PDFName.of('Count'), PDFNumber);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
pushTreeNode(treeRef: PDFRef): void {
|
|
37
|
-
const Kids = this.Kids();
|
|
38
|
-
Kids.push(treeRef);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
pushLeafNode(leafRef: PDFRef): void {
|
|
42
|
-
const Kids = this.Kids();
|
|
43
|
-
this.insertLeafKid(Kids.size(), leafRef);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Inserts the given ref as a leaf node of this page tree at the specified
|
|
48
|
-
* index (zero-based). Also increments the `Count` of each page tree in the
|
|
49
|
-
* hierarchy to accomodate the new page.
|
|
50
|
-
*
|
|
51
|
-
* Returns the ref of the PDFPageTree node into which `leafRef` was inserted,
|
|
52
|
-
* or `undefined` if it was inserted into the root node (the PDFPageTree upon
|
|
53
|
-
* which the method was first called).
|
|
54
|
-
*/
|
|
55
|
-
insertLeafNode(leafRef: PDFRef, targetIndex: number): PDFRef | undefined {
|
|
56
|
-
const Kids = this.Kids();
|
|
57
|
-
const Count = this.Count().asNumber();
|
|
58
|
-
|
|
59
|
-
if (targetIndex > Count) {
|
|
60
|
-
throw new InvalidTargetIndexError(targetIndex, Count);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let leafsRemainingUntilTarget = targetIndex;
|
|
64
|
-
for (let idx = 0, len = Kids.size(); idx < len; idx++) {
|
|
65
|
-
if (leafsRemainingUntilTarget === 0) {
|
|
66
|
-
// Insert page and return
|
|
67
|
-
this.insertLeafKid(idx, leafRef);
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const kidRef = Kids.get(idx) as PDFRef;
|
|
72
|
-
const kid = this.context.lookup(kidRef);
|
|
73
|
-
|
|
74
|
-
if (kid instanceof PDFPageTree) {
|
|
75
|
-
if (kid.Count().asNumber() > leafsRemainingUntilTarget) {
|
|
76
|
-
// Dig in
|
|
77
|
-
return kid.insertLeafNode(leafRef, leafsRemainingUntilTarget) || kidRef;
|
|
78
|
-
} else {
|
|
79
|
-
// Move on
|
|
80
|
-
leafsRemainingUntilTarget -= kid.Count().asNumber();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (kid instanceof PDFPageLeaf) {
|
|
85
|
-
// Move on
|
|
86
|
-
leafsRemainingUntilTarget -= 1;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (leafsRemainingUntilTarget === 0) {
|
|
91
|
-
// Insert page at the end and return
|
|
92
|
-
this.insertLeafKid(Kids.size(), leafRef);
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Should never get here if `targetIndex` is valid
|
|
97
|
-
throw new CorruptPageTreeError(targetIndex, 'insertLeafNode');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Removes the leaf node at the specified index (zero-based) from this page
|
|
102
|
-
* tree. Also decrements the `Count` of each page tree in the hierarchy to
|
|
103
|
-
* account for the removed page.
|
|
104
|
-
*
|
|
105
|
-
* If `prune` is true, then intermediate tree nodes will be removed from the
|
|
106
|
-
* tree if they contain 0 children after the leaf node is removed.
|
|
107
|
-
*/
|
|
108
|
-
removeLeafNode(targetIndex: number, prune = true): void {
|
|
109
|
-
const Kids = this.Kids();
|
|
110
|
-
const Count = this.Count().asNumber();
|
|
111
|
-
|
|
112
|
-
if (targetIndex >= Count) {
|
|
113
|
-
throw new InvalidTargetIndexError(targetIndex, Count);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
let leafsRemainingUntilTarget = targetIndex;
|
|
117
|
-
for (let idx = 0, len = Kids.size(); idx < len; idx++) {
|
|
118
|
-
const kidRef = Kids.get(idx) as PDFRef;
|
|
119
|
-
const kid = this.context.lookup(kidRef);
|
|
120
|
-
|
|
121
|
-
if (kid instanceof PDFPageTree) {
|
|
122
|
-
if (kid.Count().asNumber() > leafsRemainingUntilTarget) {
|
|
123
|
-
// Dig in
|
|
124
|
-
kid.removeLeafNode(leafsRemainingUntilTarget, prune);
|
|
125
|
-
if (prune && kid.Kids().size() === 0) Kids.remove(idx);
|
|
126
|
-
return;
|
|
127
|
-
} else {
|
|
128
|
-
// Move on
|
|
129
|
-
leafsRemainingUntilTarget -= kid.Count().asNumber();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (kid instanceof PDFPageLeaf) {
|
|
134
|
-
if (leafsRemainingUntilTarget === 0) {
|
|
135
|
-
// Remove page and return
|
|
136
|
-
this.removeKid(idx);
|
|
137
|
-
return;
|
|
138
|
-
} else {
|
|
139
|
-
// Move on
|
|
140
|
-
leafsRemainingUntilTarget -= 1;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Should never get here if `targetIndex` is valid
|
|
146
|
-
throw new CorruptPageTreeError(targetIndex, 'removeLeafNode');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
ascend(visitor: (node: PDFPageTree) => any): void {
|
|
150
|
-
visitor(this);
|
|
151
|
-
const Parent = this.Parent();
|
|
152
|
-
if (Parent) Parent.ascend(visitor);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** Performs a Post-Order traversal of this page tree */
|
|
156
|
-
traverse(visitor: (node: TreeNode, ref: PDFRef) => any): void {
|
|
157
|
-
const Kids = this.Kids();
|
|
158
|
-
for (let idx = 0, len = Kids.size(); idx < len; idx++) {
|
|
159
|
-
const kidRef = Kids.get(idx) as PDFRef;
|
|
160
|
-
const kid = this.context.lookup(kidRef) as TreeNode;
|
|
161
|
-
if (kid instanceof PDFPageTree) kid.traverse(visitor);
|
|
162
|
-
visitor(kid, kidRef);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
private insertLeafKid(kidIdx: number, leafRef: PDFRef): void {
|
|
167
|
-
const Kids = this.Kids();
|
|
168
|
-
|
|
169
|
-
this.ascend((node) => {
|
|
170
|
-
const newCount = node.Count().asNumber() + 1;
|
|
171
|
-
node.set(PDFName.of('Count'), PDFNumber.of(newCount));
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
Kids.insert(kidIdx, leafRef);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
private removeKid(kidIdx: number): void {
|
|
178
|
-
const Kids = this.Kids();
|
|
179
|
-
|
|
180
|
-
const kid = Kids.lookup(kidIdx);
|
|
181
|
-
if (kid instanceof PDFPageLeaf) {
|
|
182
|
-
this.ascend((node) => {
|
|
183
|
-
const newCount = node.Count().asNumber() - 1;
|
|
184
|
-
node.set(PDFName.of('Count'), PDFNumber.of(newCount));
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
Kids.remove(kidIdx);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export default PDFPageTree;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
enum CharCodes {
|
|
2
|
-
Null = 0,
|
|
3
|
-
Backspace = 8,
|
|
4
|
-
Tab = 9,
|
|
5
|
-
Newline = 10,
|
|
6
|
-
FormFeed = 12,
|
|
7
|
-
CarriageReturn = 13,
|
|
8
|
-
Space = 32,
|
|
9
|
-
ExclamationPoint = 33,
|
|
10
|
-
Hash = 35,
|
|
11
|
-
Percent = 37,
|
|
12
|
-
LeftParen = 40,
|
|
13
|
-
RightParen = 41,
|
|
14
|
-
Plus = 43,
|
|
15
|
-
Minus = 45,
|
|
16
|
-
Dash = Minus,
|
|
17
|
-
Period = 46,
|
|
18
|
-
ForwardSlash = 47,
|
|
19
|
-
Zero = 48,
|
|
20
|
-
One = 49,
|
|
21
|
-
Two = 50,
|
|
22
|
-
Three = 51,
|
|
23
|
-
Four = 52,
|
|
24
|
-
Five = 53,
|
|
25
|
-
Six = 54,
|
|
26
|
-
Seven = 55,
|
|
27
|
-
Eight = 56,
|
|
28
|
-
Nine = 57,
|
|
29
|
-
LessThan = 60,
|
|
30
|
-
GreaterThan = 62,
|
|
31
|
-
A = 65,
|
|
32
|
-
D = 68,
|
|
33
|
-
E = 69,
|
|
34
|
-
F = 70,
|
|
35
|
-
O = 79,
|
|
36
|
-
P = 80,
|
|
37
|
-
R = 82,
|
|
38
|
-
LeftSquareBracket = 91,
|
|
39
|
-
BackSlash = 92,
|
|
40
|
-
RightSquareBracket = 93,
|
|
41
|
-
a = 97,
|
|
42
|
-
b = 98,
|
|
43
|
-
d = 100,
|
|
44
|
-
e = 101,
|
|
45
|
-
f = 102,
|
|
46
|
-
i = 105,
|
|
47
|
-
j = 106,
|
|
48
|
-
l = 108,
|
|
49
|
-
m = 109,
|
|
50
|
-
n = 110,
|
|
51
|
-
o = 111,
|
|
52
|
-
r = 114,
|
|
53
|
-
s = 115,
|
|
54
|
-
t = 116,
|
|
55
|
-
u = 117,
|
|
56
|
-
x = 120,
|
|
57
|
-
LeftCurly = 123,
|
|
58
|
-
RightCurly = 125,
|
|
59
|
-
Tilde = 126,
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default CharCodes;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import CharCodes from './CharCodes';
|
|
2
|
-
|
|
3
|
-
export const IsDelimiter = new Uint8Array(256);
|
|
4
|
-
|
|
5
|
-
IsDelimiter[CharCodes.LeftParen] = 1;
|
|
6
|
-
IsDelimiter[CharCodes.RightParen] = 1;
|
|
7
|
-
IsDelimiter[CharCodes.LessThan] = 1;
|
|
8
|
-
IsDelimiter[CharCodes.GreaterThan] = 1;
|
|
9
|
-
IsDelimiter[CharCodes.LeftSquareBracket] = 1;
|
|
10
|
-
IsDelimiter[CharCodes.RightSquareBracket] = 1;
|
|
11
|
-
IsDelimiter[CharCodes.LeftCurly] = 1;
|
|
12
|
-
IsDelimiter[CharCodes.RightCurly] = 1;
|
|
13
|
-
IsDelimiter[CharCodes.ForwardSlash] = 1;
|
|
14
|
-
IsDelimiter[CharCodes.Percent] = 1;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import CharCodes from './CharCodes';
|
|
2
|
-
import { IsDelimiter } from './Delimiters';
|
|
3
|
-
import { IsWhitespace } from './Whitespace';
|
|
4
|
-
|
|
5
|
-
export const IsIrregular = new Uint8Array(256);
|
|
6
|
-
|
|
7
|
-
for (let idx = 0, len = 256; idx < len; idx++) {
|
|
8
|
-
IsIrregular[idx] = IsWhitespace[idx] || IsDelimiter[idx] ? 1 : 0;
|
|
9
|
-
}
|
|
10
|
-
IsIrregular[CharCodes.Hash] = 1;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import CharCodes from './CharCodes';
|
|
2
|
-
|
|
3
|
-
const { Space, CarriageReturn, Newline } = CharCodes;
|
|
4
|
-
|
|
5
|
-
const stream = [CharCodes.s, CharCodes.t, CharCodes.r, CharCodes.e, CharCodes.a, CharCodes.m];
|
|
6
|
-
|
|
7
|
-
const endstream = [
|
|
8
|
-
CharCodes.e,
|
|
9
|
-
CharCodes.n,
|
|
10
|
-
CharCodes.d,
|
|
11
|
-
CharCodes.s,
|
|
12
|
-
CharCodes.t,
|
|
13
|
-
CharCodes.r,
|
|
14
|
-
CharCodes.e,
|
|
15
|
-
CharCodes.a,
|
|
16
|
-
CharCodes.m,
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
export const Keywords = {
|
|
20
|
-
header: [CharCodes.Percent, CharCodes.P, CharCodes.D, CharCodes.F, CharCodes.Dash],
|
|
21
|
-
eof: [CharCodes.Percent, CharCodes.Percent, CharCodes.E, CharCodes.O, CharCodes.F],
|
|
22
|
-
obj: [CharCodes.o, CharCodes.b, CharCodes.j],
|
|
23
|
-
endobj: [CharCodes.e, CharCodes.n, CharCodes.d, CharCodes.o, CharCodes.b, CharCodes.j],
|
|
24
|
-
xref: [CharCodes.x, CharCodes.r, CharCodes.e, CharCodes.f],
|
|
25
|
-
trailer: [
|
|
26
|
-
CharCodes.t,
|
|
27
|
-
CharCodes.r,
|
|
28
|
-
CharCodes.a,
|
|
29
|
-
CharCodes.i,
|
|
30
|
-
CharCodes.l,
|
|
31
|
-
CharCodes.e,
|
|
32
|
-
CharCodes.r,
|
|
33
|
-
],
|
|
34
|
-
startxref: [
|
|
35
|
-
CharCodes.s,
|
|
36
|
-
CharCodes.t,
|
|
37
|
-
CharCodes.a,
|
|
38
|
-
CharCodes.r,
|
|
39
|
-
CharCodes.t,
|
|
40
|
-
CharCodes.x,
|
|
41
|
-
CharCodes.r,
|
|
42
|
-
CharCodes.e,
|
|
43
|
-
CharCodes.f,
|
|
44
|
-
],
|
|
45
|
-
true: [CharCodes.t, CharCodes.r, CharCodes.u, CharCodes.e],
|
|
46
|
-
false: [CharCodes.f, CharCodes.a, CharCodes.l, CharCodes.s, CharCodes.e],
|
|
47
|
-
null: [CharCodes.n, CharCodes.u, CharCodes.l, CharCodes.l],
|
|
48
|
-
stream,
|
|
49
|
-
streamEOF1: [...stream, Space, CarriageReturn, Newline],
|
|
50
|
-
streamEOF2: [...stream, CarriageReturn, Newline],
|
|
51
|
-
streamEOF3: [...stream, CarriageReturn],
|
|
52
|
-
streamEOF4: [...stream, Newline],
|
|
53
|
-
endstream,
|
|
54
|
-
EOF1endstream: [CarriageReturn, Newline, ...endstream],
|
|
55
|
-
EOF2endstream: [CarriageReturn, ...endstream],
|
|
56
|
-
EOF3endstream: [Newline, ...endstream],
|
|
57
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import CharCodes from './CharCodes';
|
|
2
|
-
|
|
3
|
-
export const IsDigit = new Uint8Array(256);
|
|
4
|
-
|
|
5
|
-
IsDigit[CharCodes.Zero] = 1;
|
|
6
|
-
IsDigit[CharCodes.One] = 1;
|
|
7
|
-
IsDigit[CharCodes.Two] = 1;
|
|
8
|
-
IsDigit[CharCodes.Three] = 1;
|
|
9
|
-
IsDigit[CharCodes.Four] = 1;
|
|
10
|
-
IsDigit[CharCodes.Five] = 1;
|
|
11
|
-
IsDigit[CharCodes.Six] = 1;
|
|
12
|
-
IsDigit[CharCodes.Seven] = 1;
|
|
13
|
-
IsDigit[CharCodes.Eight] = 1;
|
|
14
|
-
IsDigit[CharCodes.Nine] = 1;
|
|
15
|
-
|
|
16
|
-
export const IsNumericPrefix = new Uint8Array(256);
|
|
17
|
-
|
|
18
|
-
IsNumericPrefix[CharCodes.Period] = 1;
|
|
19
|
-
IsNumericPrefix[CharCodes.Plus] = 1;
|
|
20
|
-
IsNumericPrefix[CharCodes.Minus] = 1;
|
|
21
|
-
|
|
22
|
-
export const IsNumeric = new Uint8Array(256);
|
|
23
|
-
|
|
24
|
-
for (let idx = 0, len = 256; idx < len; idx++) {
|
|
25
|
-
IsNumeric[idx] = IsDigit[idx] || IsNumericPrefix[idx] ? 1 : 0;
|
|
26
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import CharCodes from './CharCodes';
|
|
2
|
-
|
|
3
|
-
export const IsWhitespace = new Uint8Array(256);
|
|
4
|
-
|
|
5
|
-
IsWhitespace[CharCodes.Null] = 1;
|
|
6
|
-
IsWhitespace[CharCodes.Tab] = 1;
|
|
7
|
-
IsWhitespace[CharCodes.Newline] = 1;
|
|
8
|
-
IsWhitespace[CharCodes.FormFeed] = 1;
|
|
9
|
-
IsWhitespace[CharCodes.CarriageReturn] = 1;
|
|
10
|
-
IsWhitespace[CharCodes.Space] = 1;
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import PDFHeader from '../document/PDFHeader';
|
|
2
|
-
import PDFTrailer from '../document/PDFTrailer';
|
|
3
|
-
import PDFInvalidObject from '../objects/PDFInvalidObject';
|
|
4
|
-
import PDFName from '../objects/PDFName';
|
|
5
|
-
import PDFNumber from '../objects/PDFNumber';
|
|
6
|
-
import PDFObject from '../objects/PDFObject';
|
|
7
|
-
import PDFRef from '../objects/PDFRef';
|
|
8
|
-
import PDFStream from '../objects/PDFStream';
|
|
9
|
-
import PDFContext from '../PDFContext';
|
|
10
|
-
import PDFCrossRefStream from '../structures/PDFCrossRefStream';
|
|
11
|
-
import PDFObjectStream from '../structures/PDFObjectStream';
|
|
12
|
-
import PDFWriter from './PDFWriter';
|
|
13
|
-
import { last, waitForTick } from '../../utils';
|
|
14
|
-
|
|
15
|
-
class PDFStreamWriter extends PDFWriter {
|
|
16
|
-
static forContext = (
|
|
17
|
-
context: PDFContext,
|
|
18
|
-
objectsPerTick: number,
|
|
19
|
-
encodeStreams = true,
|
|
20
|
-
objectsPerStream = 50,
|
|
21
|
-
) => new PDFStreamWriter(context, objectsPerTick, encodeStreams, objectsPerStream);
|
|
22
|
-
|
|
23
|
-
private readonly encodeStreams: boolean;
|
|
24
|
-
private readonly objectsPerStream: number;
|
|
25
|
-
|
|
26
|
-
private constructor(
|
|
27
|
-
context: PDFContext,
|
|
28
|
-
objectsPerTick: number,
|
|
29
|
-
encodeStreams: boolean,
|
|
30
|
-
objectsPerStream: number,
|
|
31
|
-
) {
|
|
32
|
-
super(context, objectsPerTick);
|
|
33
|
-
|
|
34
|
-
this.encodeStreams = encodeStreams;
|
|
35
|
-
this.objectsPerStream = objectsPerStream;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected async computeBufferSize() {
|
|
39
|
-
let objectNumber = this.context.largestObjectNumber + 1;
|
|
40
|
-
|
|
41
|
-
const header = PDFHeader.forVersion(1, 7);
|
|
42
|
-
|
|
43
|
-
let size = header.sizeInBytes() + 2;
|
|
44
|
-
|
|
45
|
-
const xrefStream = PDFCrossRefStream.create(this.createTrailerDict(), this.encodeStreams);
|
|
46
|
-
|
|
47
|
-
const uncompressedObjects: [PDFRef, PDFObject][] = [];
|
|
48
|
-
const compressedObjects: [PDFRef, PDFObject][][] = [];
|
|
49
|
-
const objectStreamRefs: PDFRef[] = [];
|
|
50
|
-
|
|
51
|
-
const indirectObjects = this.context.enumerateIndirectObjects();
|
|
52
|
-
for (let idx = 0, len = indirectObjects.length; idx < len; idx++) {
|
|
53
|
-
const indirectObject = indirectObjects[idx];
|
|
54
|
-
const [ref, object] = indirectObject;
|
|
55
|
-
|
|
56
|
-
const shouldNotCompress =
|
|
57
|
-
ref === this.context.trailerInfo.Encrypt ||
|
|
58
|
-
object instanceof PDFStream ||
|
|
59
|
-
object instanceof PDFInvalidObject ||
|
|
60
|
-
ref.generationNumber !== 0;
|
|
61
|
-
|
|
62
|
-
if (shouldNotCompress) {
|
|
63
|
-
uncompressedObjects.push(indirectObject);
|
|
64
|
-
xrefStream.addUncompressedEntry(ref, size);
|
|
65
|
-
size += this.computeIndirectObjectSize(indirectObject);
|
|
66
|
-
if (this.shouldWaitForTick(1)) await waitForTick();
|
|
67
|
-
} else {
|
|
68
|
-
let chunk = last(compressedObjects);
|
|
69
|
-
let objectStreamRef = last(objectStreamRefs);
|
|
70
|
-
if (!chunk || chunk.length % this.objectsPerStream === 0) {
|
|
71
|
-
chunk = [];
|
|
72
|
-
compressedObjects.push(chunk);
|
|
73
|
-
objectStreamRef = PDFRef.of(objectNumber++);
|
|
74
|
-
objectStreamRefs.push(objectStreamRef);
|
|
75
|
-
}
|
|
76
|
-
xrefStream.addCompressedEntry(ref, objectStreamRef, chunk.length);
|
|
77
|
-
chunk.push(indirectObject);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
for (let idx = 0, len = compressedObjects.length; idx < len; idx++) {
|
|
82
|
-
const chunk = compressedObjects[idx];
|
|
83
|
-
const ref = objectStreamRefs[idx];
|
|
84
|
-
|
|
85
|
-
const objectStream = PDFObjectStream.withContextAndObjects(
|
|
86
|
-
this.context,
|
|
87
|
-
chunk,
|
|
88
|
-
this.encodeStreams,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
xrefStream.addUncompressedEntry(ref, size);
|
|
92
|
-
size += this.computeIndirectObjectSize([ref, objectStream]);
|
|
93
|
-
|
|
94
|
-
uncompressedObjects.push([ref, objectStream]);
|
|
95
|
-
|
|
96
|
-
if (this.shouldWaitForTick(chunk.length)) await waitForTick();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const xrefStreamRef = PDFRef.of(objectNumber++);
|
|
100
|
-
xrefStream.dict.set(PDFName.of('Size'), PDFNumber.of(objectNumber));
|
|
101
|
-
xrefStream.addUncompressedEntry(xrefStreamRef, size);
|
|
102
|
-
const xrefOffset = size;
|
|
103
|
-
size += this.computeIndirectObjectSize([xrefStreamRef, xrefStream]);
|
|
104
|
-
|
|
105
|
-
uncompressedObjects.push([xrefStreamRef, xrefStream]);
|
|
106
|
-
|
|
107
|
-
const trailer = PDFTrailer.forLastCrossRefSectionOffset(xrefOffset);
|
|
108
|
-
size += trailer.sizeInBytes();
|
|
109
|
-
|
|
110
|
-
return { size, header, indirectObjects: uncompressedObjects, trailer };
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export default PDFStreamWriter;
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import PDFCrossRefSection from '../document/PDFCrossRefSection';
|
|
2
|
-
import PDFHeader from '../document/PDFHeader';
|
|
3
|
-
import PDFTrailer from '../document/PDFTrailer';
|
|
4
|
-
import PDFTrailerDict from '../document/PDFTrailerDict';
|
|
5
|
-
import PDFDict from '../objects/PDFDict';
|
|
6
|
-
import PDFObject from '../objects/PDFObject';
|
|
7
|
-
import PDFRef from '../objects/PDFRef';
|
|
8
|
-
import PDFContext from '../PDFContext';
|
|
9
|
-
import PDFObjectStream from '../structures/PDFObjectStream';
|
|
10
|
-
import CharCodes from '../syntax/CharCodes';
|
|
11
|
-
import { copyStringIntoBuffer, waitForTick } from '../../utils';
|
|
12
|
-
|
|
13
|
-
export interface SerializationInfo {
|
|
14
|
-
size: number;
|
|
15
|
-
header: PDFHeader;
|
|
16
|
-
indirectObjects: [PDFRef, PDFObject][];
|
|
17
|
-
xref?: PDFCrossRefSection;
|
|
18
|
-
trailerDict?: PDFTrailerDict;
|
|
19
|
-
trailer: PDFTrailer;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
class PDFWriter {
|
|
23
|
-
static forContext = (context: PDFContext, objectsPerTick: number) =>
|
|
24
|
-
new PDFWriter(context, objectsPerTick);
|
|
25
|
-
|
|
26
|
-
protected readonly context: PDFContext;
|
|
27
|
-
|
|
28
|
-
protected readonly objectsPerTick: number;
|
|
29
|
-
private parsedObjects = 0;
|
|
30
|
-
|
|
31
|
-
protected constructor(context: PDFContext, objectsPerTick: number) {
|
|
32
|
-
this.context = context;
|
|
33
|
-
this.objectsPerTick = objectsPerTick;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async serializeToBuffer(): Promise<Uint8Array<ArrayBuffer>> {
|
|
37
|
-
const { size, header, indirectObjects, xref, trailerDict, trailer } =
|
|
38
|
-
await this.computeBufferSize();
|
|
39
|
-
|
|
40
|
-
let offset = 0;
|
|
41
|
-
const buffer = new Uint8Array(size);
|
|
42
|
-
|
|
43
|
-
offset += header.copyBytesInto(buffer, offset);
|
|
44
|
-
buffer[offset++] = CharCodes.Newline;
|
|
45
|
-
buffer[offset++] = CharCodes.Newline;
|
|
46
|
-
|
|
47
|
-
for (let idx = 0, len = indirectObjects.length; idx < len; idx++) {
|
|
48
|
-
const [ref, object] = indirectObjects[idx];
|
|
49
|
-
|
|
50
|
-
const objectNumber = String(ref.objectNumber);
|
|
51
|
-
offset += copyStringIntoBuffer(objectNumber, buffer, offset);
|
|
52
|
-
buffer[offset++] = CharCodes.Space;
|
|
53
|
-
|
|
54
|
-
const generationNumber = String(ref.generationNumber);
|
|
55
|
-
offset += copyStringIntoBuffer(generationNumber, buffer, offset);
|
|
56
|
-
buffer[offset++] = CharCodes.Space;
|
|
57
|
-
|
|
58
|
-
buffer[offset++] = CharCodes.o;
|
|
59
|
-
buffer[offset++] = CharCodes.b;
|
|
60
|
-
buffer[offset++] = CharCodes.j;
|
|
61
|
-
buffer[offset++] = CharCodes.Newline;
|
|
62
|
-
|
|
63
|
-
offset += object.copyBytesInto(buffer, offset);
|
|
64
|
-
|
|
65
|
-
buffer[offset++] = CharCodes.Newline;
|
|
66
|
-
buffer[offset++] = CharCodes.e;
|
|
67
|
-
buffer[offset++] = CharCodes.n;
|
|
68
|
-
buffer[offset++] = CharCodes.d;
|
|
69
|
-
buffer[offset++] = CharCodes.o;
|
|
70
|
-
buffer[offset++] = CharCodes.b;
|
|
71
|
-
buffer[offset++] = CharCodes.j;
|
|
72
|
-
buffer[offset++] = CharCodes.Newline;
|
|
73
|
-
buffer[offset++] = CharCodes.Newline;
|
|
74
|
-
|
|
75
|
-
const n = object instanceof PDFObjectStream ? object.getObjectsCount() : 1;
|
|
76
|
-
if (this.shouldWaitForTick(n)) await waitForTick();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (xref) {
|
|
80
|
-
offset += xref.copyBytesInto(buffer, offset);
|
|
81
|
-
buffer[offset++] = CharCodes.Newline;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (trailerDict) {
|
|
85
|
-
offset += trailerDict.copyBytesInto(buffer, offset);
|
|
86
|
-
buffer[offset++] = CharCodes.Newline;
|
|
87
|
-
buffer[offset++] = CharCodes.Newline;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
offset += trailer.copyBytesInto(buffer, offset);
|
|
91
|
-
|
|
92
|
-
return buffer;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
protected computeIndirectObjectSize([ref, object]: [PDFRef, PDFObject]): number {
|
|
96
|
-
const refSize = ref.sizeInBytes() + 3; // 'R' -> 'obj\n'
|
|
97
|
-
const objectSize = object.sizeInBytes() + 9; // '\nendobj\n\n'
|
|
98
|
-
return refSize + objectSize;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
protected createTrailerDict(): PDFDict {
|
|
102
|
-
return this.context.obj({
|
|
103
|
-
Size: this.context.largestObjectNumber + 1,
|
|
104
|
-
Root: this.context.trailerInfo.Root,
|
|
105
|
-
Encrypt: this.context.trailerInfo.Encrypt,
|
|
106
|
-
Info: this.context.trailerInfo.Info,
|
|
107
|
-
ID: this.context.trailerInfo.ID,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
protected async computeBufferSize(): Promise<SerializationInfo> {
|
|
112
|
-
const header = PDFHeader.forVersion(1, 7);
|
|
113
|
-
|
|
114
|
-
let size = header.sizeInBytes() + 2;
|
|
115
|
-
|
|
116
|
-
const xref = PDFCrossRefSection.create();
|
|
117
|
-
|
|
118
|
-
const indirectObjects = this.context.enumerateIndirectObjects();
|
|
119
|
-
|
|
120
|
-
for (let idx = 0, len = indirectObjects.length; idx < len; idx++) {
|
|
121
|
-
const indirectObject = indirectObjects[idx];
|
|
122
|
-
const [ref] = indirectObject;
|
|
123
|
-
xref.addEntry(ref, size);
|
|
124
|
-
size += this.computeIndirectObjectSize(indirectObject);
|
|
125
|
-
if (this.shouldWaitForTick(1)) await waitForTick();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const xrefOffset = size;
|
|
129
|
-
size += xref.sizeInBytes() + 1; // '\n'
|
|
130
|
-
|
|
131
|
-
const trailerDict = PDFTrailerDict.of(this.createTrailerDict());
|
|
132
|
-
size += trailerDict.sizeInBytes() + 2; // '\n\n'
|
|
133
|
-
|
|
134
|
-
const trailer = PDFTrailer.forLastCrossRefSectionOffset(xrefOffset);
|
|
135
|
-
size += trailer.sizeInBytes();
|
|
136
|
-
|
|
137
|
-
return { size, header, indirectObjects, xref, trailerDict, trailer };
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
protected shouldWaitForTick = (n: number) => {
|
|
141
|
-
this.parsedObjects += n;
|
|
142
|
-
return this.parsedObjects % this.objectsPerTick === 0;
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export default PDFWriter;
|