@pdfme/pdf-lib 6.0.3 → 6.0.4-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src/api/Embeddable.ts → dist/api/Embeddable.d.ts} +1 -1
- package/dist/api/PDFDocument.d.ts +778 -0
- package/dist/api/PDFDocumentOptions.d.ts +38 -0
- package/dist/api/PDFEmbeddedFile.d.ts +38 -0
- package/dist/api/PDFEmbeddedPage.d.ts +73 -0
- package/dist/api/PDFFont.d.ts +94 -0
- package/dist/api/PDFImage.d.ts +95 -0
- package/dist/api/PDFJavaScript.d.ts +38 -0
- package/dist/api/PDFPage.d.ts +910 -0
- package/dist/api/PDFPageOptions.d.ts +172 -0
- package/dist/api/StandardFonts.d.ts +16 -0
- package/dist/api/colors.d.ts +34 -0
- package/dist/api/errors.d.ts +42 -0
- package/dist/api/form/PDFButton.d.ts +137 -0
- package/dist/api/form/PDFCheckBox.d.ts +142 -0
- package/dist/api/form/PDFDropdown.d.ts +402 -0
- package/dist/api/form/PDFField.d.ts +203 -0
- package/dist/api/form/PDFForm.d.ts +411 -0
- package/dist/api/form/PDFOptionList.d.ts +335 -0
- package/dist/api/form/PDFRadioGroup.d.ts +252 -0
- package/dist/api/form/PDFSignature.d.ts +29 -0
- package/dist/api/form/PDFTextField.d.ts +537 -0
- package/dist/api/form/appearances.d.ts +41 -0
- package/dist/api/image/alignment.d.ts +5 -0
- package/dist/api/objects.d.ts +4 -0
- package/dist/api/operations.d.ts +226 -0
- package/dist/api/operators.d.ts +90 -0
- package/dist/api/rotations.d.ts +38 -0
- package/dist/api/sizes.d.ts +52 -0
- package/dist/api/svg.d.ts +70 -0
- package/dist/api/svgPath.d.ts +2 -0
- package/dist/api/text/alignment.d.ts +5 -0
- package/dist/api/text/layout.d.ts +54 -0
- package/dist/core/PDFContext.d.ts +84 -0
- package/dist/core/PDFObjectCopier.d.ts +37 -0
- package/dist/core/acroform/PDFAcroButton.d.ts +21 -0
- package/dist/core/acroform/PDFAcroCheckBox.d.ts +13 -0
- package/dist/core/acroform/PDFAcroChoice.d.ts +20 -0
- package/dist/core/acroform/PDFAcroComboBox.d.ts +9 -0
- package/dist/core/acroform/PDFAcroField.d.ts +36 -0
- package/dist/core/acroform/PDFAcroForm.d.ts +20 -0
- package/dist/core/acroform/PDFAcroListBox.d.ts +9 -0
- package/dist/core/acroform/PDFAcroNonTerminal.d.ts +13 -0
- package/dist/core/acroform/PDFAcroPushButton.d.ts +9 -0
- package/dist/core/acroform/PDFAcroRadioButton.d.ts +13 -0
- package/{src/core/acroform/PDFAcroSignature.ts → dist/core/acroform/PDFAcroSignature.d.ts} +2 -4
- package/dist/core/acroform/PDFAcroTerminal.d.ts +16 -0
- package/dist/core/acroform/PDFAcroText.d.ts +22 -0
- package/dist/core/acroform/flags.d.ts +141 -0
- package/dist/core/acroform/utils.d.ts +6 -0
- package/dist/core/annotation/AppearanceCharacteristics.d.ts +33 -0
- package/dist/core/annotation/BorderStyle.d.ts +11 -0
- package/dist/core/annotation/PDFAnnotation.d.ts +51 -0
- package/dist/core/annotation/PDFWidgetAnnotation.d.ts +26 -0
- package/dist/core/annotation/flags.d.ts +79 -0
- package/dist/core/crypto.d.ts +95 -0
- package/dist/core/document/PDFCrossRefSection.d.ts +27 -0
- package/dist/core/document/PDFHeader.d.ts +10 -0
- package/dist/core/document/PDFTrailer.d.ts +9 -0
- package/dist/core/document/PDFTrailerDict.d.ts +10 -0
- package/dist/core/embedders/CMap.d.ts +3 -0
- package/dist/core/embedders/CustomFontEmbedder.d.ts +44 -0
- package/dist/core/embedders/CustomFontSubsetEmbedder.d.ts +20 -0
- package/dist/core/embedders/FileEmbedder.d.ts +33 -0
- package/dist/core/embedders/FontFlags.d.ts +13 -0
- package/dist/core/embedders/JavaScriptEmbedder.d.ts +10 -0
- package/dist/core/embedders/JpegEmbedder.d.ts +23 -0
- package/dist/core/embedders/PDFPageEmbedder.d.ts +37 -0
- package/dist/core/embedders/PngEmbedder.d.ts +19 -0
- package/dist/core/embedders/StandardFontEmbedder.d.ts +36 -0
- package/dist/core/errors.d.ts +94 -0
- package/{src/core/index.ts → dist/core/index.d.ts} +1 -17
- package/dist/core/interactive/ViewerPreferences.d.ts +347 -0
- package/dist/core/objects/PDFArray.d.ts +63 -0
- package/dist/core/objects/PDFBool.d.ts +13 -0
- package/dist/core/objects/PDFDict.d.ts +62 -0
- package/dist/core/objects/PDFHexString.d.ts +16 -0
- package/dist/core/objects/PDFInvalidObject.d.ts +11 -0
- package/dist/core/objects/PDFName.d.ts +41 -0
- package/dist/core/objects/PDFNull.d.ts +10 -0
- package/dist/core/objects/PDFNumber.d.ts +15 -0
- package/dist/core/objects/PDFObject.d.ts +8 -0
- package/dist/core/objects/PDFRawStream.d.ts +16 -0
- package/dist/core/objects/PDFRef.d.ts +13 -0
- package/dist/core/objects/PDFStream.d.ts +16 -0
- package/dist/core/objects/PDFString.d.ts +16 -0
- package/dist/core/operators/PDFOperator.d.ts +19 -0
- package/dist/core/operators/PDFOperatorNames.d.ts +76 -0
- package/dist/core/parser/BaseParser.d.ts +14 -0
- package/dist/core/parser/ByteStream.d.ts +26 -0
- package/dist/core/parser/PDFObjectParser.d.ts +31 -0
- package/dist/core/parser/PDFObjectStreamParser.d.ts +13 -0
- package/dist/core/parser/PDFParser.d.ts +46 -0
- package/dist/core/parser/PDFXRefStreamParser.d.ts +21 -0
- package/dist/core/streams/Ascii85Stream.d.ts +9 -0
- package/dist/core/streams/AsciiHexStream.d.ts +9 -0
- package/dist/core/streams/DecodeStream.d.ts +26 -0
- package/dist/core/streams/DecryptStream.d.ts +12 -0
- package/dist/core/streams/FlateStream.d.ts +13 -0
- package/dist/core/streams/LZWStream.d.ts +12 -0
- package/dist/core/streams/RunLengthStream.d.ts +8 -0
- package/dist/core/streams/Stream.d.ts +34 -0
- package/dist/core/streams/decode.d.ts +3 -0
- package/dist/core/structures/PDFCatalog.d.ts +27 -0
- package/dist/core/structures/PDFContentStream.d.ts +15 -0
- package/dist/core/structures/PDFCrossRefStream.d.ts +53 -0
- package/dist/core/structures/PDFFlateStream.d.ts +13 -0
- package/dist/core/structures/PDFObjectStream.d.ts +20 -0
- package/dist/core/structures/PDFPageLeaf.d.ts +54 -0
- package/dist/core/structures/PDFPageTree.d.ts +41 -0
- package/dist/core/syntax/CharCodes.d.ts +61 -0
- package/dist/core/syntax/Delimiters.d.ts +1 -0
- package/dist/core/syntax/Irregular.d.ts +1 -0
- package/dist/core/syntax/Keywords.d.ts +22 -0
- package/dist/core/syntax/Numeric.d.ts +3 -0
- package/dist/core/syntax/Whitespace.d.ts +1 -0
- package/dist/core/writers/PDFStreamWriter.d.ts +19 -0
- package/dist/core/writers/PDFWriter.d.ts +29 -0
- package/dist/index.js +19124 -0
- package/dist/index.js.map +1 -0
- package/dist/types/fontkit.d.ts +597 -0
- package/{src/types/index.ts → dist/types/index.d.ts} +8 -13
- package/{src/types/matrix.ts → dist/types/matrix.d.ts} +1 -2
- package/dist/utils/Cache.d.ts +10 -0
- package/dist/utils/arrays.d.ts +16 -0
- package/dist/utils/async.d.ts +5 -0
- package/dist/utils/base64.d.ts +10 -0
- package/dist/utils/elements/Arc.d.ts +22 -0
- package/dist/utils/elements/Circle.d.ts +14 -0
- package/dist/utils/elements/Ellipse.d.ts +20 -0
- package/dist/utils/elements/GraphElement.d.ts +6 -0
- package/dist/utils/elements/Line.d.ts +23 -0
- package/dist/utils/elements/Plot.d.ts +11 -0
- package/dist/utils/elements/Point.d.ts +18 -0
- package/dist/utils/elements/Rectangle.d.ts +21 -0
- package/dist/utils/elements/Segment.d.ts +19 -0
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/intersections.d.ts +9 -0
- package/dist/utils/maths.d.ts +45 -0
- package/dist/utils/numbers.d.ts +23 -0
- package/dist/utils/objects.d.ts +15 -0
- package/dist/utils/pdfDocEncoding.d.ts +7 -0
- package/dist/utils/png.d.ts +17 -0
- package/dist/utils/rng.d.ts +13 -0
- package/dist/utils/strings.d.ts +25 -0
- package/{src/utils/unicode.ts → dist/utils/unicode.d.ts} +8 -195
- package/dist/utils/validators.d.ts +26 -0
- package/package.json +6 -1
- package/__tests__/api/PDFDocument.spec.ts +0 -576
- package/__tests__/api/PDFImage.spec.ts +0 -60
- package/__tests__/api/PDFPage.spec.ts +0 -151
- package/__tests__/api/form/PDFCheckBox.spec.ts +0 -71
- package/__tests__/api/form/PDFDropdown.spec.ts +0 -118
- package/__tests__/api/form/PDFForm.spec.ts +0 -370
- package/__tests__/api/form/PDFOptionList.spec.ts +0 -104
- package/__tests__/api/form/PDFRadioGroup.spec.ts +0 -183
- package/__tests__/api/form/PDFTextField.spec.ts +0 -148
- package/__tests__/api/svgPath.spec.ts +0 -153
- package/__tests__/api/text/layout.spec.ts +0 -166
- package/__tests__/core/PDFContext.spec.ts +0 -194
- package/__tests__/core/PDFObjectCopier.spec.ts +0 -421
- package/__tests__/core/acroform/PDFAcroField.spec.ts +0 -98
- package/__tests__/core/acroform/PDFAcroTerminal.spec.ts +0 -39
- package/__tests__/core/annotation/PDFWidgetAnnotation.spec.ts +0 -40
- package/__tests__/core/document/PDFCrossRefSection.spec.ts +0 -88
- package/__tests__/core/document/PDFHeader.spec.ts +0 -22
- package/__tests__/core/document/PDFTrailer.spec.ts +0 -28
- package/__tests__/core/document/PDFTrailerDict.spec.ts +0 -24
- package/__tests__/core/embedders/CMap.spec.ts +0 -47
- package/__tests__/core/embedders/CustomFontEmbedder.spec.ts +0 -96
- package/__tests__/core/embedders/CustomFontSubsetEmbedder.spec.ts +0 -62
- package/__tests__/core/embedders/FileEmbedder.spec.ts +0 -54
- package/__tests__/core/embedders/JpegEmbedder.spec.ts +0 -67
- package/__tests__/core/embedders/PDFPageEmbedder.spec.ts +0 -65
- package/__tests__/core/embedders/PngEmbedder.spec.ts +0 -87
- package/__tests__/core/embedders/StandardFontEmbedder.spec.ts +0 -79
- package/__tests__/core/embedders/data/SourceHanSerifJP-Regular.otf.cmap +0 -16096
- package/__tests__/core/embedders/data/Ubuntu-R.ttf.cmap +0 -1211
- package/__tests__/core/objects/PDFArray.spec.ts +0 -134
- package/__tests__/core/objects/PDFBool.spec.ts +0 -42
- package/__tests__/core/objects/PDFDict.spec.ts +0 -195
- package/__tests__/core/objects/PDFHexString.spec.ts +0 -168
- package/__tests__/core/objects/PDFInvalidObject.spec.ts +0 -32
- package/__tests__/core/objects/PDFName.spec.ts +0 -122
- package/__tests__/core/objects/PDFNull.spec.ts +0 -30
- package/__tests__/core/objects/PDFNumber.spec.ts +0 -50
- package/__tests__/core/objects/PDFObject.spec.ts +0 -29
- package/__tests__/core/objects/PDFRawStream.spec.ts +0 -45
- package/__tests__/core/objects/PDFRef.spec.ts +0 -60
- package/__tests__/core/objects/PDFString.spec.ts +0 -237
- package/__tests__/core/operators/PDFOperator.spec.ts +0 -77
- package/__tests__/core/parser/PDFObjectParser.spec.ts +0 -730
- package/__tests__/core/parser/PDFObjectStreamParser.spec.ts +0 -158
- package/__tests__/core/parser/PDFParser.spec.ts +0 -398
- package/__tests__/core/parser/PDFXRefStreamParser.spec.ts +0 -187
- package/__tests__/core/parser/data/object-stream-invalid +0 -2
- package/__tests__/core/parser/data/object-stream1 +0 -16
- package/__tests__/core/parser/data/object-stream2 +0 -10
- package/__tests__/core/parser/data/object-stream3 +0 -0
- package/__tests__/core/parser/data/object-stream4 +0 -0
- package/__tests__/core/parser/data/xref-stream1 +0 -0
- package/__tests__/core/parser/data/xref-stream2 +0 -0
- package/__tests__/core/parser/data/xref-stream3 +0 -0
- package/__tests__/core/parser/data/xref-stream4 +0 -0
- package/__tests__/core/streams/Ascii85Stream.spec.ts +0 -20
- package/__tests__/core/streams/AsciiHexStream.spec.ts +0 -20
- package/__tests__/core/streams/FlateStream.spec.ts +0 -20
- package/__tests__/core/streams/LZWStream.spec.ts +0 -20
- package/__tests__/core/streams/RunLengthStream.spec.ts +0 -20
- package/__tests__/core/streams/Stream.spec.ts +0 -128
- package/__tests__/core/streams/data/ascii85/1.decoded +0 -0
- package/__tests__/core/streams/data/ascii85/1.encoded +0 -43
- package/__tests__/core/streams/data/asciihex/1.decoded +0 -1
- package/__tests__/core/streams/data/asciihex/1.encoded +0 -1
- package/__tests__/core/streams/data/asciihex/2.decoded +0 -7
- package/__tests__/core/streams/data/asciihex/2.encoded +0 -1
- package/__tests__/core/streams/data/flate/1.corrupt.encoded +0 -1
- package/__tests__/core/streams/data/flate/1.decoded +0 -0
- package/__tests__/core/streams/data/flate/1.encoded +0 -2
- package/__tests__/core/streams/data/flate/2.decoded +0 -33
- package/__tests__/core/streams/data/flate/2.encoded +0 -0
- package/__tests__/core/streams/data/flate/3.decoded +0 -15
- package/__tests__/core/streams/data/flate/3.encoded +0 -0
- package/__tests__/core/streams/data/flate/4.decoded +0 -16
- package/__tests__/core/streams/data/flate/4.encoded +0 -0
- package/__tests__/core/streams/data/flate/5.decoded +0 -0
- package/__tests__/core/streams/data/flate/5.encoded +0 -0
- package/__tests__/core/streams/data/flate/6.decoded +0 -17
- package/__tests__/core/streams/data/flate/6.encoded +0 -0
- package/__tests__/core/streams/data/flate/7.decoded +0 -20
- package/__tests__/core/streams/data/flate/7.encoded +0 -1
- package/__tests__/core/streams/data/lzw/1.decoded +0 -0
- package/__tests__/core/streams/data/lzw/1.encoded +0 -0
- package/__tests__/core/streams/data/lzw/2.decoded +0 -0
- package/__tests__/core/streams/data/lzw/2.encoded +0 -0
- package/__tests__/core/streams/data/lzw/3.decoded +0 -14
- package/__tests__/core/streams/data/lzw/3.encoded +0 -2
- package/__tests__/core/streams/data/lzw/4.decoded +0 -14
- package/__tests__/core/streams/data/lzw/4.encoded +0 -2
- package/__tests__/core/streams/data/runlength/1.decoded +0 -1
- package/__tests__/core/streams/data/runlength/1.encoded +0 -1
- package/__tests__/core/streams/data/runlength/2.decoded +0 -1
- package/__tests__/core/streams/data/runlength/2.encoded +0 -1
- package/__tests__/core/streams/data/runlength/3.decoded +0 -0
- package/__tests__/core/streams/data/runlength/3.encoded +0 -0
- package/__tests__/core/streams/data/runlength/4.decoded +0 -1
- package/__tests__/core/streams/data/runlength/4.encoded +0 -1
- package/__tests__/core/streams/data/runlength/5.decoded +0 -1
- package/__tests__/core/streams/data/runlength/5.encoded +0 -1
- package/__tests__/core/streams/data/runlength/empty.encoded +0 -1
- package/__tests__/core/structures/PDFCatalog.spec.ts +0 -108
- package/__tests__/core/structures/PDFContentStream.spec.ts +0 -117
- package/__tests__/core/structures/PDFCrossRefStream.spec.ts +0 -145
- package/__tests__/core/structures/PDFObjectStream.spec.ts +0 -138
- package/__tests__/core/structures/PDFPageLeaf.spec.ts +0 -355
- package/__tests__/core/structures/PDFPageTree.spec.ts +0 -592
- package/__tests__/core/writers/PDFStreamWriter.spec.ts +0 -71
- package/__tests__/core/writers/PDFWriter.spec.ts +0 -144
- package/__tests__/core/writers/data/stream-writer-1.pdf +0 -0
- package/__tests__/index.test.ts +0 -12
- package/__tests__/utils/base64.spec.ts +0 -61
- package/__tests__/utils/data/simple.pdf +0 -201
- package/__tests__/utils/data/simple.pdf.base64 +0 -1
- package/__tests__/utils/pdfDocEncoding.spec.ts +0 -82
- package/__tests__/utils/png.spec.ts +0 -53
- package/__tests__/utils/rng.spec.ts +0 -14
- package/__tests__/utils/strings.spec.ts +0 -98
- package/__tests__/utils/unicode.spec.ts +0 -337
- package/assets/fonts/source_hans_jp/SourceHanSerifJP-Regular.otf +0 -0
- package/assets/fonts/ubuntu/Ubuntu-B.ttf +0 -0
- package/assets/fonts/ubuntu/Ubuntu-R.ttf +0 -0
- package/assets/images/cat_riding_unicorn.jpg +0 -0
- package/assets/images/cmyk_colorspace.jpg +0 -0
- package/assets/images/greyscale_bird.png +0 -0
- package/assets/images/minions_banana_alpha.png +0 -0
- package/assets/images/minions_banana_no_alpha.png +0 -0
- package/assets/images/minions_laughing.jpg +0 -0
- package/assets/pdfs/bixby_guide.pdf +0 -0
- package/assets/pdfs/encrypted_new.pdf +0 -0
- package/assets/pdfs/encrypted_old.pdf +0 -0
- package/assets/pdfs/fancy_fields.pdf +0 -0
- package/assets/pdfs/giraffe.pdf +0 -0
- package/assets/pdfs/invalid_root_ref.pdf +0 -0
- package/assets/pdfs/just_metadata.pdf +0 -49
- package/assets/pdfs/missing_endobj_keyword.pdf +0 -70
- package/assets/pdfs/missing_xref_trailer_dict.pdf +0 -141
- package/assets/pdfs/normal.pdf +0 -0
- package/assets/pdfs/pdf20examples/PDF 2.0 with offset start.pdf +0 -179
- package/assets/pdfs/stuff_following_header.pdf +0 -0
- package/assets/pdfs/us_constitution.pdf +0 -0
- package/assets/pdfs/with_comments.pdf +0 -0
- package/assets/pdfs/with_invalid_objects.pdf +0 -53
- package/assets/pdfs/with_invalid_stream_EOL.pdf +0 -0
- package/assets/pdfs/with_null_parent_entry.pdf +0 -0
- package/assets/pdfs/with_signature.pdf +0 -0
- package/assets/pdfs/with_update_sections.pdf +0 -0
- package/assets/pdfs/with_viewer_prefs.pdf +0 -0
- package/assets/pdfs/with_xfa_fields.pdf +0 -0
- package/src/api/PDFDocument.ts +0 -1389
- package/src/api/PDFDocumentOptions.ts +0 -45
- package/src/api/PDFEmbeddedFile.ts +0 -87
- package/src/api/PDFEmbeddedPage.ts +0 -100
- package/src/api/PDFFont.ts +0 -149
- package/src/api/PDFImage.ts +0 -143
- package/src/api/PDFJavaScript.ts +0 -75
- package/src/api/PDFPage.ts +0 -1604
- package/src/api/PDFPageOptions.ts +0 -175
- package/src/api/StandardFonts.ts +0 -16
- package/src/api/colors.ts +0 -109
- package/src/api/errors.ts +0 -110
- package/src/api/form/PDFButton.ts +0 -242
- package/src/api/form/PDFCheckBox.ts +0 -247
- package/src/api/form/PDFDropdown.ts +0 -637
- package/src/api/form/PDFField.ts +0 -491
- package/src/api/form/PDFForm.ts +0 -842
- package/src/api/form/PDFOptionList.ts +0 -555
- package/src/api/form/PDFRadioGroup.ts +0 -455
- package/src/api/form/PDFSignature.ts +0 -44
- package/src/api/form/PDFTextField.ts +0 -811
- package/src/api/form/appearances.ts +0 -655
- package/src/api/image/alignment.ts +0 -5
- package/src/api/objects.ts +0 -10
- package/src/api/operations.ts +0 -873
- package/src/api/operators.ts +0 -335
- package/src/api/rotations.ts +0 -84
- package/src/api/sizes.ts +0 -52
- package/src/api/svg.ts +0 -888
- package/src/api/svgPath.ts +0 -460
- package/src/api/text/alignment.ts +0 -5
- package/src/api/text/layout.ts +0 -328
- package/src/core/PDFContext.ts +0 -274
- package/src/core/PDFObjectCopier.ts +0 -142
- package/src/core/acroform/PDFAcroButton.ts +0 -104
- package/src/core/acroform/PDFAcroCheckBox.ts +0 -48
- package/src/core/acroform/PDFAcroChoice.ts +0 -143
- package/src/core/acroform/PDFAcroComboBox.ts +0 -21
- package/src/core/acroform/PDFAcroField.ts +0 -168
- package/src/core/acroform/PDFAcroForm.ts +0 -96
- package/src/core/acroform/PDFAcroListBox.ts +0 -19
- package/src/core/acroform/PDFAcroNonTerminal.ts +0 -33
- package/src/core/acroform/PDFAcroPushButton.ts +0 -21
- package/src/core/acroform/PDFAcroRadioButton.ts +0 -57
- package/src/core/acroform/PDFAcroTerminal.ts +0 -70
- package/src/core/acroform/PDFAcroText.ts +0 -76
- package/src/core/acroform/flags.ts +0 -162
- package/src/core/acroform/utils.ts +0 -129
- package/src/core/annotation/AppearanceCharacteristics.ts +0 -133
- package/src/core/annotation/BorderStyle.ts +0 -31
- package/src/core/annotation/PDFAnnotation.ts +0 -148
- package/src/core/annotation/PDFWidgetAnnotation.ts +0 -111
- package/src/core/annotation/flags.ts +0 -90
- package/src/core/crypto.ts +0 -1844
- package/src/core/document/PDFCrossRefSection.ts +0 -161
- package/src/core/document/PDFHeader.ts +0 -48
- package/src/core/document/PDFTrailer.ts +0 -48
- package/src/core/document/PDFTrailerDict.ts +0 -39
- package/src/core/embedders/CMap.ts +0 -65
- package/src/core/embedders/CustomFontEmbedder.ts +0 -237
- package/src/core/embedders/CustomFontSubsetEmbedder.ts +0 -89
- package/src/core/embedders/FileEmbedder.ts +0 -77
- package/src/core/embedders/FontFlags.ts +0 -45
- package/src/core/embedders/JavaScriptEmbedder.ts +0 -34
- package/src/core/embedders/JpegEmbedder.ts +0 -118
- package/src/core/embedders/PDFPageEmbedder.ts +0 -139
- package/src/core/embedders/PngEmbedder.ts +0 -69
- package/src/core/embedders/StandardFontEmbedder.ts +0 -121
- package/src/core/errors.ts +0 -226
- package/src/core/interactive/ViewerPreferences.ts +0 -565
- package/src/core/objects/PDFArray.ts +0 -179
- package/src/core/objects/PDFBool.ts +0 -53
- package/src/core/objects/PDFDict.ts +0 -220
- package/src/core/objects/PDFHexString.ts +0 -94
- package/src/core/objects/PDFInvalidObject.ts +0 -34
- package/src/core/objects/PDFName.ts +0 -152
- package/src/core/objects/PDFNull.ts +0 -30
- package/src/core/objects/PDFNumber.ts +0 -44
- package/src/core/objects/PDFObject.ts +0 -22
- package/src/core/objects/PDFRawStream.ts +0 -41
- package/src/core/objects/PDFRef.ts +0 -51
- package/src/core/objects/PDFStream.ts +0 -87
- package/src/core/objects/PDFString.ts +0 -118
- package/src/core/operators/PDFOperator.ts +0 -72
- package/src/core/operators/PDFOperatorNames.ts +0 -92
- package/src/core/parser/BaseParser.ts +0 -119
- package/src/core/parser/ByteStream.ts +0 -76
- package/src/core/parser/PDFObjectParser.ts +0 -302
- package/src/core/parser/PDFObjectStreamParser.ts +0 -65
- package/src/core/parser/PDFParser.ts +0 -363
- package/src/core/parser/PDFXRefStreamParser.ts +0 -129
- package/src/core/streams/Ascii85Stream.ts +0 -97
- package/src/core/streams/AsciiHexStream.ts +0 -77
- package/src/core/streams/DecodeStream.ts +0 -188
- package/src/core/streams/DecryptStream.ts +0 -49
- package/src/core/streams/FlateStream.ts +0 -397
- package/src/core/streams/LZWStream.ts +0 -157
- package/src/core/streams/RunLengthStream.ts +0 -55
- package/src/core/streams/Stream.ts +0 -126
- package/src/core/streams/decode.ts +0 -70
- package/src/core/structures/PDFCatalog.ts +0 -81
- package/src/core/structures/PDFContentStream.ts +0 -58
- package/src/core/structures/PDFCrossRefStream.ts +0 -238
- package/src/core/structures/PDFFlateStream.ts +0 -40
- package/src/core/structures/PDFObjectStream.ts +0 -91
- package/src/core/structures/PDFPageLeaf.ts +0 -244
- package/src/core/structures/PDFPageTree.ts +0 -192
- package/src/core/syntax/CharCodes.ts +0 -62
- package/src/core/syntax/Delimiters.ts +0 -14
- package/src/core/syntax/Irregular.ts +0 -10
- package/src/core/syntax/Keywords.ts +0 -57
- package/src/core/syntax/Numeric.ts +0 -26
- package/src/core/syntax/Whitespace.ts +0 -10
- package/src/core/writers/PDFStreamWriter.ts +0 -114
- package/src/core/writers/PDFWriter.ts +0 -146
- package/src/types/fontkit.ts +0 -643
- package/src/utils/Cache.ts +0 -26
- package/src/utils/arrays.ts +0 -153
- package/src/utils/async.ts +0 -8
- package/src/utils/base64.ts +0 -98
- package/src/utils/elements/Arc.ts +0 -97
- package/src/utils/elements/Circle.ts +0 -47
- package/src/utils/elements/Ellipse.ts +0 -117
- package/src/utils/elements/GraphElement.ts +0 -14
- package/src/utils/elements/Line.ts +0 -83
- package/src/utils/elements/Plot.ts +0 -50
- package/src/utils/elements/Point.ts +0 -37
- package/src/utils/elements/Rectangle.ts +0 -65
- package/src/utils/elements/Segment.ts +0 -81
- package/src/utils/errors.ts +0 -3
- package/src/utils/intersections.ts +0 -237
- package/src/utils/maths.ts +0 -96
- package/src/utils/numbers.ts +0 -55
- package/src/utils/objects.ts +0 -13
- package/src/utils/pdfDocEncoding.ts +0 -69
- package/src/utils/png.ts +0 -100
- package/src/utils/rng.ts +0 -21
- package/src/utils/strings.ts +0 -191
- package/src/utils/validators.ts +0 -192
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -15
- package/vite.config.mts +0 -39
- /package/{src/api/form/index.ts → dist/api/form/index.d.ts} +0 -0
- /package/{src/api/image/index.ts → dist/api/image/index.d.ts} +0 -0
- /package/{src/api/index.ts → dist/api/index.d.ts} +0 -0
- /package/{src/api/text/index.ts → dist/api/text/index.d.ts} +0 -0
- /package/{src/core/acroform/index.ts → dist/core/acroform/index.d.ts} +0 -0
- /package/{src/core/annotation/index.ts → dist/core/annotation/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/utils/elements/index.ts → dist/utils/elements/index.d.ts} +0 -0
- /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import PDFArray from './objects/PDFArray';
|
|
2
|
-
import PDFDict from './objects/PDFDict';
|
|
3
|
-
import PDFName from './objects/PDFName';
|
|
4
|
-
import PDFObject from './objects/PDFObject';
|
|
5
|
-
import PDFRef from './objects/PDFRef';
|
|
6
|
-
import PDFStream from './objects/PDFStream';
|
|
7
|
-
import PDFContext from './PDFContext';
|
|
8
|
-
import PDFPageLeaf from './structures/PDFPageLeaf';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* PDFObjectCopier copies PDFObjects from a src context to a dest context.
|
|
12
|
-
* The primary use case for this is to copy pages between PDFs.
|
|
13
|
-
*
|
|
14
|
-
* _Copying_ an object with a PDFObjectCopier is different from _cloning_ an
|
|
15
|
-
* object with its [[PDFObject.clone]] method:
|
|
16
|
-
*
|
|
17
|
-
* ```
|
|
18
|
-
* const src: PDFContext = ...
|
|
19
|
-
* const dest: PDFContext = ...
|
|
20
|
-
* const originalObject: PDFObject = ...
|
|
21
|
-
* const copiedObject = PDFObjectCopier.for(src, dest).copy(originalObject);
|
|
22
|
-
* const clonedObject = originalObject.clone();
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* Copying an object is equivalent to cloning it and then copying over any other
|
|
26
|
-
* objects that it references. Note that only dictionaries, arrays, and streams
|
|
27
|
-
* (or structures build from them) can contain indirect references to other
|
|
28
|
-
* objects. Copying a PDFObject that is not a dictionary, array, or stream is
|
|
29
|
-
* supported, but is equivalent to cloning it.
|
|
30
|
-
*/
|
|
31
|
-
class PDFObjectCopier {
|
|
32
|
-
static for = (src: PDFContext, dest: PDFContext) => new PDFObjectCopier(src, dest);
|
|
33
|
-
|
|
34
|
-
private readonly src: PDFContext;
|
|
35
|
-
private readonly dest: PDFContext;
|
|
36
|
-
private readonly traversedObjects = new Map<PDFObject, PDFObject>();
|
|
37
|
-
|
|
38
|
-
private constructor(src: PDFContext, dest: PDFContext) {
|
|
39
|
-
this.src = src;
|
|
40
|
-
this.dest = dest;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// prettier-ignore
|
|
44
|
-
copy = <T extends PDFObject>(object: T): T => (
|
|
45
|
-
object instanceof PDFPageLeaf ? this.copyPDFPage(object)
|
|
46
|
-
: object instanceof PDFDict ? this.copyPDFDict(object)
|
|
47
|
-
: object instanceof PDFArray ? this.copyPDFArray(object)
|
|
48
|
-
: object instanceof PDFStream ? this.copyPDFStream(object)
|
|
49
|
-
: object instanceof PDFRef ? this.copyPDFIndirectObject(object)
|
|
50
|
-
: object.clone()
|
|
51
|
-
) as T;
|
|
52
|
-
|
|
53
|
-
private copyPDFPage = (originalPage: PDFPageLeaf): PDFPageLeaf => {
|
|
54
|
-
const clonedPage = originalPage.clone();
|
|
55
|
-
|
|
56
|
-
// Move any entries that the originalPage is inheriting from its parent
|
|
57
|
-
// tree nodes directly into originalPage so they are preserved during
|
|
58
|
-
// the copy.
|
|
59
|
-
const { InheritableEntries } = PDFPageLeaf;
|
|
60
|
-
for (let idx = 0, len = InheritableEntries.length; idx < len; idx++) {
|
|
61
|
-
const key = PDFName.of(InheritableEntries[idx]);
|
|
62
|
-
const value = clonedPage.getInheritableAttribute(key)!;
|
|
63
|
-
if (!clonedPage.get(key) && value) clonedPage.set(key, value);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Remove the parent reference to prevent the whole donor document's page
|
|
67
|
-
// tree from being copied when we only need a single page.
|
|
68
|
-
clonedPage.delete(PDFName.of('Parent'));
|
|
69
|
-
|
|
70
|
-
return this.copyPDFDict(clonedPage) as PDFPageLeaf;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
private copyPDFDict = (originalDict: PDFDict): PDFDict => {
|
|
74
|
-
if (this.traversedObjects.has(originalDict)) {
|
|
75
|
-
return this.traversedObjects.get(originalDict) as PDFDict;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const clonedDict = originalDict.clone(this.dest);
|
|
79
|
-
this.traversedObjects.set(originalDict, clonedDict);
|
|
80
|
-
|
|
81
|
-
const entries = originalDict.entries();
|
|
82
|
-
|
|
83
|
-
for (let idx = 0, len = entries.length; idx < len; idx++) {
|
|
84
|
-
const [key, value] = entries[idx];
|
|
85
|
-
clonedDict.set(key, this.copy(value));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return clonedDict;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
private copyPDFArray = (originalArray: PDFArray): PDFArray => {
|
|
92
|
-
if (this.traversedObjects.has(originalArray)) {
|
|
93
|
-
return this.traversedObjects.get(originalArray) as PDFArray;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const clonedArray = originalArray.clone(this.dest);
|
|
97
|
-
this.traversedObjects.set(originalArray, clonedArray);
|
|
98
|
-
|
|
99
|
-
for (let idx = 0, len = originalArray.size(); idx < len; idx++) {
|
|
100
|
-
const value = originalArray.get(idx);
|
|
101
|
-
clonedArray.set(idx, this.copy(value));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return clonedArray;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
private copyPDFStream = (originalStream: PDFStream): PDFStream => {
|
|
108
|
-
if (this.traversedObjects.has(originalStream)) {
|
|
109
|
-
return this.traversedObjects.get(originalStream) as PDFStream;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const clonedStream = originalStream.clone(this.dest);
|
|
113
|
-
this.traversedObjects.set(originalStream, clonedStream);
|
|
114
|
-
|
|
115
|
-
const entries = originalStream.dict.entries();
|
|
116
|
-
for (let idx = 0, len = entries.length; idx < len; idx++) {
|
|
117
|
-
const [key, value] = entries[idx];
|
|
118
|
-
clonedStream.dict.set(key, this.copy(value));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return clonedStream;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
private copyPDFIndirectObject = (ref: PDFRef): PDFRef => {
|
|
125
|
-
const alreadyMapped = this.traversedObjects.has(ref);
|
|
126
|
-
|
|
127
|
-
if (!alreadyMapped) {
|
|
128
|
-
const newRef = this.dest.nextRef();
|
|
129
|
-
this.traversedObjects.set(ref, newRef);
|
|
130
|
-
|
|
131
|
-
const dereferencedValue = this.src.lookup(ref);
|
|
132
|
-
if (dereferencedValue) {
|
|
133
|
-
const cloned = this.copy(dereferencedValue);
|
|
134
|
-
this.dest.assign(newRef, cloned);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return this.traversedObjects.get(ref) as PDFRef;
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export default PDFObjectCopier;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import PDFObject from '../objects/PDFObject';
|
|
2
|
-
import PDFString from '../objects/PDFString';
|
|
3
|
-
import PDFHexString from '../objects/PDFHexString';
|
|
4
|
-
import PDFArray from '../objects/PDFArray';
|
|
5
|
-
import PDFName from '../objects/PDFName';
|
|
6
|
-
import PDFRef from '../objects/PDFRef';
|
|
7
|
-
import PDFAcroTerminal from './PDFAcroTerminal';
|
|
8
|
-
import { IndexOutOfBoundsError } from '../errors';
|
|
9
|
-
|
|
10
|
-
class PDFAcroButton extends PDFAcroTerminal {
|
|
11
|
-
Opt(): PDFString | PDFHexString | PDFArray | undefined {
|
|
12
|
-
return this.dict.lookupMaybe(PDFName.of('Opt'), PDFString, PDFHexString, PDFArray);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
setOpt(opt: PDFObject[]) {
|
|
16
|
-
this.dict.set(PDFName.of('Opt'), this.dict.context.obj(opt));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getExportValues(): (PDFString | PDFHexString)[] | undefined {
|
|
20
|
-
const opt = this.Opt();
|
|
21
|
-
|
|
22
|
-
if (!opt) return undefined;
|
|
23
|
-
|
|
24
|
-
if (opt instanceof PDFString || opt instanceof PDFHexString) {
|
|
25
|
-
return [opt];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const values: (PDFString | PDFHexString)[] = [];
|
|
29
|
-
for (let idx = 0, len = opt.size(); idx < len; idx++) {
|
|
30
|
-
const value = opt.lookup(idx);
|
|
31
|
-
if (value instanceof PDFString || value instanceof PDFHexString) {
|
|
32
|
-
values.push(value);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return values;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
removeExportValue(idx: number) {
|
|
40
|
-
const opt = this.Opt();
|
|
41
|
-
|
|
42
|
-
if (!opt) return;
|
|
43
|
-
|
|
44
|
-
if (opt instanceof PDFString || opt instanceof PDFHexString) {
|
|
45
|
-
if (idx !== 0) throw new IndexOutOfBoundsError(idx, 0, 0);
|
|
46
|
-
this.setOpt([]);
|
|
47
|
-
} else {
|
|
48
|
-
if (idx < 0 || idx > opt.size()) {
|
|
49
|
-
throw new IndexOutOfBoundsError(idx, 0, opt.size());
|
|
50
|
-
}
|
|
51
|
-
opt.remove(idx);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Enforce use use of /Opt even if it isn't strictly necessary
|
|
56
|
-
normalizeExportValues() {
|
|
57
|
-
const exportValues = this.getExportValues() ?? [];
|
|
58
|
-
|
|
59
|
-
const Opt: (PDFString | PDFHexString)[] = [];
|
|
60
|
-
|
|
61
|
-
const widgets = this.getWidgets();
|
|
62
|
-
for (let idx = 0, len = widgets.length; idx < len; idx++) {
|
|
63
|
-
const widget = widgets[idx];
|
|
64
|
-
const exportVal =
|
|
65
|
-
exportValues[idx] ?? PDFHexString.fromText(widget.getOnValue()?.decodeText() ?? '');
|
|
66
|
-
Opt.push(exportVal);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this.setOpt(Opt);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Reuses existing opt if one exists with the same value (assuming
|
|
74
|
-
* `useExistingIdx` is `true`). Returns index of existing (or new) opt.
|
|
75
|
-
*/
|
|
76
|
-
addOpt(opt: PDFHexString | PDFString, useExistingOptIdx: boolean): number {
|
|
77
|
-
this.normalizeExportValues();
|
|
78
|
-
|
|
79
|
-
const optText = opt.decodeText();
|
|
80
|
-
|
|
81
|
-
let existingIdx: number | undefined;
|
|
82
|
-
if (useExistingOptIdx) {
|
|
83
|
-
const exportValues = this.getExportValues() ?? [];
|
|
84
|
-
for (let idx = 0, len = exportValues.length; idx < len; idx++) {
|
|
85
|
-
const exportVal = exportValues[idx];
|
|
86
|
-
if (exportVal.decodeText() === optText) existingIdx = idx;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const Opt = this.Opt() as PDFArray;
|
|
91
|
-
Opt.push(opt);
|
|
92
|
-
|
|
93
|
-
return existingIdx ?? Opt.size() - 1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
addWidgetWithOpt(widget: PDFRef, opt: PDFHexString | PDFString, useExistingOptIdx: boolean) {
|
|
97
|
-
const optIdx = this.addOpt(opt, useExistingOptIdx);
|
|
98
|
-
const apStateValue = PDFName.of(String(optIdx));
|
|
99
|
-
this.addWidget(widget);
|
|
100
|
-
return apStateValue;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export default PDFAcroButton;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import PDFContext from '../PDFContext';
|
|
2
|
-
import PDFRef from '../objects/PDFRef';
|
|
3
|
-
import PDFDict from '../objects/PDFDict';
|
|
4
|
-
import PDFName from '../objects/PDFName';
|
|
5
|
-
import PDFAcroButton from './PDFAcroButton';
|
|
6
|
-
import { InvalidAcroFieldValueError } from '../errors';
|
|
7
|
-
|
|
8
|
-
class PDFAcroCheckBox extends PDFAcroButton {
|
|
9
|
-
static fromDict = (dict: PDFDict, ref: PDFRef) => new PDFAcroCheckBox(dict, ref);
|
|
10
|
-
|
|
11
|
-
static create = (context: PDFContext) => {
|
|
12
|
-
const dict = context.obj({
|
|
13
|
-
FT: 'Btn',
|
|
14
|
-
Kids: [],
|
|
15
|
-
});
|
|
16
|
-
const ref = context.register(dict);
|
|
17
|
-
return new PDFAcroCheckBox(dict, ref);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
setValue(value: PDFName) {
|
|
21
|
-
const onValue = this.getOnValue() ?? PDFName.of('Yes');
|
|
22
|
-
if (value !== onValue && value !== PDFName.of('Off')) {
|
|
23
|
-
throw new InvalidAcroFieldValueError();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
this.dict.set(PDFName.of('V'), value);
|
|
27
|
-
|
|
28
|
-
const widgets = this.getWidgets();
|
|
29
|
-
for (let idx = 0, len = widgets.length; idx < len; idx++) {
|
|
30
|
-
const widget = widgets[idx];
|
|
31
|
-
const state = widget.getOnValue() === value ? value : PDFName.of('Off');
|
|
32
|
-
widget.setAppearanceState(state);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
getValue(): PDFName {
|
|
37
|
-
const v = this.V();
|
|
38
|
-
if (v instanceof PDFName) return v;
|
|
39
|
-
return PDFName.of('Off');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
getOnValue(): PDFName | undefined {
|
|
43
|
-
const [widget] = this.getWidgets();
|
|
44
|
-
return widget?.getOnValue();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default PDFAcroCheckBox;
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import PDFAcroTerminal from './PDFAcroTerminal';
|
|
2
|
-
import PDFHexString from '../objects/PDFHexString';
|
|
3
|
-
import PDFString from '../objects/PDFString';
|
|
4
|
-
import PDFArray from '../objects/PDFArray';
|
|
5
|
-
import PDFName from '../objects/PDFName';
|
|
6
|
-
import { AcroChoiceFlags } from './flags';
|
|
7
|
-
import { InvalidAcroFieldValueError, MultiSelectValueError } from '../errors';
|
|
8
|
-
|
|
9
|
-
class PDFAcroChoice extends PDFAcroTerminal {
|
|
10
|
-
setValues(values: (PDFString | PDFHexString)[]) {
|
|
11
|
-
if (
|
|
12
|
-
this.hasFlag(AcroChoiceFlags.Combo) &&
|
|
13
|
-
!this.hasFlag(AcroChoiceFlags.Edit) &&
|
|
14
|
-
!this.valuesAreValid(values)
|
|
15
|
-
) {
|
|
16
|
-
throw new InvalidAcroFieldValueError();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (values.length === 0) {
|
|
20
|
-
this.dict.delete(PDFName.of('V'));
|
|
21
|
-
}
|
|
22
|
-
if (values.length === 1) {
|
|
23
|
-
this.dict.set(PDFName.of('V'), values[0]);
|
|
24
|
-
}
|
|
25
|
-
if (values.length > 1) {
|
|
26
|
-
if (!this.hasFlag(AcroChoiceFlags.MultiSelect)) {
|
|
27
|
-
throw new MultiSelectValueError();
|
|
28
|
-
}
|
|
29
|
-
this.dict.set(PDFName.of('V'), this.dict.context.obj(values));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this.updateSelectedIndices(values);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
valuesAreValid(values: (PDFString | PDFHexString)[]): boolean {
|
|
36
|
-
const options = this.getOptions();
|
|
37
|
-
for (let idx = 0, len = values.length; idx < len; idx++) {
|
|
38
|
-
const val = values[idx].decodeText();
|
|
39
|
-
if (!options.find((o) => val === (o.display || o.value).decodeText())) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
updateSelectedIndices(values: (PDFString | PDFHexString)[]) {
|
|
47
|
-
if (values.length > 1) {
|
|
48
|
-
const indices = Array<number>(values.length);
|
|
49
|
-
const options = this.getOptions();
|
|
50
|
-
for (let idx = 0, len = values.length; idx < len; idx++) {
|
|
51
|
-
const val = values[idx].decodeText();
|
|
52
|
-
indices[idx] = options.findIndex((o) => val === (o.display || o.value).decodeText());
|
|
53
|
-
}
|
|
54
|
-
this.dict.set(PDFName.of('I'), this.dict.context.obj(indices.sort()));
|
|
55
|
-
} else {
|
|
56
|
-
this.dict.delete(PDFName.of('I'));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getValues(): (PDFString | PDFHexString)[] {
|
|
61
|
-
const v = this.V();
|
|
62
|
-
|
|
63
|
-
if (v instanceof PDFString || v instanceof PDFHexString) return [v];
|
|
64
|
-
|
|
65
|
-
if (v instanceof PDFArray) {
|
|
66
|
-
const values: (PDFString | PDFHexString)[] = [];
|
|
67
|
-
|
|
68
|
-
for (let idx = 0, len = v.size(); idx < len; idx++) {
|
|
69
|
-
const value = v.lookup(idx);
|
|
70
|
-
if (value instanceof PDFString || value instanceof PDFHexString) {
|
|
71
|
-
values.push(value);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return values;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
Opt(): PDFArray | PDFString | PDFHexString | undefined {
|
|
82
|
-
return this.dict.lookupMaybe(PDFName.of('Opt'), PDFString, PDFHexString, PDFArray);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
setOptions(
|
|
86
|
-
options: {
|
|
87
|
-
value: PDFString | PDFHexString;
|
|
88
|
-
display?: PDFString | PDFHexString;
|
|
89
|
-
}[],
|
|
90
|
-
) {
|
|
91
|
-
const newOpt = Array<PDFArray>(options.length);
|
|
92
|
-
for (let idx = 0, len = options.length; idx < len; idx++) {
|
|
93
|
-
const { value, display } = options[idx];
|
|
94
|
-
newOpt[idx] = this.dict.context.obj([value, display || value]);
|
|
95
|
-
}
|
|
96
|
-
this.dict.set(PDFName.of('Opt'), this.dict.context.obj(newOpt));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getOptions(): {
|
|
100
|
-
value: PDFString | PDFHexString;
|
|
101
|
-
display: PDFString | PDFHexString;
|
|
102
|
-
}[] {
|
|
103
|
-
const Opt = this.Opt();
|
|
104
|
-
|
|
105
|
-
// Not supposed to happen - Opt _should_ always be `PDFArray | undefined`
|
|
106
|
-
if (Opt instanceof PDFString || Opt instanceof PDFHexString) {
|
|
107
|
-
return [{ value: Opt, display: Opt }];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (Opt instanceof PDFArray) {
|
|
111
|
-
const res: {
|
|
112
|
-
value: PDFString | PDFHexString;
|
|
113
|
-
display: PDFString | PDFHexString;
|
|
114
|
-
}[] = [];
|
|
115
|
-
|
|
116
|
-
for (let idx = 0, len = Opt.size(); idx < len; idx++) {
|
|
117
|
-
const item = Opt.lookup(idx);
|
|
118
|
-
|
|
119
|
-
// If `item` is a string, use that as both the export and text value
|
|
120
|
-
if (item instanceof PDFString || item instanceof PDFHexString) {
|
|
121
|
-
res.push({ value: item, display: item });
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// If `item` is an array of one, treat it the same as just a string,
|
|
125
|
-
// if it's an array of two then `item[0]` is the export value and
|
|
126
|
-
// `item[1]` is the text value
|
|
127
|
-
if (item instanceof PDFArray) {
|
|
128
|
-
if (item.size() > 0) {
|
|
129
|
-
const first = item.lookup(0, PDFString, PDFHexString);
|
|
130
|
-
const second = item.lookupMaybe(1, PDFString, PDFHexString);
|
|
131
|
-
res.push({ value: first, display: second || first });
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return res;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return [];
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export default PDFAcroChoice;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import PDFDict from '../objects/PDFDict';
|
|
2
|
-
import PDFAcroChoice from './PDFAcroChoice';
|
|
3
|
-
import PDFContext from '../PDFContext';
|
|
4
|
-
import PDFRef from '../objects/PDFRef';
|
|
5
|
-
import { AcroChoiceFlags } from './flags';
|
|
6
|
-
|
|
7
|
-
class PDFAcroComboBox extends PDFAcroChoice {
|
|
8
|
-
static fromDict = (dict: PDFDict, ref: PDFRef) => new PDFAcroComboBox(dict, ref);
|
|
9
|
-
|
|
10
|
-
static create = (context: PDFContext) => {
|
|
11
|
-
const dict = context.obj({
|
|
12
|
-
FT: 'Ch',
|
|
13
|
-
Ff: AcroChoiceFlags.Combo,
|
|
14
|
-
Kids: [],
|
|
15
|
-
});
|
|
16
|
-
const ref = context.register(dict);
|
|
17
|
-
return new PDFAcroComboBox(dict, ref);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default PDFAcroComboBox;
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import PDFDict from '../objects/PDFDict';
|
|
2
|
-
import PDFString from '../objects/PDFString';
|
|
3
|
-
import PDFHexString from '../objects/PDFHexString';
|
|
4
|
-
import PDFName from '../objects/PDFName';
|
|
5
|
-
import PDFObject from '../objects/PDFObject';
|
|
6
|
-
import PDFNumber from '../objects/PDFNumber';
|
|
7
|
-
import PDFArray from '../objects/PDFArray';
|
|
8
|
-
import PDFRef from '../objects/PDFRef';
|
|
9
|
-
import { findLastMatch } from '../../utils';
|
|
10
|
-
import { MissingDAEntryError, MissingTfOperatorError } from '../errors';
|
|
11
|
-
|
|
12
|
-
// Examples:
|
|
13
|
-
// `/Helv 12 Tf` -> ['Helv', '12']
|
|
14
|
-
// `/HeBo 8.00 Tf` -> ['HeBo', '8.00']
|
|
15
|
-
// `/HeBo Tf` -> ['HeBo', undefined]
|
|
16
|
-
// oxlint-disable-next-line no-control-regex -- Default appearance strings can contain NUL delimiters.
|
|
17
|
-
const tfRegex = /\/([^\u0000\t\n\f\r ]+)[\u0000\t\n\f\r ]*(\d*\.\d+|\d+)?[\u0000\t\n\f\r ]+Tf/;
|
|
18
|
-
|
|
19
|
-
class PDFAcroField {
|
|
20
|
-
readonly dict: PDFDict;
|
|
21
|
-
readonly ref: PDFRef;
|
|
22
|
-
|
|
23
|
-
protected constructor(dict: PDFDict, ref: PDFRef) {
|
|
24
|
-
this.dict = dict;
|
|
25
|
-
this.ref = ref;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
T(): PDFString | PDFHexString | undefined {
|
|
29
|
-
return this.dict.lookupMaybe(PDFName.of('T'), PDFString, PDFHexString);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
Ff(): PDFNumber | undefined {
|
|
33
|
-
const numberOrRef = this.getInheritableAttribute(PDFName.of('Ff'));
|
|
34
|
-
return this.dict.context.lookupMaybe(numberOrRef, PDFNumber);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
V(): PDFObject | undefined {
|
|
38
|
-
const valueOrRef = this.getInheritableAttribute(PDFName.of('V'));
|
|
39
|
-
return this.dict.context.lookup(valueOrRef);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
Kids(): PDFArray | undefined {
|
|
43
|
-
return this.dict.lookupMaybe(PDFName.of('Kids'), PDFArray);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Parent(): PDFDict | undefined {
|
|
47
|
-
// return this.dict.lookupMaybe(PDFName.of('Parent'), PDFDict);
|
|
48
|
-
// }
|
|
49
|
-
|
|
50
|
-
DA(): PDFString | PDFHexString | undefined {
|
|
51
|
-
const da = this.dict.lookup(PDFName.of('DA'));
|
|
52
|
-
if (da instanceof PDFString || da instanceof PDFHexString) return da;
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
setKids(kids: PDFObject[]) {
|
|
57
|
-
this.dict.set(PDFName.of('Kids'), this.dict.context.obj(kids));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getParent(): PDFAcroField | undefined {
|
|
61
|
-
// const parent = this.Parent();
|
|
62
|
-
// if (!parent) return undefined;
|
|
63
|
-
// return new PDFAcroField(parent);
|
|
64
|
-
|
|
65
|
-
const parentRef = this.dict.get(PDFName.of('Parent'));
|
|
66
|
-
if (parentRef instanceof PDFRef) {
|
|
67
|
-
const parent = this.dict.lookup(PDFName.of('Parent'), PDFDict);
|
|
68
|
-
return new PDFAcroField(parent, parentRef);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
setParent(parent: PDFRef | undefined) {
|
|
75
|
-
if (!parent) this.dict.delete(PDFName.of('Parent'));
|
|
76
|
-
else this.dict.set(PDFName.of('Parent'), parent);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getFullyQualifiedName(): string | undefined {
|
|
80
|
-
const parent = this.getParent();
|
|
81
|
-
if (!parent) return this.getPartialName();
|
|
82
|
-
return `${parent.getFullyQualifiedName()}.${this.getPartialName()}`;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getPartialName(): string | undefined {
|
|
86
|
-
return this.T()?.decodeText();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
setPartialName(partialName: string | undefined) {
|
|
90
|
-
if (!partialName) this.dict.delete(PDFName.of('T'));
|
|
91
|
-
else this.dict.set(PDFName.of('T'), PDFHexString.fromText(partialName));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
setDefaultAppearance(appearance: string) {
|
|
95
|
-
this.dict.set(PDFName.of('DA'), PDFString.of(appearance));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
getDefaultAppearance(): string | undefined {
|
|
99
|
-
const DA = this.DA();
|
|
100
|
-
|
|
101
|
-
if (DA instanceof PDFHexString) {
|
|
102
|
-
return DA.decodeText();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return DA?.asString();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
setFontSize(fontSize: number) {
|
|
109
|
-
const name = this.getFullyQualifiedName() ?? '';
|
|
110
|
-
|
|
111
|
-
const da = this.getDefaultAppearance();
|
|
112
|
-
if (!da) throw new MissingDAEntryError(name);
|
|
113
|
-
|
|
114
|
-
const daMatch = findLastMatch(da, tfRegex);
|
|
115
|
-
if (!daMatch.match) throw new MissingTfOperatorError(name);
|
|
116
|
-
|
|
117
|
-
const daStart = da.slice(0, daMatch.pos - daMatch.match[0].length);
|
|
118
|
-
const daEnd = daMatch.pos <= da.length ? da.slice(daMatch.pos) : '';
|
|
119
|
-
const fontName = daMatch.match[1];
|
|
120
|
-
const modifiedDa = `${daStart} /${fontName} ${fontSize} Tf ${daEnd}`;
|
|
121
|
-
|
|
122
|
-
this.setDefaultAppearance(modifiedDa);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
getFlags(): number {
|
|
126
|
-
return this.Ff()?.asNumber() ?? 0;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
setFlags(flags: number) {
|
|
130
|
-
this.dict.set(PDFName.of('Ff'), PDFNumber.of(flags));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
hasFlag(flag: number): boolean {
|
|
134
|
-
const flags = this.getFlags();
|
|
135
|
-
return (flags & flag) !== 0;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
setFlag(flag: number) {
|
|
139
|
-
const flags = this.getFlags();
|
|
140
|
-
this.setFlags(flags | flag);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
clearFlag(flag: number) {
|
|
144
|
-
const flags = this.getFlags();
|
|
145
|
-
this.setFlags(flags & ~flag);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
setFlagTo(flag: number, enable: boolean) {
|
|
149
|
-
if (enable) this.setFlag(flag);
|
|
150
|
-
else this.clearFlag(flag);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
getInheritableAttribute(name: PDFName): PDFObject | undefined {
|
|
154
|
-
let attribute: PDFObject | undefined;
|
|
155
|
-
this.ascend((node) => {
|
|
156
|
-
if (!attribute) attribute = node.dict.get(name);
|
|
157
|
-
});
|
|
158
|
-
return attribute;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
ascend(visitor: (node: PDFAcroField) => any): void {
|
|
162
|
-
visitor(this);
|
|
163
|
-
const parent = this.getParent();
|
|
164
|
-
if (parent) parent.ascend(visitor);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export default PDFAcroField;
|