@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,238 +0,0 @@
|
|
|
1
|
-
import PDFDict from '../objects/PDFDict';
|
|
2
|
-
import PDFName from '../objects/PDFName';
|
|
3
|
-
import PDFRef from '../objects/PDFRef';
|
|
4
|
-
import PDFContext from '../PDFContext';
|
|
5
|
-
import PDFFlateStream from './PDFFlateStream';
|
|
6
|
-
import { bytesFor, Cache, reverseArray, sizeInBytes, sum } from '../../utils';
|
|
7
|
-
|
|
8
|
-
export enum EntryType {
|
|
9
|
-
Deleted = 0,
|
|
10
|
-
Uncompressed = 1,
|
|
11
|
-
Compressed = 2,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface DeletedEntry {
|
|
15
|
-
type: EntryType.Deleted;
|
|
16
|
-
ref: PDFRef;
|
|
17
|
-
nextFreeObjectNumber: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface UncompressedEntry {
|
|
21
|
-
type: EntryType.Uncompressed;
|
|
22
|
-
ref: PDFRef;
|
|
23
|
-
offset: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface CompressedEntry {
|
|
27
|
-
type: EntryType.Compressed;
|
|
28
|
-
ref: PDFRef;
|
|
29
|
-
objectStreamRef: PDFRef;
|
|
30
|
-
index: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type Entry = DeletedEntry | UncompressedEntry | CompressedEntry;
|
|
34
|
-
|
|
35
|
-
export type EntryTuple = [number, number, number];
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Entries should be added using the [[addDeletedEntry]],
|
|
39
|
-
* [[addUncompressedEntry]], and [[addCompressedEntry]] methods
|
|
40
|
-
* **in order of ascending object number**.
|
|
41
|
-
*/
|
|
42
|
-
class PDFCrossRefStream extends PDFFlateStream {
|
|
43
|
-
static create = (dict: PDFDict, encode = true) => {
|
|
44
|
-
const stream = new PDFCrossRefStream(dict, [], encode);
|
|
45
|
-
stream.addDeletedEntry(PDFRef.of(0, 65535), 0);
|
|
46
|
-
return stream;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
static of = (dict: PDFDict, entries: Entry[], encode = true) =>
|
|
50
|
-
new PDFCrossRefStream(dict, entries, encode);
|
|
51
|
-
|
|
52
|
-
private readonly entries: Entry[];
|
|
53
|
-
private readonly entryTuplesCache: Cache<EntryTuple[]>;
|
|
54
|
-
private readonly maxByteWidthsCache: Cache<[number, number, number]>;
|
|
55
|
-
private readonly indexCache: Cache<number[]>;
|
|
56
|
-
|
|
57
|
-
private constructor(dict: PDFDict, entries?: Entry[], encode = true) {
|
|
58
|
-
super(dict, encode);
|
|
59
|
-
|
|
60
|
-
this.entries = entries || [];
|
|
61
|
-
this.entryTuplesCache = Cache.populatedBy(this.computeEntryTuples);
|
|
62
|
-
this.maxByteWidthsCache = Cache.populatedBy(this.computeMaxEntryByteWidths);
|
|
63
|
-
this.indexCache = Cache.populatedBy(this.computeIndex);
|
|
64
|
-
|
|
65
|
-
dict.set(PDFName.of('Type'), PDFName.of('XRef'));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
addDeletedEntry(ref: PDFRef, nextFreeObjectNumber: number) {
|
|
69
|
-
const type = EntryType.Deleted;
|
|
70
|
-
this.entries.push({ type, ref, nextFreeObjectNumber });
|
|
71
|
-
this.entryTuplesCache.invalidate();
|
|
72
|
-
this.maxByteWidthsCache.invalidate();
|
|
73
|
-
this.indexCache.invalidate();
|
|
74
|
-
this.contentsCache.invalidate();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
addUncompressedEntry(ref: PDFRef, offset: number) {
|
|
78
|
-
const type = EntryType.Uncompressed;
|
|
79
|
-
this.entries.push({ type, ref, offset });
|
|
80
|
-
this.entryTuplesCache.invalidate();
|
|
81
|
-
this.maxByteWidthsCache.invalidate();
|
|
82
|
-
this.indexCache.invalidate();
|
|
83
|
-
this.contentsCache.invalidate();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
addCompressedEntry(ref: PDFRef, objectStreamRef: PDFRef, index: number) {
|
|
87
|
-
const type = EntryType.Compressed;
|
|
88
|
-
this.entries.push({ type, ref, objectStreamRef, index });
|
|
89
|
-
this.entryTuplesCache.invalidate();
|
|
90
|
-
this.maxByteWidthsCache.invalidate();
|
|
91
|
-
this.indexCache.invalidate();
|
|
92
|
-
this.contentsCache.invalidate();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
clone(context?: PDFContext): PDFCrossRefStream {
|
|
96
|
-
const { dict, entries, encode } = this;
|
|
97
|
-
return PDFCrossRefStream.of(dict.clone(context), entries.slice(), encode);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
getContentsString(): string {
|
|
101
|
-
const entryTuples = this.entryTuplesCache.access();
|
|
102
|
-
const byteWidths = this.maxByteWidthsCache.access();
|
|
103
|
-
let value = '';
|
|
104
|
-
|
|
105
|
-
for (let entryIdx = 0, entriesLen = entryTuples.length; entryIdx < entriesLen; entryIdx++) {
|
|
106
|
-
const [first, second, third] = entryTuples[entryIdx];
|
|
107
|
-
|
|
108
|
-
const firstBytes = reverseArray(bytesFor(first));
|
|
109
|
-
const secondBytes = reverseArray(bytesFor(second));
|
|
110
|
-
const thirdBytes = reverseArray(bytesFor(third));
|
|
111
|
-
|
|
112
|
-
for (let idx = byteWidths[0] - 1; idx >= 0; idx--) {
|
|
113
|
-
value += (firstBytes[idx] || 0).toString(2);
|
|
114
|
-
}
|
|
115
|
-
for (let idx = byteWidths[1] - 1; idx >= 0; idx--) {
|
|
116
|
-
value += (secondBytes[idx] || 0).toString(2);
|
|
117
|
-
}
|
|
118
|
-
for (let idx = byteWidths[2] - 1; idx >= 0; idx--) {
|
|
119
|
-
value += (thirdBytes[idx] || 0).toString(2);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return value;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
getUnencodedContents(): Uint8Array {
|
|
127
|
-
const entryTuples = this.entryTuplesCache.access();
|
|
128
|
-
const byteWidths = this.maxByteWidthsCache.access();
|
|
129
|
-
const buffer = new Uint8Array(this.getUnencodedContentsSize());
|
|
130
|
-
|
|
131
|
-
let offset = 0;
|
|
132
|
-
for (let entryIdx = 0, entriesLen = entryTuples.length; entryIdx < entriesLen; entryIdx++) {
|
|
133
|
-
const [first, second, third] = entryTuples[entryIdx];
|
|
134
|
-
|
|
135
|
-
const firstBytes = reverseArray(bytesFor(first));
|
|
136
|
-
const secondBytes = reverseArray(bytesFor(second));
|
|
137
|
-
const thirdBytes = reverseArray(bytesFor(third));
|
|
138
|
-
|
|
139
|
-
for (let idx = byteWidths[0] - 1; idx >= 0; idx--) {
|
|
140
|
-
buffer[offset++] = firstBytes[idx] || 0;
|
|
141
|
-
}
|
|
142
|
-
for (let idx = byteWidths[1] - 1; idx >= 0; idx--) {
|
|
143
|
-
buffer[offset++] = secondBytes[idx] || 0;
|
|
144
|
-
}
|
|
145
|
-
for (let idx = byteWidths[2] - 1; idx >= 0; idx--) {
|
|
146
|
-
buffer[offset++] = thirdBytes[idx] || 0;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return buffer;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
getUnencodedContentsSize(): number {
|
|
154
|
-
const byteWidths = this.maxByteWidthsCache.access();
|
|
155
|
-
const entryWidth = sum(byteWidths);
|
|
156
|
-
return entryWidth * this.entries.length;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
updateDict(): void {
|
|
160
|
-
super.updateDict();
|
|
161
|
-
|
|
162
|
-
const byteWidths = this.maxByteWidthsCache.access();
|
|
163
|
-
const index = this.indexCache.access();
|
|
164
|
-
|
|
165
|
-
const { context } = this.dict;
|
|
166
|
-
this.dict.set(PDFName.of('W'), context.obj(byteWidths));
|
|
167
|
-
this.dict.set(PDFName.of('Index'), context.obj(index));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Returns an array of integer pairs for each subsection of the cross ref
|
|
171
|
-
// section, where each integer pair represents:
|
|
172
|
-
// firstObjectNumber(OfSection), length(OfSection)
|
|
173
|
-
private computeIndex = (): number[] => {
|
|
174
|
-
const subsections: number[] = [];
|
|
175
|
-
|
|
176
|
-
let subsectionLength = 0;
|
|
177
|
-
for (let idx = 0, len = this.entries.length; idx < len; idx++) {
|
|
178
|
-
const currEntry = this.entries[idx];
|
|
179
|
-
const prevEntry = this.entries[idx - 1];
|
|
180
|
-
|
|
181
|
-
if (idx === 0) {
|
|
182
|
-
subsections.push(currEntry.ref.objectNumber);
|
|
183
|
-
} else if (currEntry.ref.objectNumber - prevEntry.ref.objectNumber > 1) {
|
|
184
|
-
subsections.push(subsectionLength);
|
|
185
|
-
subsections.push(currEntry.ref.objectNumber);
|
|
186
|
-
subsectionLength = 0;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
subsectionLength += 1;
|
|
190
|
-
}
|
|
191
|
-
subsections.push(subsectionLength);
|
|
192
|
-
|
|
193
|
-
return subsections;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
private computeEntryTuples = (): EntryTuple[] => {
|
|
197
|
-
const entryTuples: EntryTuple[] = Array(this.entries.length);
|
|
198
|
-
|
|
199
|
-
for (let idx = 0, len = this.entries.length; idx < len; idx++) {
|
|
200
|
-
const entry = this.entries[idx];
|
|
201
|
-
if (entry.type === EntryType.Deleted) {
|
|
202
|
-
const { type, nextFreeObjectNumber, ref } = entry;
|
|
203
|
-
entryTuples[idx] = [type, nextFreeObjectNumber, ref.generationNumber];
|
|
204
|
-
}
|
|
205
|
-
if (entry.type === EntryType.Uncompressed) {
|
|
206
|
-
const { type, offset, ref } = entry;
|
|
207
|
-
entryTuples[idx] = [type, offset, ref.generationNumber];
|
|
208
|
-
}
|
|
209
|
-
if (entry.type === EntryType.Compressed) {
|
|
210
|
-
const { type, objectStreamRef, index } = entry;
|
|
211
|
-
entryTuples[idx] = [type, objectStreamRef.objectNumber, index];
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return entryTuples;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
private computeMaxEntryByteWidths = (): [number, number, number] => {
|
|
219
|
-
const entryTuples = this.entryTuplesCache.access();
|
|
220
|
-
const widths: [number, number, number] = [0, 0, 0];
|
|
221
|
-
|
|
222
|
-
for (let idx = 0, len = entryTuples.length; idx < len; idx++) {
|
|
223
|
-
const [first, second, third] = entryTuples[idx];
|
|
224
|
-
|
|
225
|
-
const firstSize = sizeInBytes(first);
|
|
226
|
-
const secondSize = sizeInBytes(second);
|
|
227
|
-
const thirdSize = sizeInBytes(third);
|
|
228
|
-
|
|
229
|
-
if (firstSize > widths[0]) widths[0] = firstSize;
|
|
230
|
-
if (secondSize > widths[1]) widths[1] = secondSize;
|
|
231
|
-
if (thirdSize > widths[2]) widths[2] = thirdSize;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return widths;
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export default PDFCrossRefStream;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import pako from 'pako';
|
|
2
|
-
|
|
3
|
-
import { MethodNotImplementedError } from '../errors';
|
|
4
|
-
import PDFDict from '../objects/PDFDict';
|
|
5
|
-
import PDFName from '../objects/PDFName';
|
|
6
|
-
import PDFStream from '../objects/PDFStream';
|
|
7
|
-
import { Cache } from '../../utils';
|
|
8
|
-
|
|
9
|
-
class PDFFlateStream extends PDFStream {
|
|
10
|
-
protected readonly contentsCache: Cache<Uint8Array>;
|
|
11
|
-
protected readonly encode: boolean;
|
|
12
|
-
|
|
13
|
-
constructor(dict: PDFDict, encode: boolean) {
|
|
14
|
-
super(dict);
|
|
15
|
-
|
|
16
|
-
this.encode = encode;
|
|
17
|
-
|
|
18
|
-
if (encode) dict.set(PDFName.of('Filter'), PDFName.of('FlateDecode'));
|
|
19
|
-
this.contentsCache = Cache.populatedBy(this.computeContents);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
computeContents = (): Uint8Array => {
|
|
23
|
-
const unencodedContents = this.getUnencodedContents();
|
|
24
|
-
return this.encode ? pako.deflate(unencodedContents) : unencodedContents;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
getContents(): Uint8Array {
|
|
28
|
-
return this.contentsCache.access();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getContentsSize(): number {
|
|
32
|
-
return this.contentsCache.access().length;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
getUnencodedContents(): Uint8Array {
|
|
36
|
-
throw new MethodNotImplementedError(this.constructor.name, 'getUnencodedContents');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default PDFFlateStream;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import PDFName from '../objects/PDFName';
|
|
2
|
-
import PDFNumber from '../objects/PDFNumber';
|
|
3
|
-
import PDFObject from '../objects/PDFObject';
|
|
4
|
-
import PDFRef from '../objects/PDFRef';
|
|
5
|
-
import PDFContext from '../PDFContext';
|
|
6
|
-
import PDFFlateStream from './PDFFlateStream';
|
|
7
|
-
import CharCodes from '../syntax/CharCodes';
|
|
8
|
-
import { copyStringIntoBuffer, last } from '../../utils';
|
|
9
|
-
|
|
10
|
-
export type IndirectObject = [PDFRef, PDFObject];
|
|
11
|
-
|
|
12
|
-
class PDFObjectStream extends PDFFlateStream {
|
|
13
|
-
static withContextAndObjects = (context: PDFContext, objects: IndirectObject[], encode = true) =>
|
|
14
|
-
new PDFObjectStream(context, objects, encode);
|
|
15
|
-
|
|
16
|
-
private readonly objects: IndirectObject[];
|
|
17
|
-
private readonly offsets: [number, number][];
|
|
18
|
-
private readonly offsetsString: string;
|
|
19
|
-
|
|
20
|
-
private constructor(context: PDFContext, objects: IndirectObject[], encode = true) {
|
|
21
|
-
super(context.obj({}), encode);
|
|
22
|
-
|
|
23
|
-
this.objects = objects;
|
|
24
|
-
this.offsets = this.computeObjectOffsets();
|
|
25
|
-
this.offsetsString = this.computeOffsetsString();
|
|
26
|
-
|
|
27
|
-
this.dict.set(PDFName.of('Type'), PDFName.of('ObjStm'));
|
|
28
|
-
this.dict.set(PDFName.of('N'), PDFNumber.of(this.objects.length));
|
|
29
|
-
this.dict.set(PDFName.of('First'), PDFNumber.of(this.offsetsString.length));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getObjectsCount(): number {
|
|
33
|
-
return this.objects.length;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
clone(context?: PDFContext): PDFObjectStream {
|
|
37
|
-
return PDFObjectStream.withContextAndObjects(
|
|
38
|
-
context || this.dict.context,
|
|
39
|
-
this.objects.slice(),
|
|
40
|
-
this.encode,
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getContentsString(): string {
|
|
45
|
-
let value = this.offsetsString;
|
|
46
|
-
for (let idx = 0, len = this.objects.length; idx < len; idx++) {
|
|
47
|
-
const [, object] = this.objects[idx];
|
|
48
|
-
value += `${object}\n`;
|
|
49
|
-
}
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
getUnencodedContents(): Uint8Array {
|
|
54
|
-
const buffer = new Uint8Array(this.getUnencodedContentsSize());
|
|
55
|
-
let offset = copyStringIntoBuffer(this.offsetsString, buffer, 0);
|
|
56
|
-
for (let idx = 0, len = this.objects.length; idx < len; idx++) {
|
|
57
|
-
const [, object] = this.objects[idx];
|
|
58
|
-
offset += object.copyBytesInto(buffer, offset);
|
|
59
|
-
buffer[offset++] = CharCodes.Newline;
|
|
60
|
-
}
|
|
61
|
-
return buffer;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getUnencodedContentsSize(): number {
|
|
65
|
-
return (
|
|
66
|
-
this.offsetsString.length + last(this.offsets)[1] + last(this.objects)[1].sizeInBytes() + 1
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
private computeOffsetsString(): string {
|
|
71
|
-
let offsetsString = '';
|
|
72
|
-
for (let idx = 0, len = this.offsets.length; idx < len; idx++) {
|
|
73
|
-
const [objectNumber, offset] = this.offsets[idx];
|
|
74
|
-
offsetsString += `${objectNumber} ${offset} `;
|
|
75
|
-
}
|
|
76
|
-
return offsetsString;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private computeObjectOffsets(): [number, number][] {
|
|
80
|
-
let offset = 0;
|
|
81
|
-
const offsets = Array(this.objects.length);
|
|
82
|
-
for (let idx = 0, len = this.objects.length; idx < len; idx++) {
|
|
83
|
-
const [ref, object] = this.objects[idx];
|
|
84
|
-
offsets[idx] = [ref.objectNumber, offset];
|
|
85
|
-
offset += object.sizeInBytes() + 1; // '\n'
|
|
86
|
-
}
|
|
87
|
-
return offsets;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export default PDFObjectStream;
|
|
@@ -1,244 +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 PDFObject from '../objects/PDFObject';
|
|
6
|
-
import PDFRef from '../objects/PDFRef';
|
|
7
|
-
import PDFStream from '../objects/PDFStream';
|
|
8
|
-
import PDFContext from '../PDFContext';
|
|
9
|
-
import PDFPageTree from './PDFPageTree';
|
|
10
|
-
|
|
11
|
-
class PDFPageLeaf extends PDFDict {
|
|
12
|
-
static readonly InheritableEntries = ['Resources', 'MediaBox', 'CropBox', 'Rotate'];
|
|
13
|
-
|
|
14
|
-
static withContextAndParent = (context: PDFContext, parent: PDFRef) => {
|
|
15
|
-
const dict = new Map();
|
|
16
|
-
dict.set(PDFName.Type, PDFName.Page);
|
|
17
|
-
dict.set(PDFName.Parent, parent);
|
|
18
|
-
dict.set(PDFName.Resources, context.obj({}));
|
|
19
|
-
dict.set(PDFName.MediaBox, context.obj([0, 0, 612, 792]));
|
|
20
|
-
return new PDFPageLeaf(dict, context, false);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
static fromMapWithContext = (map: DictMap, context: PDFContext, autoNormalizeCTM = true) =>
|
|
24
|
-
new PDFPageLeaf(map, context, autoNormalizeCTM);
|
|
25
|
-
|
|
26
|
-
private normalized = false;
|
|
27
|
-
private readonly autoNormalizeCTM: boolean;
|
|
28
|
-
|
|
29
|
-
private constructor(map: DictMap, context: PDFContext, autoNormalizeCTM = true) {
|
|
30
|
-
super(map, context);
|
|
31
|
-
this.autoNormalizeCTM = autoNormalizeCTM;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
clone(context?: PDFContext): PDFPageLeaf {
|
|
35
|
-
const clone = PDFPageLeaf.fromMapWithContext(
|
|
36
|
-
new Map(),
|
|
37
|
-
context || this.context,
|
|
38
|
-
this.autoNormalizeCTM,
|
|
39
|
-
);
|
|
40
|
-
const entries = this.entries();
|
|
41
|
-
for (let idx = 0, len = entries.length; idx < len; idx++) {
|
|
42
|
-
const [key, value] = entries[idx];
|
|
43
|
-
clone.set(key, value);
|
|
44
|
-
}
|
|
45
|
-
return clone;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
Parent(): PDFPageTree | undefined {
|
|
49
|
-
return this.lookupMaybe(PDFName.Parent, PDFDict) as PDFPageTree | undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
Contents(): PDFStream | PDFArray | undefined {
|
|
53
|
-
return this.lookup(PDFName.of('Contents')) as PDFStream | PDFArray | undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Annots(): PDFArray | undefined {
|
|
57
|
-
return this.lookupMaybe(PDFName.Annots, PDFArray);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
BleedBox(): PDFArray | undefined {
|
|
61
|
-
return this.lookupMaybe(PDFName.BleedBox, PDFArray);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
TrimBox(): PDFArray | undefined {
|
|
65
|
-
return this.lookupMaybe(PDFName.TrimBox, PDFArray);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
ArtBox(): PDFArray | undefined {
|
|
69
|
-
return this.lookupMaybe(PDFName.ArtBox, PDFArray);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
Resources(): PDFDict | undefined {
|
|
73
|
-
const dictOrRef = this.getInheritableAttribute(PDFName.Resources);
|
|
74
|
-
return this.context.lookupMaybe(dictOrRef, PDFDict);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
MediaBox(): PDFArray {
|
|
78
|
-
const arrayOrRef = this.getInheritableAttribute(PDFName.MediaBox);
|
|
79
|
-
return this.context.lookup(arrayOrRef, PDFArray);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
CropBox(): PDFArray | undefined {
|
|
83
|
-
const arrayOrRef = this.getInheritableAttribute(PDFName.CropBox);
|
|
84
|
-
return this.context.lookupMaybe(arrayOrRef, PDFArray);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
Rotate(): PDFNumber | undefined {
|
|
88
|
-
const numberOrRef = this.getInheritableAttribute(PDFName.Rotate);
|
|
89
|
-
return this.context.lookupMaybe(numberOrRef, PDFNumber);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
getInheritableAttribute(name: PDFName): PDFObject | undefined {
|
|
93
|
-
let attribute: PDFObject | undefined;
|
|
94
|
-
this.ascend((node) => {
|
|
95
|
-
if (!attribute) attribute = node.get(name);
|
|
96
|
-
});
|
|
97
|
-
return attribute;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
setParent(parentRef: PDFRef): void {
|
|
101
|
-
this.set(PDFName.Parent, parentRef);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
addContentStream(contentStreamRef: PDFRef): void {
|
|
105
|
-
const Contents = this.normalizedEntries().Contents || this.context.obj([]);
|
|
106
|
-
this.set(PDFName.Contents, Contents);
|
|
107
|
-
Contents.push(contentStreamRef);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
wrapContentStreams(startStream: PDFRef, endStream: PDFRef): boolean {
|
|
111
|
-
const Contents = this.Contents();
|
|
112
|
-
if (Contents instanceof PDFArray) {
|
|
113
|
-
Contents.insert(0, startStream);
|
|
114
|
-
Contents.push(endStream);
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
addAnnot(annotRef: PDFRef): void {
|
|
121
|
-
const { Annots } = this.normalizedEntries();
|
|
122
|
-
Annots.push(annotRef);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
removeAnnot(annotRef: PDFRef) {
|
|
126
|
-
const { Annots } = this.normalizedEntries();
|
|
127
|
-
const index = Annots.indexOf(annotRef);
|
|
128
|
-
if (index !== undefined) {
|
|
129
|
-
Annots.remove(index);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
setFontDictionary(name: PDFName, fontDictRef: PDFRef): void {
|
|
134
|
-
const { Font } = this.normalizedEntries();
|
|
135
|
-
Font.set(name, fontDictRef);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
newFontDictionaryKey(tag: string): PDFName {
|
|
139
|
-
const { Font } = this.normalizedEntries();
|
|
140
|
-
return Font.uniqueKey(tag);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
newFontDictionary(tag: string, fontDictRef: PDFRef): PDFName {
|
|
144
|
-
const key = this.newFontDictionaryKey(tag);
|
|
145
|
-
this.setFontDictionary(key, fontDictRef);
|
|
146
|
-
return key;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
setXObject(name: PDFName, xObjectRef: PDFRef): void {
|
|
150
|
-
const { XObject } = this.normalizedEntries();
|
|
151
|
-
XObject.set(name, xObjectRef);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
newXObjectKey(tag: string): PDFName {
|
|
155
|
-
const { XObject } = this.normalizedEntries();
|
|
156
|
-
return XObject.uniqueKey(tag);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
newXObject(tag: string, xObjectRef: PDFRef): PDFName {
|
|
160
|
-
const key = this.newXObjectKey(tag);
|
|
161
|
-
this.setXObject(key, xObjectRef);
|
|
162
|
-
return key;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
setExtGState(name: PDFName, extGStateRef: PDFRef | PDFDict): void {
|
|
166
|
-
const { ExtGState } = this.normalizedEntries();
|
|
167
|
-
ExtGState.set(name, extGStateRef);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
newExtGStateKey(tag: string): PDFName {
|
|
171
|
-
const { ExtGState } = this.normalizedEntries();
|
|
172
|
-
return ExtGState.uniqueKey(tag);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
newExtGState(tag: string, extGStateRef: PDFRef | PDFDict): PDFName {
|
|
176
|
-
const key = this.newExtGStateKey(tag);
|
|
177
|
-
this.setExtGState(key, extGStateRef);
|
|
178
|
-
return key;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
ascend(visitor: (node: PDFPageTree | PDFPageLeaf) => any): void {
|
|
182
|
-
visitor(this);
|
|
183
|
-
const Parent = this.Parent();
|
|
184
|
-
if (Parent) Parent.ascend(visitor);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
normalize() {
|
|
188
|
-
if (this.normalized) return;
|
|
189
|
-
|
|
190
|
-
const { context } = this;
|
|
191
|
-
|
|
192
|
-
const contentsRef = this.get(PDFName.Contents);
|
|
193
|
-
const contents = this.context.lookup(contentsRef);
|
|
194
|
-
if (contents instanceof PDFStream) {
|
|
195
|
-
this.set(PDFName.Contents, context.obj([contentsRef]));
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (this.autoNormalizeCTM) {
|
|
199
|
-
this.wrapContentStreams(
|
|
200
|
-
this.context.getPushGraphicsStateContentStream(),
|
|
201
|
-
this.context.getPopGraphicsStateContentStream(),
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// TODO: Clone `Resources` if it is inherited
|
|
206
|
-
const dictOrRef = this.getInheritableAttribute(PDFName.Resources);
|
|
207
|
-
const Resources = context.lookupMaybe(dictOrRef, PDFDict) || context.obj({});
|
|
208
|
-
this.set(PDFName.Resources, Resources);
|
|
209
|
-
|
|
210
|
-
// TODO: Clone `Font` if it is inherited
|
|
211
|
-
const Font = Resources.lookupMaybe(PDFName.Font, PDFDict) || context.obj({});
|
|
212
|
-
Resources.set(PDFName.Font, Font);
|
|
213
|
-
|
|
214
|
-
// TODO: Clone `XObject` if it is inherited
|
|
215
|
-
const XObject = Resources.lookupMaybe(PDFName.XObject, PDFDict) || context.obj({});
|
|
216
|
-
Resources.set(PDFName.XObject, XObject);
|
|
217
|
-
|
|
218
|
-
// TODO: Clone `ExtGState` if it is inherited
|
|
219
|
-
const ExtGState = Resources.lookupMaybe(PDFName.ExtGState, PDFDict) || context.obj({});
|
|
220
|
-
Resources.set(PDFName.ExtGState, ExtGState);
|
|
221
|
-
|
|
222
|
-
const Annots = this.Annots() || context.obj([]);
|
|
223
|
-
this.set(PDFName.Annots, Annots);
|
|
224
|
-
|
|
225
|
-
this.normalized = true;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
normalizedEntries() {
|
|
229
|
-
this.normalize();
|
|
230
|
-
const Annots = this.Annots()!;
|
|
231
|
-
const Resources = this.Resources()!;
|
|
232
|
-
const Contents = this.Contents() as PDFArray | undefined;
|
|
233
|
-
return {
|
|
234
|
-
Annots,
|
|
235
|
-
Resources,
|
|
236
|
-
Contents,
|
|
237
|
-
Font: Resources.lookup(PDFName.Font, PDFDict),
|
|
238
|
-
XObject: Resources.lookup(PDFName.XObject, PDFDict),
|
|
239
|
-
ExtGState: Resources.lookup(PDFName.ExtGState, PDFDict),
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export default PDFPageLeaf;
|