@pdfme/pdf-lib 6.0.3-dev.0 → 6.0.4-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src/api/Embeddable.ts → dist/api/Embeddable.d.ts} +1 -1
- package/dist/api/PDFDocument.d.ts +778 -0
- package/dist/api/PDFDocumentOptions.d.ts +38 -0
- package/dist/api/PDFEmbeddedFile.d.ts +38 -0
- package/dist/api/PDFEmbeddedPage.d.ts +73 -0
- package/dist/api/PDFFont.d.ts +94 -0
- package/dist/api/PDFImage.d.ts +95 -0
- package/dist/api/PDFJavaScript.d.ts +38 -0
- package/dist/api/PDFPage.d.ts +910 -0
- package/dist/api/PDFPageOptions.d.ts +172 -0
- package/dist/api/StandardFonts.d.ts +16 -0
- package/dist/api/colors.d.ts +34 -0
- package/dist/api/errors.d.ts +42 -0
- package/dist/api/form/PDFButton.d.ts +137 -0
- package/dist/api/form/PDFCheckBox.d.ts +142 -0
- package/dist/api/form/PDFDropdown.d.ts +402 -0
- package/dist/api/form/PDFField.d.ts +203 -0
- package/dist/api/form/PDFForm.d.ts +411 -0
- package/dist/api/form/PDFOptionList.d.ts +335 -0
- package/dist/api/form/PDFRadioGroup.d.ts +252 -0
- package/dist/api/form/PDFSignature.d.ts +29 -0
- package/dist/api/form/PDFTextField.d.ts +537 -0
- package/dist/api/form/appearances.d.ts +41 -0
- package/dist/api/image/alignment.d.ts +5 -0
- package/dist/api/objects.d.ts +4 -0
- package/dist/api/operations.d.ts +226 -0
- package/dist/api/operators.d.ts +90 -0
- package/dist/api/rotations.d.ts +38 -0
- package/dist/api/sizes.d.ts +52 -0
- package/dist/api/svg.d.ts +70 -0
- package/dist/api/svgPath.d.ts +2 -0
- package/dist/api/text/alignment.d.ts +5 -0
- package/dist/api/text/layout.d.ts +54 -0
- package/dist/core/PDFContext.d.ts +84 -0
- package/dist/core/PDFObjectCopier.d.ts +37 -0
- package/dist/core/acroform/PDFAcroButton.d.ts +21 -0
- package/dist/core/acroform/PDFAcroCheckBox.d.ts +13 -0
- package/dist/core/acroform/PDFAcroChoice.d.ts +20 -0
- package/dist/core/acroform/PDFAcroComboBox.d.ts +9 -0
- package/dist/core/acroform/PDFAcroField.d.ts +36 -0
- package/dist/core/acroform/PDFAcroForm.d.ts +20 -0
- package/dist/core/acroform/PDFAcroListBox.d.ts +9 -0
- package/dist/core/acroform/PDFAcroNonTerminal.d.ts +13 -0
- package/dist/core/acroform/PDFAcroPushButton.d.ts +9 -0
- package/dist/core/acroform/PDFAcroRadioButton.d.ts +13 -0
- package/{src/core/acroform/PDFAcroSignature.ts → dist/core/acroform/PDFAcroSignature.d.ts} +2 -4
- package/dist/core/acroform/PDFAcroTerminal.d.ts +16 -0
- package/dist/core/acroform/PDFAcroText.d.ts +22 -0
- package/dist/core/acroform/flags.d.ts +141 -0
- package/dist/core/acroform/utils.d.ts +6 -0
- package/dist/core/annotation/AppearanceCharacteristics.d.ts +33 -0
- package/dist/core/annotation/BorderStyle.d.ts +11 -0
- package/dist/core/annotation/PDFAnnotation.d.ts +51 -0
- package/dist/core/annotation/PDFWidgetAnnotation.d.ts +26 -0
- package/dist/core/annotation/flags.d.ts +79 -0
- package/dist/core/crypto.d.ts +95 -0
- package/dist/core/document/PDFCrossRefSection.d.ts +27 -0
- package/dist/core/document/PDFHeader.d.ts +10 -0
- package/dist/core/document/PDFTrailer.d.ts +9 -0
- package/dist/core/document/PDFTrailerDict.d.ts +10 -0
- package/dist/core/embedders/CMap.d.ts +3 -0
- package/dist/core/embedders/CustomFontEmbedder.d.ts +44 -0
- package/dist/core/embedders/CustomFontSubsetEmbedder.d.ts +20 -0
- package/dist/core/embedders/FileEmbedder.d.ts +33 -0
- package/dist/core/embedders/FontFlags.d.ts +13 -0
- package/dist/core/embedders/JavaScriptEmbedder.d.ts +10 -0
- package/dist/core/embedders/JpegEmbedder.d.ts +23 -0
- package/dist/core/embedders/PDFPageEmbedder.d.ts +37 -0
- package/dist/core/embedders/PngEmbedder.d.ts +19 -0
- package/dist/core/embedders/StandardFontEmbedder.d.ts +36 -0
- package/dist/core/errors.d.ts +94 -0
- package/{src/core/index.ts → dist/core/index.d.ts} +1 -17
- package/dist/core/interactive/ViewerPreferences.d.ts +347 -0
- package/dist/core/objects/PDFArray.d.ts +63 -0
- package/dist/core/objects/PDFBool.d.ts +13 -0
- package/dist/core/objects/PDFDict.d.ts +62 -0
- package/dist/core/objects/PDFHexString.d.ts +16 -0
- package/dist/core/objects/PDFInvalidObject.d.ts +11 -0
- package/dist/core/objects/PDFName.d.ts +41 -0
- package/dist/core/objects/PDFNull.d.ts +10 -0
- package/dist/core/objects/PDFNumber.d.ts +15 -0
- package/dist/core/objects/PDFObject.d.ts +8 -0
- package/dist/core/objects/PDFRawStream.d.ts +16 -0
- package/dist/core/objects/PDFRef.d.ts +13 -0
- package/dist/core/objects/PDFStream.d.ts +16 -0
- package/dist/core/objects/PDFString.d.ts +16 -0
- package/dist/core/operators/PDFOperator.d.ts +19 -0
- package/dist/core/operators/PDFOperatorNames.d.ts +76 -0
- package/dist/core/parser/BaseParser.d.ts +14 -0
- package/dist/core/parser/ByteStream.d.ts +26 -0
- package/dist/core/parser/PDFObjectParser.d.ts +31 -0
- package/dist/core/parser/PDFObjectStreamParser.d.ts +13 -0
- package/dist/core/parser/PDFParser.d.ts +46 -0
- package/dist/core/parser/PDFXRefStreamParser.d.ts +21 -0
- package/dist/core/streams/Ascii85Stream.d.ts +9 -0
- package/dist/core/streams/AsciiHexStream.d.ts +9 -0
- package/dist/core/streams/DecodeStream.d.ts +26 -0
- package/dist/core/streams/DecryptStream.d.ts +12 -0
- package/dist/core/streams/FlateStream.d.ts +13 -0
- package/dist/core/streams/LZWStream.d.ts +12 -0
- package/dist/core/streams/RunLengthStream.d.ts +8 -0
- package/dist/core/streams/Stream.d.ts +34 -0
- package/dist/core/streams/decode.d.ts +3 -0
- package/dist/core/structures/PDFCatalog.d.ts +27 -0
- package/dist/core/structures/PDFContentStream.d.ts +15 -0
- package/dist/core/structures/PDFCrossRefStream.d.ts +53 -0
- package/dist/core/structures/PDFFlateStream.d.ts +13 -0
- package/dist/core/structures/PDFObjectStream.d.ts +20 -0
- package/dist/core/structures/PDFPageLeaf.d.ts +54 -0
- package/dist/core/structures/PDFPageTree.d.ts +41 -0
- package/dist/core/syntax/CharCodes.d.ts +61 -0
- package/dist/core/syntax/Delimiters.d.ts +1 -0
- package/dist/core/syntax/Irregular.d.ts +1 -0
- package/dist/core/syntax/Keywords.d.ts +22 -0
- package/dist/core/syntax/Numeric.d.ts +3 -0
- package/dist/core/syntax/Whitespace.d.ts +1 -0
- package/dist/core/writers/PDFStreamWriter.d.ts +19 -0
- package/dist/core/writers/PDFWriter.d.ts +29 -0
- package/dist/index.js +19124 -0
- package/dist/index.js.map +1 -0
- package/dist/types/fontkit.d.ts +597 -0
- package/{src/types/index.ts → dist/types/index.d.ts} +8 -13
- package/{src/types/matrix.ts → dist/types/matrix.d.ts} +1 -2
- package/dist/utils/Cache.d.ts +10 -0
- package/dist/utils/arrays.d.ts +16 -0
- package/dist/utils/async.d.ts +5 -0
- package/dist/utils/base64.d.ts +10 -0
- package/dist/utils/elements/Arc.d.ts +22 -0
- package/dist/utils/elements/Circle.d.ts +14 -0
- package/dist/utils/elements/Ellipse.d.ts +20 -0
- package/dist/utils/elements/GraphElement.d.ts +6 -0
- package/dist/utils/elements/Line.d.ts +23 -0
- package/dist/utils/elements/Plot.d.ts +11 -0
- package/dist/utils/elements/Point.d.ts +18 -0
- package/dist/utils/elements/Rectangle.d.ts +21 -0
- package/dist/utils/elements/Segment.d.ts +19 -0
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/intersections.d.ts +9 -0
- package/dist/utils/maths.d.ts +45 -0
- package/dist/utils/numbers.d.ts +23 -0
- package/dist/utils/objects.d.ts +15 -0
- package/dist/utils/pdfDocEncoding.d.ts +7 -0
- package/dist/utils/png.d.ts +17 -0
- package/dist/utils/rng.d.ts +13 -0
- package/dist/utils/strings.d.ts +25 -0
- package/{src/utils/unicode.ts → dist/utils/unicode.d.ts} +8 -195
- package/dist/utils/validators.d.ts +26 -0
- package/package.json +6 -1
- package/__tests__/api/PDFDocument.spec.ts +0 -576
- package/__tests__/api/PDFImage.spec.ts +0 -60
- package/__tests__/api/PDFPage.spec.ts +0 -151
- package/__tests__/api/form/PDFCheckBox.spec.ts +0 -71
- package/__tests__/api/form/PDFDropdown.spec.ts +0 -118
- package/__tests__/api/form/PDFForm.spec.ts +0 -370
- package/__tests__/api/form/PDFOptionList.spec.ts +0 -104
- package/__tests__/api/form/PDFRadioGroup.spec.ts +0 -183
- package/__tests__/api/form/PDFTextField.spec.ts +0 -148
- package/__tests__/api/svgPath.spec.ts +0 -153
- package/__tests__/api/text/layout.spec.ts +0 -166
- package/__tests__/core/PDFContext.spec.ts +0 -194
- package/__tests__/core/PDFObjectCopier.spec.ts +0 -421
- package/__tests__/core/acroform/PDFAcroField.spec.ts +0 -98
- package/__tests__/core/acroform/PDFAcroTerminal.spec.ts +0 -39
- package/__tests__/core/annotation/PDFWidgetAnnotation.spec.ts +0 -40
- package/__tests__/core/document/PDFCrossRefSection.spec.ts +0 -88
- package/__tests__/core/document/PDFHeader.spec.ts +0 -22
- package/__tests__/core/document/PDFTrailer.spec.ts +0 -28
- package/__tests__/core/document/PDFTrailerDict.spec.ts +0 -24
- package/__tests__/core/embedders/CMap.spec.ts +0 -47
- package/__tests__/core/embedders/CustomFontEmbedder.spec.ts +0 -96
- package/__tests__/core/embedders/CustomFontSubsetEmbedder.spec.ts +0 -62
- package/__tests__/core/embedders/FileEmbedder.spec.ts +0 -54
- package/__tests__/core/embedders/JpegEmbedder.spec.ts +0 -67
- package/__tests__/core/embedders/PDFPageEmbedder.spec.ts +0 -65
- package/__tests__/core/embedders/PngEmbedder.spec.ts +0 -87
- package/__tests__/core/embedders/StandardFontEmbedder.spec.ts +0 -79
- package/__tests__/core/embedders/data/SourceHanSerifJP-Regular.otf.cmap +0 -16096
- package/__tests__/core/embedders/data/Ubuntu-R.ttf.cmap +0 -1211
- package/__tests__/core/objects/PDFArray.spec.ts +0 -134
- package/__tests__/core/objects/PDFBool.spec.ts +0 -42
- package/__tests__/core/objects/PDFDict.spec.ts +0 -195
- package/__tests__/core/objects/PDFHexString.spec.ts +0 -168
- package/__tests__/core/objects/PDFInvalidObject.spec.ts +0 -32
- package/__tests__/core/objects/PDFName.spec.ts +0 -122
- package/__tests__/core/objects/PDFNull.spec.ts +0 -30
- package/__tests__/core/objects/PDFNumber.spec.ts +0 -50
- package/__tests__/core/objects/PDFObject.spec.ts +0 -29
- package/__tests__/core/objects/PDFRawStream.spec.ts +0 -45
- package/__tests__/core/objects/PDFRef.spec.ts +0 -60
- package/__tests__/core/objects/PDFString.spec.ts +0 -237
- package/__tests__/core/operators/PDFOperator.spec.ts +0 -77
- package/__tests__/core/parser/PDFObjectParser.spec.ts +0 -730
- package/__tests__/core/parser/PDFObjectStreamParser.spec.ts +0 -158
- package/__tests__/core/parser/PDFParser.spec.ts +0 -398
- package/__tests__/core/parser/PDFXRefStreamParser.spec.ts +0 -187
- package/__tests__/core/parser/data/object-stream-invalid +0 -2
- package/__tests__/core/parser/data/object-stream1 +0 -16
- package/__tests__/core/parser/data/object-stream2 +0 -10
- package/__tests__/core/parser/data/object-stream3 +0 -0
- package/__tests__/core/parser/data/object-stream4 +0 -0
- package/__tests__/core/parser/data/xref-stream1 +0 -0
- package/__tests__/core/parser/data/xref-stream2 +0 -0
- package/__tests__/core/parser/data/xref-stream3 +0 -0
- package/__tests__/core/parser/data/xref-stream4 +0 -0
- package/__tests__/core/streams/Ascii85Stream.spec.ts +0 -20
- package/__tests__/core/streams/AsciiHexStream.spec.ts +0 -20
- package/__tests__/core/streams/FlateStream.spec.ts +0 -20
- package/__tests__/core/streams/LZWStream.spec.ts +0 -20
- package/__tests__/core/streams/RunLengthStream.spec.ts +0 -20
- package/__tests__/core/streams/Stream.spec.ts +0 -128
- package/__tests__/core/streams/data/ascii85/1.decoded +0 -0
- package/__tests__/core/streams/data/ascii85/1.encoded +0 -43
- package/__tests__/core/streams/data/asciihex/1.decoded +0 -1
- package/__tests__/core/streams/data/asciihex/1.encoded +0 -1
- package/__tests__/core/streams/data/asciihex/2.decoded +0 -7
- package/__tests__/core/streams/data/asciihex/2.encoded +0 -1
- package/__tests__/core/streams/data/flate/1.corrupt.encoded +0 -1
- package/__tests__/core/streams/data/flate/1.decoded +0 -0
- package/__tests__/core/streams/data/flate/1.encoded +0 -2
- package/__tests__/core/streams/data/flate/2.decoded +0 -33
- package/__tests__/core/streams/data/flate/2.encoded +0 -0
- package/__tests__/core/streams/data/flate/3.decoded +0 -15
- package/__tests__/core/streams/data/flate/3.encoded +0 -0
- package/__tests__/core/streams/data/flate/4.decoded +0 -16
- package/__tests__/core/streams/data/flate/4.encoded +0 -0
- package/__tests__/core/streams/data/flate/5.decoded +0 -0
- package/__tests__/core/streams/data/flate/5.encoded +0 -0
- package/__tests__/core/streams/data/flate/6.decoded +0 -17
- package/__tests__/core/streams/data/flate/6.encoded +0 -0
- package/__tests__/core/streams/data/flate/7.decoded +0 -20
- package/__tests__/core/streams/data/flate/7.encoded +0 -1
- package/__tests__/core/streams/data/lzw/1.decoded +0 -0
- package/__tests__/core/streams/data/lzw/1.encoded +0 -0
- package/__tests__/core/streams/data/lzw/2.decoded +0 -0
- package/__tests__/core/streams/data/lzw/2.encoded +0 -0
- package/__tests__/core/streams/data/lzw/3.decoded +0 -14
- package/__tests__/core/streams/data/lzw/3.encoded +0 -2
- package/__tests__/core/streams/data/lzw/4.decoded +0 -14
- package/__tests__/core/streams/data/lzw/4.encoded +0 -2
- package/__tests__/core/streams/data/runlength/1.decoded +0 -1
- package/__tests__/core/streams/data/runlength/1.encoded +0 -1
- package/__tests__/core/streams/data/runlength/2.decoded +0 -1
- package/__tests__/core/streams/data/runlength/2.encoded +0 -1
- package/__tests__/core/streams/data/runlength/3.decoded +0 -0
- package/__tests__/core/streams/data/runlength/3.encoded +0 -0
- package/__tests__/core/streams/data/runlength/4.decoded +0 -1
- package/__tests__/core/streams/data/runlength/4.encoded +0 -1
- package/__tests__/core/streams/data/runlength/5.decoded +0 -1
- package/__tests__/core/streams/data/runlength/5.encoded +0 -1
- package/__tests__/core/streams/data/runlength/empty.encoded +0 -1
- package/__tests__/core/structures/PDFCatalog.spec.ts +0 -108
- package/__tests__/core/structures/PDFContentStream.spec.ts +0 -117
- package/__tests__/core/structures/PDFCrossRefStream.spec.ts +0 -145
- package/__tests__/core/structures/PDFObjectStream.spec.ts +0 -138
- package/__tests__/core/structures/PDFPageLeaf.spec.ts +0 -355
- package/__tests__/core/structures/PDFPageTree.spec.ts +0 -592
- package/__tests__/core/writers/PDFStreamWriter.spec.ts +0 -71
- package/__tests__/core/writers/PDFWriter.spec.ts +0 -144
- package/__tests__/core/writers/data/stream-writer-1.pdf +0 -0
- package/__tests__/index.test.ts +0 -12
- package/__tests__/utils/base64.spec.ts +0 -61
- package/__tests__/utils/data/simple.pdf +0 -201
- package/__tests__/utils/data/simple.pdf.base64 +0 -1
- package/__tests__/utils/pdfDocEncoding.spec.ts +0 -82
- package/__tests__/utils/png.spec.ts +0 -53
- package/__tests__/utils/rng.spec.ts +0 -14
- package/__tests__/utils/strings.spec.ts +0 -98
- package/__tests__/utils/unicode.spec.ts +0 -337
- package/assets/fonts/source_hans_jp/SourceHanSerifJP-Regular.otf +0 -0
- package/assets/fonts/ubuntu/Ubuntu-B.ttf +0 -0
- package/assets/fonts/ubuntu/Ubuntu-R.ttf +0 -0
- package/assets/images/cat_riding_unicorn.jpg +0 -0
- package/assets/images/cmyk_colorspace.jpg +0 -0
- package/assets/images/greyscale_bird.png +0 -0
- package/assets/images/minions_banana_alpha.png +0 -0
- package/assets/images/minions_banana_no_alpha.png +0 -0
- package/assets/images/minions_laughing.jpg +0 -0
- package/assets/pdfs/bixby_guide.pdf +0 -0
- package/assets/pdfs/encrypted_new.pdf +0 -0
- package/assets/pdfs/encrypted_old.pdf +0 -0
- package/assets/pdfs/fancy_fields.pdf +0 -0
- package/assets/pdfs/giraffe.pdf +0 -0
- package/assets/pdfs/invalid_root_ref.pdf +0 -0
- package/assets/pdfs/just_metadata.pdf +0 -49
- package/assets/pdfs/missing_endobj_keyword.pdf +0 -70
- package/assets/pdfs/missing_xref_trailer_dict.pdf +0 -141
- package/assets/pdfs/normal.pdf +0 -0
- package/assets/pdfs/pdf20examples/PDF 2.0 with offset start.pdf +0 -179
- package/assets/pdfs/stuff_following_header.pdf +0 -0
- package/assets/pdfs/us_constitution.pdf +0 -0
- package/assets/pdfs/with_comments.pdf +0 -0
- package/assets/pdfs/with_invalid_objects.pdf +0 -53
- package/assets/pdfs/with_invalid_stream_EOL.pdf +0 -0
- package/assets/pdfs/with_null_parent_entry.pdf +0 -0
- package/assets/pdfs/with_signature.pdf +0 -0
- package/assets/pdfs/with_update_sections.pdf +0 -0
- package/assets/pdfs/with_viewer_prefs.pdf +0 -0
- package/assets/pdfs/with_xfa_fields.pdf +0 -0
- package/src/api/PDFDocument.ts +0 -1389
- package/src/api/PDFDocumentOptions.ts +0 -45
- package/src/api/PDFEmbeddedFile.ts +0 -87
- package/src/api/PDFEmbeddedPage.ts +0 -100
- package/src/api/PDFFont.ts +0 -149
- package/src/api/PDFImage.ts +0 -143
- package/src/api/PDFJavaScript.ts +0 -75
- package/src/api/PDFPage.ts +0 -1604
- package/src/api/PDFPageOptions.ts +0 -175
- package/src/api/StandardFonts.ts +0 -16
- package/src/api/colors.ts +0 -109
- package/src/api/errors.ts +0 -110
- package/src/api/form/PDFButton.ts +0 -242
- package/src/api/form/PDFCheckBox.ts +0 -247
- package/src/api/form/PDFDropdown.ts +0 -637
- package/src/api/form/PDFField.ts +0 -491
- package/src/api/form/PDFForm.ts +0 -842
- package/src/api/form/PDFOptionList.ts +0 -555
- package/src/api/form/PDFRadioGroup.ts +0 -455
- package/src/api/form/PDFSignature.ts +0 -44
- package/src/api/form/PDFTextField.ts +0 -811
- package/src/api/form/appearances.ts +0 -655
- package/src/api/image/alignment.ts +0 -5
- package/src/api/objects.ts +0 -10
- package/src/api/operations.ts +0 -873
- package/src/api/operators.ts +0 -335
- package/src/api/rotations.ts +0 -84
- package/src/api/sizes.ts +0 -52
- package/src/api/svg.ts +0 -888
- package/src/api/svgPath.ts +0 -460
- package/src/api/text/alignment.ts +0 -5
- package/src/api/text/layout.ts +0 -328
- package/src/core/PDFContext.ts +0 -274
- package/src/core/PDFObjectCopier.ts +0 -142
- package/src/core/acroform/PDFAcroButton.ts +0 -104
- package/src/core/acroform/PDFAcroCheckBox.ts +0 -48
- package/src/core/acroform/PDFAcroChoice.ts +0 -143
- package/src/core/acroform/PDFAcroComboBox.ts +0 -21
- package/src/core/acroform/PDFAcroField.ts +0 -168
- package/src/core/acroform/PDFAcroForm.ts +0 -96
- package/src/core/acroform/PDFAcroListBox.ts +0 -19
- package/src/core/acroform/PDFAcroNonTerminal.ts +0 -33
- package/src/core/acroform/PDFAcroPushButton.ts +0 -21
- package/src/core/acroform/PDFAcroRadioButton.ts +0 -57
- package/src/core/acroform/PDFAcroTerminal.ts +0 -70
- package/src/core/acroform/PDFAcroText.ts +0 -76
- package/src/core/acroform/flags.ts +0 -162
- package/src/core/acroform/utils.ts +0 -129
- package/src/core/annotation/AppearanceCharacteristics.ts +0 -133
- package/src/core/annotation/BorderStyle.ts +0 -31
- package/src/core/annotation/PDFAnnotation.ts +0 -148
- package/src/core/annotation/PDFWidgetAnnotation.ts +0 -111
- package/src/core/annotation/flags.ts +0 -90
- package/src/core/crypto.ts +0 -1844
- package/src/core/document/PDFCrossRefSection.ts +0 -161
- package/src/core/document/PDFHeader.ts +0 -48
- package/src/core/document/PDFTrailer.ts +0 -48
- package/src/core/document/PDFTrailerDict.ts +0 -39
- package/src/core/embedders/CMap.ts +0 -65
- package/src/core/embedders/CustomFontEmbedder.ts +0 -237
- package/src/core/embedders/CustomFontSubsetEmbedder.ts +0 -89
- package/src/core/embedders/FileEmbedder.ts +0 -77
- package/src/core/embedders/FontFlags.ts +0 -45
- package/src/core/embedders/JavaScriptEmbedder.ts +0 -34
- package/src/core/embedders/JpegEmbedder.ts +0 -118
- package/src/core/embedders/PDFPageEmbedder.ts +0 -139
- package/src/core/embedders/PngEmbedder.ts +0 -69
- package/src/core/embedders/StandardFontEmbedder.ts +0 -121
- package/src/core/errors.ts +0 -226
- package/src/core/interactive/ViewerPreferences.ts +0 -565
- package/src/core/objects/PDFArray.ts +0 -179
- package/src/core/objects/PDFBool.ts +0 -53
- package/src/core/objects/PDFDict.ts +0 -220
- package/src/core/objects/PDFHexString.ts +0 -94
- package/src/core/objects/PDFInvalidObject.ts +0 -34
- package/src/core/objects/PDFName.ts +0 -152
- package/src/core/objects/PDFNull.ts +0 -30
- package/src/core/objects/PDFNumber.ts +0 -44
- package/src/core/objects/PDFObject.ts +0 -22
- package/src/core/objects/PDFRawStream.ts +0 -41
- package/src/core/objects/PDFRef.ts +0 -51
- package/src/core/objects/PDFStream.ts +0 -87
- package/src/core/objects/PDFString.ts +0 -118
- package/src/core/operators/PDFOperator.ts +0 -72
- package/src/core/operators/PDFOperatorNames.ts +0 -92
- package/src/core/parser/BaseParser.ts +0 -119
- package/src/core/parser/ByteStream.ts +0 -76
- package/src/core/parser/PDFObjectParser.ts +0 -302
- package/src/core/parser/PDFObjectStreamParser.ts +0 -65
- package/src/core/parser/PDFParser.ts +0 -363
- package/src/core/parser/PDFXRefStreamParser.ts +0 -129
- package/src/core/streams/Ascii85Stream.ts +0 -97
- package/src/core/streams/AsciiHexStream.ts +0 -77
- package/src/core/streams/DecodeStream.ts +0 -188
- package/src/core/streams/DecryptStream.ts +0 -49
- package/src/core/streams/FlateStream.ts +0 -397
- package/src/core/streams/LZWStream.ts +0 -157
- package/src/core/streams/RunLengthStream.ts +0 -55
- package/src/core/streams/Stream.ts +0 -126
- package/src/core/streams/decode.ts +0 -70
- package/src/core/structures/PDFCatalog.ts +0 -81
- package/src/core/structures/PDFContentStream.ts +0 -58
- package/src/core/structures/PDFCrossRefStream.ts +0 -238
- package/src/core/structures/PDFFlateStream.ts +0 -40
- package/src/core/structures/PDFObjectStream.ts +0 -91
- package/src/core/structures/PDFPageLeaf.ts +0 -244
- package/src/core/structures/PDFPageTree.ts +0 -192
- package/src/core/syntax/CharCodes.ts +0 -62
- package/src/core/syntax/Delimiters.ts +0 -14
- package/src/core/syntax/Irregular.ts +0 -10
- package/src/core/syntax/Keywords.ts +0 -57
- package/src/core/syntax/Numeric.ts +0 -26
- package/src/core/syntax/Whitespace.ts +0 -10
- package/src/core/writers/PDFStreamWriter.ts +0 -114
- package/src/core/writers/PDFWriter.ts +0 -146
- package/src/types/fontkit.ts +0 -643
- package/src/utils/Cache.ts +0 -26
- package/src/utils/arrays.ts +0 -153
- package/src/utils/async.ts +0 -8
- package/src/utils/base64.ts +0 -98
- package/src/utils/elements/Arc.ts +0 -97
- package/src/utils/elements/Circle.ts +0 -47
- package/src/utils/elements/Ellipse.ts +0 -117
- package/src/utils/elements/GraphElement.ts +0 -14
- package/src/utils/elements/Line.ts +0 -83
- package/src/utils/elements/Plot.ts +0 -50
- package/src/utils/elements/Point.ts +0 -37
- package/src/utils/elements/Rectangle.ts +0 -65
- package/src/utils/elements/Segment.ts +0 -81
- package/src/utils/errors.ts +0 -3
- package/src/utils/intersections.ts +0 -237
- package/src/utils/maths.ts +0 -96
- package/src/utils/numbers.ts +0 -55
- package/src/utils/objects.ts +0 -13
- package/src/utils/pdfDocEncoding.ts +0 -69
- package/src/utils/png.ts +0 -100
- package/src/utils/rng.ts +0 -21
- package/src/utils/strings.ts +0 -191
- package/src/utils/validators.ts +0 -192
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -15
- package/vite.config.mts +0 -39
- /package/{src/api/form/index.ts → dist/api/form/index.d.ts} +0 -0
- /package/{src/api/image/index.ts → dist/api/image/index.d.ts} +0 -0
- /package/{src/api/index.ts → dist/api/index.d.ts} +0 -0
- /package/{src/api/text/index.ts → dist/api/text/index.d.ts} +0 -0
- /package/{src/core/acroform/index.ts → dist/core/acroform/index.d.ts} +0 -0
- /package/{src/core/annotation/index.ts → dist/core/annotation/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/utils/elements/index.ts → dist/utils/elements/index.d.ts} +0 -0
- /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
package/src/api/text/layout.ts
DELETED
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import PDFFont from '../PDFFont';
|
|
2
|
-
import { CombedTextLayoutError } from '../errors';
|
|
3
|
-
import { TextAlignment } from './alignment';
|
|
4
|
-
|
|
5
|
-
import { PDFHexString } from '../../core';
|
|
6
|
-
import { cleanText, lineSplit, mergeLines, charAtIndex, charSplit } from '../../utils';
|
|
7
|
-
|
|
8
|
-
export interface TextPosition {
|
|
9
|
-
text: string;
|
|
10
|
-
encoded: PDFHexString;
|
|
11
|
-
x: number;
|
|
12
|
-
y: number;
|
|
13
|
-
width: number;
|
|
14
|
-
height: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface LayoutBounds {
|
|
18
|
-
x: number;
|
|
19
|
-
y: number;
|
|
20
|
-
width: number;
|
|
21
|
-
height: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const MIN_FONT_SIZE = 4;
|
|
25
|
-
const MAX_FONT_SIZE = 500;
|
|
26
|
-
|
|
27
|
-
const computeFontSize = (
|
|
28
|
-
lines: string[],
|
|
29
|
-
font: PDFFont,
|
|
30
|
-
bounds: LayoutBounds,
|
|
31
|
-
multiline: boolean = false,
|
|
32
|
-
) => {
|
|
33
|
-
let fontSize = MIN_FONT_SIZE;
|
|
34
|
-
|
|
35
|
-
while (fontSize < MAX_FONT_SIZE) {
|
|
36
|
-
let linesUsed = 0;
|
|
37
|
-
|
|
38
|
-
for (let lineIdx = 0, lineLen = lines.length; lineIdx < lineLen; lineIdx++) {
|
|
39
|
-
linesUsed += 1;
|
|
40
|
-
|
|
41
|
-
const line = lines[lineIdx];
|
|
42
|
-
const words = line.split(' ');
|
|
43
|
-
|
|
44
|
-
// Layout the words using the current `fontSize`, line wrapping
|
|
45
|
-
// whenever we reach the end of the current line.
|
|
46
|
-
let spaceInLineRemaining = bounds.width;
|
|
47
|
-
for (let idx = 0, len = words.length; idx < len; idx++) {
|
|
48
|
-
const isLastWord = idx === len - 1;
|
|
49
|
-
const word = isLastWord ? words[idx] : words[idx] + ' ';
|
|
50
|
-
const widthOfWord = font.widthOfTextAtSize(word, fontSize);
|
|
51
|
-
spaceInLineRemaining -= widthOfWord;
|
|
52
|
-
if (spaceInLineRemaining <= 0) {
|
|
53
|
-
linesUsed += 1;
|
|
54
|
-
spaceInLineRemaining = bounds.width - widthOfWord;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Return if we exceeded the allowed width
|
|
60
|
-
if (!multiline && linesUsed > lines.length) return fontSize - 1;
|
|
61
|
-
|
|
62
|
-
const height = font.heightAtSize(fontSize);
|
|
63
|
-
const lineHeight = height + height * 0.2;
|
|
64
|
-
const totalHeight = lineHeight * linesUsed;
|
|
65
|
-
|
|
66
|
-
// Return if we exceeded the allowed height
|
|
67
|
-
if (totalHeight > Math.abs(bounds.height)) return fontSize - 1;
|
|
68
|
-
|
|
69
|
-
fontSize += 1;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return fontSize;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const computeCombedFontSize = (
|
|
76
|
-
line: string,
|
|
77
|
-
font: PDFFont,
|
|
78
|
-
bounds: LayoutBounds,
|
|
79
|
-
cellCount: number,
|
|
80
|
-
) => {
|
|
81
|
-
const cellWidth = bounds.width / cellCount;
|
|
82
|
-
const cellHeight = bounds.height;
|
|
83
|
-
|
|
84
|
-
let fontSize = MIN_FONT_SIZE;
|
|
85
|
-
|
|
86
|
-
const chars = charSplit(line);
|
|
87
|
-
while (fontSize < MAX_FONT_SIZE) {
|
|
88
|
-
for (let idx = 0, len = chars.length; idx < len; idx++) {
|
|
89
|
-
const c = chars[idx];
|
|
90
|
-
const tooLong = font.widthOfTextAtSize(c, fontSize) > cellWidth * 0.75;
|
|
91
|
-
if (tooLong) return fontSize - 1;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const height = font.heightAtSize(fontSize, { descender: false });
|
|
95
|
-
if (height > cellHeight) return fontSize - 1;
|
|
96
|
-
|
|
97
|
-
fontSize += 1;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return fontSize;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export interface LayoutTextOptions {
|
|
104
|
-
alignment: TextAlignment;
|
|
105
|
-
fontSize?: number;
|
|
106
|
-
font: PDFFont;
|
|
107
|
-
bounds: LayoutBounds;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export interface MultilineTextLayout {
|
|
111
|
-
bounds: LayoutBounds;
|
|
112
|
-
lines: TextPosition[];
|
|
113
|
-
fontSize: number;
|
|
114
|
-
lineHeight: number;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const lastIndexOfWhitespace = (line: string) => {
|
|
118
|
-
for (let idx = line.length; idx > 0; idx--) {
|
|
119
|
-
if (/\s/.test(line[idx])) return idx;
|
|
120
|
-
}
|
|
121
|
-
return undefined;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const splitOutLines = (input: string, maxWidth: number, font: PDFFont, fontSize: number) => {
|
|
125
|
-
let lastWhitespaceIdx = input.length;
|
|
126
|
-
while (lastWhitespaceIdx > 0) {
|
|
127
|
-
const line = input.substring(0, lastWhitespaceIdx);
|
|
128
|
-
const encoded = font.encodeText(line);
|
|
129
|
-
const width = font.widthOfTextAtSize(line, fontSize);
|
|
130
|
-
if (width < maxWidth) {
|
|
131
|
-
const remainder = input.substring(lastWhitespaceIdx) || undefined;
|
|
132
|
-
return { line, encoded, width, remainder };
|
|
133
|
-
}
|
|
134
|
-
lastWhitespaceIdx = lastIndexOfWhitespace(line) ?? 0;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// We were unable to split the input enough to get a chunk that would fit
|
|
138
|
-
// within the specified `maxWidth` so we'll just return everything
|
|
139
|
-
return {
|
|
140
|
-
line: input,
|
|
141
|
-
encoded: font.encodeText(input),
|
|
142
|
-
width: font.widthOfTextAtSize(input, fontSize),
|
|
143
|
-
remainder: undefined,
|
|
144
|
-
};
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const layoutMultilineText = (
|
|
148
|
-
text: string,
|
|
149
|
-
{ alignment, fontSize, font, bounds }: LayoutTextOptions,
|
|
150
|
-
): MultilineTextLayout => {
|
|
151
|
-
const lines = lineSplit(cleanText(text));
|
|
152
|
-
|
|
153
|
-
if (fontSize === undefined || fontSize === 0) {
|
|
154
|
-
fontSize = computeFontSize(lines, font, bounds, true);
|
|
155
|
-
}
|
|
156
|
-
const height = font.heightAtSize(fontSize);
|
|
157
|
-
const lineHeight = height + height * 0.2;
|
|
158
|
-
|
|
159
|
-
const textLines: TextPosition[] = [];
|
|
160
|
-
|
|
161
|
-
let minX = bounds.x;
|
|
162
|
-
let minY = bounds.y;
|
|
163
|
-
let maxX = bounds.x + bounds.width;
|
|
164
|
-
let maxY = bounds.y + bounds.height;
|
|
165
|
-
|
|
166
|
-
let y = bounds.y + bounds.height;
|
|
167
|
-
for (let idx = 0, len = lines.length; idx < len; idx++) {
|
|
168
|
-
let prevRemainder: string | undefined = lines[idx];
|
|
169
|
-
while (prevRemainder !== undefined) {
|
|
170
|
-
const { line, encoded, width, remainder } = splitOutLines(
|
|
171
|
-
prevRemainder,
|
|
172
|
-
bounds.width,
|
|
173
|
-
font,
|
|
174
|
-
fontSize,
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
// prettier-ignore
|
|
178
|
-
const x = (
|
|
179
|
-
alignment === TextAlignment.Left ? bounds.x
|
|
180
|
-
: alignment === TextAlignment.Center ? bounds.x + (bounds.width / 2) - (width / 2)
|
|
181
|
-
: alignment === TextAlignment.Right ? bounds.x + bounds.width - width
|
|
182
|
-
: bounds.x
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
y -= lineHeight;
|
|
186
|
-
|
|
187
|
-
if (x < minX) minX = x;
|
|
188
|
-
if (y < minY) minY = y;
|
|
189
|
-
if (x + width > maxX) maxX = x + width;
|
|
190
|
-
if (y + height > maxY) maxY = y + height;
|
|
191
|
-
|
|
192
|
-
textLines.push({ text: line, encoded, width, height, x, y });
|
|
193
|
-
|
|
194
|
-
// Only trim lines that we had to split ourselves. So we won't trim lines
|
|
195
|
-
// that the user provided themselves with whitespace.
|
|
196
|
-
prevRemainder = remainder?.trim();
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
fontSize,
|
|
202
|
-
lineHeight,
|
|
203
|
-
lines: textLines,
|
|
204
|
-
bounds: {
|
|
205
|
-
x: minX,
|
|
206
|
-
y: minY,
|
|
207
|
-
width: maxX - minX,
|
|
208
|
-
height: maxY - minY,
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
export interface LayoutCombedTextOptions {
|
|
214
|
-
fontSize?: number;
|
|
215
|
-
font: PDFFont;
|
|
216
|
-
bounds: LayoutBounds;
|
|
217
|
-
cellCount: number;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export interface CombedTextLayout {
|
|
221
|
-
bounds: LayoutBounds;
|
|
222
|
-
cells: TextPosition[];
|
|
223
|
-
fontSize: number;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export const layoutCombedText = (
|
|
227
|
-
text: string,
|
|
228
|
-
{ fontSize, font, bounds, cellCount }: LayoutCombedTextOptions,
|
|
229
|
-
): CombedTextLayout => {
|
|
230
|
-
const line = mergeLines(cleanText(text));
|
|
231
|
-
|
|
232
|
-
if (line.length > cellCount) {
|
|
233
|
-
throw new CombedTextLayoutError(line.length, cellCount);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (fontSize === undefined || fontSize === 0) {
|
|
237
|
-
fontSize = computeCombedFontSize(line, font, bounds, cellCount);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const cellWidth = bounds.width / cellCount;
|
|
241
|
-
|
|
242
|
-
const height = font.heightAtSize(fontSize, { descender: false });
|
|
243
|
-
const y = bounds.y + (bounds.height / 2 - height / 2);
|
|
244
|
-
|
|
245
|
-
const cells: TextPosition[] = [];
|
|
246
|
-
|
|
247
|
-
let minX = bounds.x;
|
|
248
|
-
let minY = bounds.y;
|
|
249
|
-
let maxX = bounds.x + bounds.width;
|
|
250
|
-
let maxY = bounds.y + bounds.height;
|
|
251
|
-
|
|
252
|
-
let cellOffset = 0;
|
|
253
|
-
let charOffset = 0;
|
|
254
|
-
while (cellOffset < cellCount) {
|
|
255
|
-
const [char, charLength] = charAtIndex(line, charOffset);
|
|
256
|
-
|
|
257
|
-
const encoded = font.encodeText(char);
|
|
258
|
-
const width = font.widthOfTextAtSize(char, fontSize);
|
|
259
|
-
|
|
260
|
-
const cellCenter = bounds.x + (cellWidth * cellOffset + cellWidth / 2);
|
|
261
|
-
const x = cellCenter - width / 2;
|
|
262
|
-
|
|
263
|
-
if (x < minX) minX = x;
|
|
264
|
-
if (y < minY) minY = y;
|
|
265
|
-
if (x + width > maxX) maxX = x + width;
|
|
266
|
-
if (y + height > maxY) maxY = y + height;
|
|
267
|
-
|
|
268
|
-
cells.push({ text: line, encoded, width, height, x, y });
|
|
269
|
-
|
|
270
|
-
cellOffset += 1;
|
|
271
|
-
charOffset += charLength;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return {
|
|
275
|
-
fontSize,
|
|
276
|
-
cells,
|
|
277
|
-
bounds: {
|
|
278
|
-
x: minX,
|
|
279
|
-
y: minY,
|
|
280
|
-
width: maxX - minX,
|
|
281
|
-
height: maxY - minY,
|
|
282
|
-
},
|
|
283
|
-
};
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
export interface LayoutSinglelineTextOptions {
|
|
287
|
-
alignment: TextAlignment;
|
|
288
|
-
fontSize?: number;
|
|
289
|
-
font: PDFFont;
|
|
290
|
-
bounds: LayoutBounds;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
export interface SinglelineTextLayout {
|
|
294
|
-
bounds: LayoutBounds;
|
|
295
|
-
line: TextPosition;
|
|
296
|
-
fontSize: number;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export const layoutSinglelineText = (
|
|
300
|
-
text: string,
|
|
301
|
-
{ alignment, fontSize, font, bounds }: LayoutSinglelineTextOptions,
|
|
302
|
-
): SinglelineTextLayout => {
|
|
303
|
-
const line = mergeLines(cleanText(text));
|
|
304
|
-
|
|
305
|
-
if (fontSize === undefined || fontSize === 0) {
|
|
306
|
-
fontSize = computeFontSize([line], font, bounds);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const encoded = font.encodeText(line);
|
|
310
|
-
const width = font.widthOfTextAtSize(line, fontSize);
|
|
311
|
-
const height = font.heightAtSize(fontSize, { descender: false });
|
|
312
|
-
|
|
313
|
-
// prettier-ignore
|
|
314
|
-
const x = (
|
|
315
|
-
alignment === TextAlignment.Left ? bounds.x
|
|
316
|
-
: alignment === TextAlignment.Center ? bounds.x + (bounds.width / 2) - (width / 2)
|
|
317
|
-
: alignment === TextAlignment.Right ? bounds.x + bounds.width - width
|
|
318
|
-
: bounds.x
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
const y = bounds.y + (bounds.height / 2 - height / 2);
|
|
322
|
-
|
|
323
|
-
return {
|
|
324
|
-
fontSize,
|
|
325
|
-
line: { text: line, encoded, width, height, x, y },
|
|
326
|
-
bounds: { x, y, width, height },
|
|
327
|
-
};
|
|
328
|
-
};
|
package/src/core/PDFContext.ts
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
import pako from 'pako';
|
|
2
|
-
|
|
3
|
-
import PDFHeader from './document/PDFHeader';
|
|
4
|
-
import { UnexpectedObjectTypeError } from './errors';
|
|
5
|
-
import PDFArray from './objects/PDFArray';
|
|
6
|
-
import PDFBool from './objects/PDFBool';
|
|
7
|
-
import PDFDict from './objects/PDFDict';
|
|
8
|
-
import PDFHexString from './objects/PDFHexString';
|
|
9
|
-
import PDFName from './objects/PDFName';
|
|
10
|
-
import PDFNull from './objects/PDFNull';
|
|
11
|
-
import PDFNumber from './objects/PDFNumber';
|
|
12
|
-
import PDFObject from './objects/PDFObject';
|
|
13
|
-
import PDFRawStream from './objects/PDFRawStream';
|
|
14
|
-
import PDFRef from './objects/PDFRef';
|
|
15
|
-
import PDFStream from './objects/PDFStream';
|
|
16
|
-
import PDFString from './objects/PDFString';
|
|
17
|
-
import PDFOperator from './operators/PDFOperator';
|
|
18
|
-
import Ops from './operators/PDFOperatorNames';
|
|
19
|
-
import PDFContentStream from './structures/PDFContentStream';
|
|
20
|
-
import { typedArrayFor } from '../utils';
|
|
21
|
-
import { SimpleRNG } from '../utils/rng';
|
|
22
|
-
|
|
23
|
-
type LookupKey = PDFRef | PDFObject | undefined;
|
|
24
|
-
|
|
25
|
-
interface LiteralObject {
|
|
26
|
-
[name: string]: Literal | PDFObject;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface LiteralArray {
|
|
30
|
-
[index: number]: Literal | PDFObject;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type Literal = LiteralObject | LiteralArray | string | number | boolean | null | undefined;
|
|
34
|
-
|
|
35
|
-
const byAscendingObjectNumber = ([a]: [PDFRef, PDFObject], [b]: [PDFRef, PDFObject]) =>
|
|
36
|
-
a.objectNumber - b.objectNumber;
|
|
37
|
-
|
|
38
|
-
class PDFContext {
|
|
39
|
-
isDecrypted = true;
|
|
40
|
-
static create = () => new PDFContext();
|
|
41
|
-
|
|
42
|
-
largestObjectNumber: number;
|
|
43
|
-
header: PDFHeader;
|
|
44
|
-
trailerInfo: {
|
|
45
|
-
Root?: PDFObject;
|
|
46
|
-
Encrypt?: PDFObject;
|
|
47
|
-
Info?: PDFObject;
|
|
48
|
-
ID?: PDFObject;
|
|
49
|
-
};
|
|
50
|
-
rng: SimpleRNG;
|
|
51
|
-
|
|
52
|
-
private readonly indirectObjects: Map<PDFRef, PDFObject>;
|
|
53
|
-
|
|
54
|
-
private pushGraphicsStateContentStreamRef?: PDFRef;
|
|
55
|
-
private popGraphicsStateContentStreamRef?: PDFRef;
|
|
56
|
-
|
|
57
|
-
private constructor() {
|
|
58
|
-
this.largestObjectNumber = 0;
|
|
59
|
-
this.header = PDFHeader.forVersion(1, 7);
|
|
60
|
-
this.trailerInfo = {};
|
|
61
|
-
|
|
62
|
-
this.indirectObjects = new Map();
|
|
63
|
-
this.rng = SimpleRNG.withSeed(1);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
assign(ref: PDFRef, object: PDFObject): void {
|
|
67
|
-
this.indirectObjects.set(ref, object);
|
|
68
|
-
if (ref.objectNumber > this.largestObjectNumber) {
|
|
69
|
-
this.largestObjectNumber = ref.objectNumber;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
nextRef(): PDFRef {
|
|
74
|
-
this.largestObjectNumber += 1;
|
|
75
|
-
return PDFRef.of(this.largestObjectNumber);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
register(object: PDFObject): PDFRef {
|
|
79
|
-
const ref = this.nextRef();
|
|
80
|
-
this.assign(ref, object);
|
|
81
|
-
return ref;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
delete(ref: PDFRef): boolean {
|
|
85
|
-
return this.indirectObjects.delete(ref);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
lookupMaybe(ref: LookupKey, type: typeof PDFArray): PDFArray | undefined;
|
|
89
|
-
lookupMaybe(ref: LookupKey, type: typeof PDFBool): PDFBool | undefined;
|
|
90
|
-
lookupMaybe(ref: LookupKey, type: typeof PDFDict): PDFDict | undefined;
|
|
91
|
-
lookupMaybe(ref: LookupKey, type: typeof PDFHexString): PDFHexString | undefined;
|
|
92
|
-
lookupMaybe(ref: LookupKey, type: typeof PDFName): PDFName | undefined;
|
|
93
|
-
lookupMaybe(ref: LookupKey, type: typeof PDFNull): typeof PDFNull | undefined;
|
|
94
|
-
lookupMaybe(ref: LookupKey, type: typeof PDFNumber): PDFNumber | undefined;
|
|
95
|
-
lookupMaybe(ref: LookupKey, type: typeof PDFStream): PDFStream | undefined;
|
|
96
|
-
lookupMaybe(ref: LookupKey, type: typeof PDFRef): PDFRef | undefined;
|
|
97
|
-
lookupMaybe(ref: LookupKey, type: typeof PDFString): PDFString | undefined;
|
|
98
|
-
lookupMaybe(
|
|
99
|
-
ref: LookupKey,
|
|
100
|
-
type1: typeof PDFString,
|
|
101
|
-
type2: typeof PDFHexString,
|
|
102
|
-
): PDFString | PDFHexString | undefined;
|
|
103
|
-
|
|
104
|
-
lookupMaybe(ref: LookupKey, ...types: any[]) {
|
|
105
|
-
// TODO: `preservePDFNull` is for backwards compatibility. Should be
|
|
106
|
-
// removed in next breaking API change.
|
|
107
|
-
const preservePDFNull = types.includes(PDFNull);
|
|
108
|
-
|
|
109
|
-
const result = ref instanceof PDFRef ? this.indirectObjects.get(ref) : ref;
|
|
110
|
-
|
|
111
|
-
if (!result || (result === PDFNull && !preservePDFNull)) return undefined;
|
|
112
|
-
|
|
113
|
-
for (let idx = 0, len = types.length; idx < len; idx++) {
|
|
114
|
-
const type = types[idx];
|
|
115
|
-
if (type === PDFNull) {
|
|
116
|
-
if (result === PDFNull) return result;
|
|
117
|
-
} else {
|
|
118
|
-
if (result instanceof type) return result;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
throw new UnexpectedObjectTypeError(types, result);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
lookup(ref: LookupKey): PDFObject | undefined;
|
|
125
|
-
lookup(ref: LookupKey, type: typeof PDFArray): PDFArray;
|
|
126
|
-
lookup(ref: LookupKey, type: typeof PDFBool): PDFBool;
|
|
127
|
-
lookup(ref: LookupKey, type: typeof PDFDict): PDFDict;
|
|
128
|
-
lookup(ref: LookupKey, type: typeof PDFHexString): PDFHexString;
|
|
129
|
-
lookup(ref: LookupKey, type: typeof PDFName): PDFName;
|
|
130
|
-
lookup(ref: LookupKey, type: typeof PDFNull): typeof PDFNull;
|
|
131
|
-
lookup(ref: LookupKey, type: typeof PDFNumber): PDFNumber;
|
|
132
|
-
lookup(ref: LookupKey, type: typeof PDFStream): PDFStream;
|
|
133
|
-
lookup(ref: LookupKey, type: typeof PDFRef): PDFRef;
|
|
134
|
-
lookup(ref: LookupKey, type: typeof PDFString): PDFString;
|
|
135
|
-
lookup(
|
|
136
|
-
ref: LookupKey,
|
|
137
|
-
type1: typeof PDFString,
|
|
138
|
-
type2: typeof PDFHexString,
|
|
139
|
-
): PDFString | PDFHexString;
|
|
140
|
-
|
|
141
|
-
lookup(ref: LookupKey, ...types: any[]) {
|
|
142
|
-
const result = ref instanceof PDFRef ? this.indirectObjects.get(ref) : ref;
|
|
143
|
-
|
|
144
|
-
if (types.length === 0) return result;
|
|
145
|
-
|
|
146
|
-
for (let idx = 0, len = types.length; idx < len; idx++) {
|
|
147
|
-
const type = types[idx];
|
|
148
|
-
if (type === PDFNull) {
|
|
149
|
-
if (result === PDFNull) return result;
|
|
150
|
-
} else {
|
|
151
|
-
if (result instanceof type) return result;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
throw new UnexpectedObjectTypeError(types, result);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
getObjectRef(pdfObject: PDFObject): PDFRef | undefined {
|
|
159
|
-
const entries = Array.from(this.indirectObjects.entries());
|
|
160
|
-
for (let idx = 0, len = entries.length; idx < len; idx++) {
|
|
161
|
-
const [ref, object] = entries[idx];
|
|
162
|
-
if (object === pdfObject) {
|
|
163
|
-
return ref;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return undefined;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
enumerateIndirectObjects(): [PDFRef, PDFObject][] {
|
|
171
|
-
return Array.from(this.indirectObjects.entries()).sort(byAscendingObjectNumber);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
obj(literal: null | undefined): typeof PDFNull;
|
|
175
|
-
obj(literal: string): PDFName;
|
|
176
|
-
obj(literal: number): PDFNumber;
|
|
177
|
-
obj(literal: boolean): PDFBool;
|
|
178
|
-
obj(literal: LiteralObject): PDFDict;
|
|
179
|
-
obj(literal: LiteralArray): PDFArray;
|
|
180
|
-
|
|
181
|
-
obj(literal: Literal) {
|
|
182
|
-
if (literal instanceof PDFObject) {
|
|
183
|
-
return literal;
|
|
184
|
-
} else if (literal === null || literal === undefined) {
|
|
185
|
-
return PDFNull;
|
|
186
|
-
} else if (typeof literal === 'string') {
|
|
187
|
-
return PDFName.of(literal);
|
|
188
|
-
} else if (typeof literal === 'number') {
|
|
189
|
-
return PDFNumber.of(literal);
|
|
190
|
-
} else if (typeof literal === 'boolean') {
|
|
191
|
-
return literal ? PDFBool.True : PDFBool.False;
|
|
192
|
-
} else if (Array.isArray(literal)) {
|
|
193
|
-
const array = PDFArray.withContext(this);
|
|
194
|
-
for (let idx = 0, len = literal.length; idx < len; idx++) {
|
|
195
|
-
array.push(this.obj(literal[idx]));
|
|
196
|
-
}
|
|
197
|
-
return array;
|
|
198
|
-
} else {
|
|
199
|
-
const dict = PDFDict.withContext(this);
|
|
200
|
-
const keys = Object.keys(literal);
|
|
201
|
-
for (let idx = 0, len = keys.length; idx < len; idx++) {
|
|
202
|
-
const key = keys[idx];
|
|
203
|
-
const value = (literal as LiteralObject)[key] as any;
|
|
204
|
-
if (value !== undefined) dict.set(PDFName.of(key), this.obj(value));
|
|
205
|
-
}
|
|
206
|
-
return dict;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
stream(contents: string | Uint8Array, dict: LiteralObject = {}): PDFRawStream {
|
|
211
|
-
return PDFRawStream.of(this.obj(dict), typedArrayFor(contents));
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
flateStream(contents: string | Uint8Array, dict: LiteralObject = {}): PDFRawStream {
|
|
215
|
-
return this.stream(pako.deflate(typedArrayFor(contents)), {
|
|
216
|
-
...dict,
|
|
217
|
-
Filter: 'FlateDecode',
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
contentStream(operators: PDFOperator[], dict: LiteralObject = {}): PDFContentStream {
|
|
222
|
-
return PDFContentStream.of(this.obj(dict), operators);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
formXObject(operators: PDFOperator[], dict: LiteralObject = {}): PDFContentStream {
|
|
226
|
-
return this.contentStream(operators, {
|
|
227
|
-
BBox: this.obj([0, 0, 0, 0]),
|
|
228
|
-
Matrix: this.obj([1, 0, 0, 1, 0, 0]),
|
|
229
|
-
...dict,
|
|
230
|
-
Type: 'XObject',
|
|
231
|
-
Subtype: 'Form',
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/*
|
|
236
|
-
* Reference to PDFContentStream that contains a single PDFOperator: `q`.
|
|
237
|
-
* Used by [[PDFPageLeaf]] instances to ensure that when content streams are
|
|
238
|
-
* added to a modified PDF, they start in the default, unchanged graphics
|
|
239
|
-
* state.
|
|
240
|
-
*/
|
|
241
|
-
getPushGraphicsStateContentStream(): PDFRef {
|
|
242
|
-
if (this.pushGraphicsStateContentStreamRef) {
|
|
243
|
-
return this.pushGraphicsStateContentStreamRef;
|
|
244
|
-
}
|
|
245
|
-
const dict = this.obj({});
|
|
246
|
-
const op = PDFOperator.of(Ops.PushGraphicsState);
|
|
247
|
-
const stream = PDFContentStream.of(dict, [op]);
|
|
248
|
-
this.pushGraphicsStateContentStreamRef = this.register(stream);
|
|
249
|
-
return this.pushGraphicsStateContentStreamRef;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/*
|
|
253
|
-
* Reference to PDFContentStream that contains a single PDFOperator: `Q`.
|
|
254
|
-
* Used by [[PDFPageLeaf]] instances to ensure that when content streams are
|
|
255
|
-
* added to a modified PDF, they start in the default, unchanged graphics
|
|
256
|
-
* state.
|
|
257
|
-
*/
|
|
258
|
-
getPopGraphicsStateContentStream(): PDFRef {
|
|
259
|
-
if (this.popGraphicsStateContentStreamRef) {
|
|
260
|
-
return this.popGraphicsStateContentStreamRef;
|
|
261
|
-
}
|
|
262
|
-
const dict = this.obj({});
|
|
263
|
-
const op = PDFOperator.of(Ops.PopGraphicsState);
|
|
264
|
-
const stream = PDFContentStream.of(dict, [op]);
|
|
265
|
-
this.popGraphicsStateContentStreamRef = this.register(stream);
|
|
266
|
-
return this.popGraphicsStateContentStreamRef;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
addRandomSuffix(prefix: string, suffixLength = 4): string {
|
|
270
|
-
return `${prefix}-${Math.floor(this.rng.nextInt() * 10 ** suffixLength)}`;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export default PDFContext;
|