@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,555 +0,0 @@
|
|
|
1
|
-
import PDFDocument from '../PDFDocument';
|
|
2
|
-
import PDFPage from '../PDFPage';
|
|
3
|
-
import PDFFont from '../PDFFont';
|
|
4
|
-
import PDFField, { FieldAppearanceOptions, assertFieldAppearanceOptions } from './PDFField';
|
|
5
|
-
import {
|
|
6
|
-
AppearanceProviderFor,
|
|
7
|
-
normalizeAppearance,
|
|
8
|
-
defaultOptionListAppearanceProvider,
|
|
9
|
-
} from './appearances';
|
|
10
|
-
import { rgb } from '../colors';
|
|
11
|
-
import { degrees } from '../rotations';
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
PDFRef,
|
|
15
|
-
PDFHexString,
|
|
16
|
-
PDFString,
|
|
17
|
-
PDFStream,
|
|
18
|
-
PDFAcroListBox,
|
|
19
|
-
AcroChoiceFlags,
|
|
20
|
-
PDFWidgetAnnotation,
|
|
21
|
-
} from '../../core';
|
|
22
|
-
import { assertIs, assertIsSubset, assertOrUndefined, assertPositive } from '../../utils';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Represents an option list field of a [[PDFForm]].
|
|
26
|
-
*
|
|
27
|
-
* [[PDFOptionList]] fields are interactive lists of options. The purpose of an
|
|
28
|
-
* option list is to enable users to select one or more options from a set of
|
|
29
|
-
* possible options. Users are able to see the full set of options without
|
|
30
|
-
* first having to click on the field (though scrolling may be necessary).
|
|
31
|
-
* Clicking an option in the list will cause it to be selected and displayed
|
|
32
|
-
* with a highlighted background. Some option lists allow users to select
|
|
33
|
-
* more than one option (see [[PDFOptionList.isMultiselect]]).
|
|
34
|
-
*/
|
|
35
|
-
export default class PDFOptionList extends PDFField {
|
|
36
|
-
/**
|
|
37
|
-
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
|
38
|
-
* > consider using the [[PDFForm.getOptionList]] method, which will create
|
|
39
|
-
* > an instance of [[PDFOptionList]] for you.
|
|
40
|
-
*
|
|
41
|
-
* Create an instance of [[PDFOptionList]] from an existing acroListBox and
|
|
42
|
-
* ref
|
|
43
|
-
*
|
|
44
|
-
* @param acroComboBox The underlying `PDFAcroListBox` for this option list.
|
|
45
|
-
* @param ref The unique reference for this option list.
|
|
46
|
-
* @param doc The document to which this option list will belong.
|
|
47
|
-
*/
|
|
48
|
-
static of = (acroListBox: PDFAcroListBox, ref: PDFRef, doc: PDFDocument) =>
|
|
49
|
-
new PDFOptionList(acroListBox, ref, doc);
|
|
50
|
-
|
|
51
|
-
/** The low-level PDFAcroListBox wrapped by this option list. */
|
|
52
|
-
readonly acroField: PDFAcroListBox;
|
|
53
|
-
|
|
54
|
-
private constructor(acroListBox: PDFAcroListBox, ref: PDFRef, doc: PDFDocument) {
|
|
55
|
-
super(acroListBox, ref, doc);
|
|
56
|
-
|
|
57
|
-
assertIs(acroListBox, 'acroListBox', [[PDFAcroListBox, 'PDFAcroListBox']]);
|
|
58
|
-
|
|
59
|
-
this.acroField = acroListBox;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Get the list of available options for this option list. These options will
|
|
64
|
-
* be displayed to users who view this option list in a PDF reader.
|
|
65
|
-
* For example:
|
|
66
|
-
* ```js
|
|
67
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
68
|
-
* const options = optionList.getOptions()
|
|
69
|
-
* console.log('Option List options:', options)
|
|
70
|
-
* ```
|
|
71
|
-
* @returns The options for this option list.
|
|
72
|
-
*/
|
|
73
|
-
getOptions(): string[] {
|
|
74
|
-
const rawOptions = this.acroField.getOptions();
|
|
75
|
-
|
|
76
|
-
const options = Array<string>(rawOptions.length);
|
|
77
|
-
for (let idx = 0, len = options.length; idx < len; idx++) {
|
|
78
|
-
const { display, value } = rawOptions[idx];
|
|
79
|
-
options[idx] = (display ?? value).decodeText();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return options;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Get the selected options for this option list. These are the values that
|
|
87
|
-
* were selected by a human user via a PDF reader, or programatically via
|
|
88
|
-
* software.
|
|
89
|
-
* For example:
|
|
90
|
-
* ```js
|
|
91
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
92
|
-
* const selections = optionList.getSelected()
|
|
93
|
-
* console.log('Option List selections:', selections)
|
|
94
|
-
* ```
|
|
95
|
-
* @returns The selected options for this option list.
|
|
96
|
-
*/
|
|
97
|
-
getSelected(): string[] {
|
|
98
|
-
const values = this.acroField.getValues();
|
|
99
|
-
|
|
100
|
-
const selected = Array<string>(values.length);
|
|
101
|
-
for (let idx = 0, len = values.length; idx < len; idx++) {
|
|
102
|
-
selected[idx] = values[idx].decodeText();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return selected;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Set the list of options that are available for this option list. These are
|
|
110
|
-
* the values that will be available for users to select when they view this
|
|
111
|
-
* option list in a PDF reader. Note that preexisting options for this
|
|
112
|
-
* option list will be removed. Only the values passed as `options` will be
|
|
113
|
-
* available to select.
|
|
114
|
-
*
|
|
115
|
-
* For example:
|
|
116
|
-
* ```js
|
|
117
|
-
* const optionList = form.getOptionList('planets.optionList')
|
|
118
|
-
* optionList.setOptions(['Earth', 'Mars', 'Pluto', 'Venus'])
|
|
119
|
-
* ```
|
|
120
|
-
*
|
|
121
|
-
* This method will mark this option list as dirty, causing its appearance
|
|
122
|
-
* streams to be updated when either [[PDFDocument.save]] or
|
|
123
|
-
* [[PDFForm.updateFieldAppearances]] is called. The updated streams will
|
|
124
|
-
* display the options this field contains inside the widgets of this text
|
|
125
|
-
* field (with selected options highlighted).
|
|
126
|
-
*
|
|
127
|
-
* **IMPORTANT:** The default font used to update appearance streams is
|
|
128
|
-
* [[StandardFonts.Helvetica]]. Note that this is a WinAnsi font. This means
|
|
129
|
-
* that encoding errors will be thrown if this field contains any options
|
|
130
|
-
* with characters outside the WinAnsi character set (the latin alphabet).
|
|
131
|
-
*
|
|
132
|
-
* Embedding a custom font and passing it to
|
|
133
|
-
* [[PDFForm.updateFieldAppearances]] or [[PDFOptionList.updateAppearances]]
|
|
134
|
-
* allows you to generate appearance streams with characters outside the
|
|
135
|
-
* latin alphabet (assuming the custom font supports them).
|
|
136
|
-
*
|
|
137
|
-
* @param options The options that should be available in this option list.
|
|
138
|
-
*/
|
|
139
|
-
setOptions(options: string[]) {
|
|
140
|
-
assertIs(options, 'options', [Array]);
|
|
141
|
-
|
|
142
|
-
this.markAsDirty();
|
|
143
|
-
const optionObjects = Array<{ value: PDFHexString }>(options.length);
|
|
144
|
-
for (let idx = 0, len = options.length; idx < len; idx++) {
|
|
145
|
-
optionObjects[idx] = { value: PDFHexString.fromText(options[idx]) };
|
|
146
|
-
}
|
|
147
|
-
this.acroField.setOptions(optionObjects);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Add to the list of options that are available for this option list. Users
|
|
152
|
-
* will be able to select these values in a PDF reader. In addition to the
|
|
153
|
-
* values passed as `options`, any preexisting options for this option list
|
|
154
|
-
* will still be available for users to select.
|
|
155
|
-
* For example:
|
|
156
|
-
* ```js
|
|
157
|
-
* const optionList = form.getOptionList('rockets.optionList')
|
|
158
|
-
* optionList.addOptions(['Saturn IV', 'Falcon Heavy'])
|
|
159
|
-
* ```
|
|
160
|
-
* This method will mark this option list as dirty. See
|
|
161
|
-
* [[PDFOptionList.setOptions]] for more details about what this means.
|
|
162
|
-
* @param options New options that should be available in this option list.
|
|
163
|
-
*/
|
|
164
|
-
addOptions(options: string | string[]) {
|
|
165
|
-
assertIs(options, 'options', ['string', Array]);
|
|
166
|
-
|
|
167
|
-
this.markAsDirty();
|
|
168
|
-
|
|
169
|
-
const optionsArr = Array.isArray(options) ? options : [options];
|
|
170
|
-
|
|
171
|
-
const existingOptions: {
|
|
172
|
-
value: PDFString | PDFHexString;
|
|
173
|
-
display?: PDFString | PDFHexString;
|
|
174
|
-
}[] = this.acroField.getOptions();
|
|
175
|
-
|
|
176
|
-
const newOptions = Array<{ value: PDFHexString }>(optionsArr.length);
|
|
177
|
-
for (let idx = 0, len = optionsArr.length; idx < len; idx++) {
|
|
178
|
-
newOptions[idx] = { value: PDFHexString.fromText(optionsArr[idx]) };
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
this.acroField.setOptions(existingOptions.concat(newOptions));
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Select one or more values for this option list. This operation is analogous
|
|
186
|
-
* to a human user opening the option list in a PDF reader and clicking on one
|
|
187
|
-
* or more values to select them. This method will update the underlying state
|
|
188
|
-
* of the option list to indicate which values have been selected. PDF
|
|
189
|
-
* libraries and readers will be able to extract these values from the saved
|
|
190
|
-
* document and determine which values were selected.
|
|
191
|
-
* For example:
|
|
192
|
-
* ```js
|
|
193
|
-
* const optionList = form.getOptionList('best.superheroes.optionList')
|
|
194
|
-
* optionList.select(['One Punch Man', 'Iron Man'])
|
|
195
|
-
* ```
|
|
196
|
-
* This method will mark this option list as dirty. See
|
|
197
|
-
* [[PDFOptionList.setOptions]] for more details about what this means.
|
|
198
|
-
* @param options The options to be selected.
|
|
199
|
-
* @param merge Whether or not existing selections should be preserved.
|
|
200
|
-
*/
|
|
201
|
-
select(options: string | string[], merge = false) {
|
|
202
|
-
assertIs(options, 'options', ['string', Array]);
|
|
203
|
-
assertIs(merge, 'merge', ['boolean']);
|
|
204
|
-
|
|
205
|
-
const optionsArr = Array.isArray(options) ? options : [options];
|
|
206
|
-
|
|
207
|
-
const validOptions = this.getOptions();
|
|
208
|
-
assertIsSubset(optionsArr, 'option', validOptions);
|
|
209
|
-
|
|
210
|
-
this.markAsDirty();
|
|
211
|
-
|
|
212
|
-
if (optionsArr.length > 1 || (optionsArr.length === 1 && merge)) {
|
|
213
|
-
this.enableMultiselect();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const values = Array<PDFHexString>(optionsArr.length);
|
|
217
|
-
for (let idx = 0, len = optionsArr.length; idx < len; idx++) {
|
|
218
|
-
values[idx] = PDFHexString.fromText(optionsArr[idx]);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (merge) {
|
|
222
|
-
const existingValues = this.acroField.getValues();
|
|
223
|
-
this.acroField.setValues(existingValues.concat(values));
|
|
224
|
-
} else {
|
|
225
|
-
this.acroField.setValues(values);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Clear all selected values for this option list. This operation is
|
|
231
|
-
* equivalent to selecting an empty list. This method will update the
|
|
232
|
-
* underlying state of the option list to indicate that no values have been
|
|
233
|
-
* selected.
|
|
234
|
-
* For example:
|
|
235
|
-
* ```js
|
|
236
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
237
|
-
* optionList.clear()
|
|
238
|
-
* ```
|
|
239
|
-
* This method will mark this option list as dirty. See
|
|
240
|
-
* [[PDFOptionList.setOptions]] for more details about what this means.
|
|
241
|
-
*/
|
|
242
|
-
clear() {
|
|
243
|
-
this.markAsDirty();
|
|
244
|
-
this.acroField.setValues([]);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Set the font size for the text in this field. There needs to be a
|
|
249
|
-
* default appearance string (DA) set with a font value specified
|
|
250
|
-
* for this to work. For example:
|
|
251
|
-
* ```js
|
|
252
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
253
|
-
* optionList.setFontSize(4);
|
|
254
|
-
* ```
|
|
255
|
-
* @param fontSize The font size to set the font to.
|
|
256
|
-
*/
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Set the font size for this field. Larger font sizes will result in larger
|
|
260
|
-
* text being displayed when PDF readers render this option list. Font sizes
|
|
261
|
-
* may be integer or floating point numbers. Supplying a negative font size
|
|
262
|
-
* will cause this method to throw an error.
|
|
263
|
-
*
|
|
264
|
-
* For example:
|
|
265
|
-
* ```js
|
|
266
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
267
|
-
* optionList.setFontSize(4)
|
|
268
|
-
* optionList.setFontSize(15.7)
|
|
269
|
-
* ```
|
|
270
|
-
*
|
|
271
|
-
* > This method depends upon the existence of a default appearance
|
|
272
|
-
* > (`/DA`) string. If this field does not have a default appearance string,
|
|
273
|
-
* > or that string does not contain a font size (via the `Tf` operator),
|
|
274
|
-
* > then this method will throw an error.
|
|
275
|
-
*
|
|
276
|
-
* @param fontSize The font size to be used when rendering text in this field.
|
|
277
|
-
*/
|
|
278
|
-
setFontSize(fontSize: number) {
|
|
279
|
-
assertPositive(fontSize, 'fontSize');
|
|
280
|
-
this.acroField.setFontSize(fontSize);
|
|
281
|
-
this.markAsDirty();
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Returns `true` if the options of this option list are always displayed
|
|
286
|
-
* in alphabetical order, irrespective of the order in which the options
|
|
287
|
-
* were added to the option list. See [[PDFOptionList.enableSorting]] and
|
|
288
|
-
* [[PDFOptionList.disableSorting]]. For example:
|
|
289
|
-
* ```js
|
|
290
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
291
|
-
* if (optionList.isSorted()) console.log('Sorting is enabled')
|
|
292
|
-
* ```
|
|
293
|
-
* @returns Whether or not this option list is sorted.
|
|
294
|
-
*/
|
|
295
|
-
isSorted(): boolean {
|
|
296
|
-
return this.acroField.hasFlag(AcroChoiceFlags.Sort);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Always display the options of this option list in alphabetical order,
|
|
301
|
-
* irrespective of the order in which the options were added to this option
|
|
302
|
-
* list.
|
|
303
|
-
* For example:
|
|
304
|
-
* ```js
|
|
305
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
306
|
-
* optionList.enableSorting()
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
enableSorting() {
|
|
310
|
-
this.acroField.setFlagTo(AcroChoiceFlags.Sort, true);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Do not always display the options of this option list in alphabetical
|
|
315
|
-
* order. Instead, display the options in whichever order they were added
|
|
316
|
-
* to this option list. For example:
|
|
317
|
-
* ```js
|
|
318
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
319
|
-
* optionList.disableSorting()
|
|
320
|
-
* ```
|
|
321
|
-
*/
|
|
322
|
-
disableSorting() {
|
|
323
|
-
this.acroField.setFlagTo(AcroChoiceFlags.Sort, false);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Returns `true` if multiple options can be selected from this option list.
|
|
328
|
-
* See [[PDFOptionList.enableMultiselect]] and
|
|
329
|
-
* [[PDFOptionList.disableMultiselect]]. For example:
|
|
330
|
-
* ```js
|
|
331
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
332
|
-
* if (optionList.isMultiselect()) console.log('Multiselect is enabled')
|
|
333
|
-
* ```
|
|
334
|
-
* @returns Whether or not multiple options can be selected.
|
|
335
|
-
*/
|
|
336
|
-
isMultiselect(): boolean {
|
|
337
|
-
return this.acroField.hasFlag(AcroChoiceFlags.MultiSelect);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Allow users to select more than one option from this option list.
|
|
342
|
-
* For example:
|
|
343
|
-
* ```js
|
|
344
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
345
|
-
* optionList.enableMultiselect()
|
|
346
|
-
* ```
|
|
347
|
-
*/
|
|
348
|
-
enableMultiselect() {
|
|
349
|
-
this.acroField.setFlagTo(AcroChoiceFlags.MultiSelect, true);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Do not allow users to select more than one option from this option list.
|
|
354
|
-
* For example:
|
|
355
|
-
* ```js
|
|
356
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
357
|
-
* optionList.disableMultiselect()
|
|
358
|
-
* ```
|
|
359
|
-
*/
|
|
360
|
-
disableMultiselect() {
|
|
361
|
-
this.acroField.setFlagTo(AcroChoiceFlags.MultiSelect, false);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Returns `true` if the option selected by a user is stored, or "committed",
|
|
366
|
-
* when the user clicks the option. The alternative is that the user's
|
|
367
|
-
* selection is stored when the user leaves this option list field (by
|
|
368
|
-
* clicking outside of it - on another field, for example). See
|
|
369
|
-
* [[PDFOptionList.enableSelectOnClick]] and
|
|
370
|
-
* [[PDFOptionList.disableSelectOnClick]]. For example:
|
|
371
|
-
* ```js
|
|
372
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
373
|
-
* if (optionList.isSelectOnClick()) console.log('Select on click is enabled')
|
|
374
|
-
* ```
|
|
375
|
-
* @returns Whether or not options are selected immediately after they are
|
|
376
|
-
* clicked.
|
|
377
|
-
*/
|
|
378
|
-
isSelectOnClick(): boolean {
|
|
379
|
-
return this.acroField.hasFlag(AcroChoiceFlags.CommitOnSelChange);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Store the option selected by a user immediately after the user clicks the
|
|
384
|
-
* option. Do not wait for the user to leave this option list field (by
|
|
385
|
-
* clicking outside of it - on another field, for example). For example:
|
|
386
|
-
* ```js
|
|
387
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
388
|
-
* optionList.enableSelectOnClick()
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
enableSelectOnClick() {
|
|
392
|
-
this.acroField.setFlagTo(AcroChoiceFlags.CommitOnSelChange, true);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Wait to store the option selected by a user until they leave this option
|
|
397
|
-
* list field (by clicking outside of it - on another field, for example).
|
|
398
|
-
* For example:
|
|
399
|
-
* ```js
|
|
400
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
401
|
-
* optionList.disableSelectOnClick()
|
|
402
|
-
* ```
|
|
403
|
-
*/
|
|
404
|
-
disableSelectOnClick() {
|
|
405
|
-
this.acroField.setFlagTo(AcroChoiceFlags.CommitOnSelChange, false);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* Show this option list on the specified page. For example:
|
|
410
|
-
* ```js
|
|
411
|
-
* const ubuntuFont = await pdfDoc.embedFont(ubuntuFontBytes)
|
|
412
|
-
* const page = pdfDoc.addPage()
|
|
413
|
-
*
|
|
414
|
-
* const form = pdfDoc.getForm()
|
|
415
|
-
* const optionList = form.createOptionList('best.gundams')
|
|
416
|
-
* optionList.setOptions(['Exia', 'Dynames', 'Kyrios', 'Virtue'])
|
|
417
|
-
* optionList.select(['Exia', 'Virtue'])
|
|
418
|
-
*
|
|
419
|
-
* optionList.addToPage(page, {
|
|
420
|
-
* x: 50,
|
|
421
|
-
* y: 75,
|
|
422
|
-
* width: 200,
|
|
423
|
-
* height: 100,
|
|
424
|
-
* textColor: rgb(1, 0, 0),
|
|
425
|
-
* backgroundColor: rgb(0, 1, 0),
|
|
426
|
-
* borderColor: rgb(0, 0, 1),
|
|
427
|
-
* borderWidth: 2,
|
|
428
|
-
* rotate: degrees(90),
|
|
429
|
-
* font: ubuntuFont,
|
|
430
|
-
* })
|
|
431
|
-
* ```
|
|
432
|
-
* This will create a new widget for this option list field.
|
|
433
|
-
* @param page The page to which this option list widget should be added.
|
|
434
|
-
* @param options The options to be used when adding this option list widget.
|
|
435
|
-
*/
|
|
436
|
-
addToPage(page: PDFPage, options?: FieldAppearanceOptions) {
|
|
437
|
-
assertIs(page, 'page', [[PDFPage, 'PDFPage']]);
|
|
438
|
-
assertFieldAppearanceOptions(options);
|
|
439
|
-
|
|
440
|
-
if (!options) options = {};
|
|
441
|
-
|
|
442
|
-
if (!('textColor' in options)) options.textColor = rgb(0, 0, 0);
|
|
443
|
-
if (!('backgroundColor' in options)) options.backgroundColor = rgb(1, 1, 1);
|
|
444
|
-
if (!('borderColor' in options)) options.borderColor = rgb(0, 0, 0);
|
|
445
|
-
if (!('borderWidth' in options)) options.borderWidth = 1;
|
|
446
|
-
|
|
447
|
-
// Create a widget for this option list
|
|
448
|
-
const widget = this.createWidget({
|
|
449
|
-
x: options.x ?? 0,
|
|
450
|
-
y: options.y ?? 0,
|
|
451
|
-
width: options.width ?? 200,
|
|
452
|
-
height: options.height ?? 100,
|
|
453
|
-
textColor: options.textColor,
|
|
454
|
-
backgroundColor: options.backgroundColor,
|
|
455
|
-
borderColor: options.borderColor,
|
|
456
|
-
borderWidth: options.borderWidth ?? 0,
|
|
457
|
-
rotate: options.rotate ?? degrees(0),
|
|
458
|
-
hidden: options.hidden,
|
|
459
|
-
page: page.ref,
|
|
460
|
-
});
|
|
461
|
-
const widgetRef = this.doc.context.register(widget.dict);
|
|
462
|
-
|
|
463
|
-
// Add widget to this field
|
|
464
|
-
this.acroField.addWidget(widgetRef);
|
|
465
|
-
|
|
466
|
-
// Set appearance streams for widget
|
|
467
|
-
const font = options.font ?? this.doc.getForm().getDefaultFont();
|
|
468
|
-
this.updateWidgetAppearance(widget, font);
|
|
469
|
-
|
|
470
|
-
// Add widget to the given page
|
|
471
|
-
page.node.addAnnot(widgetRef);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Returns `true` if this option list has been marked as dirty, or if any of
|
|
476
|
-
* this option list's widgets do not have an appearance stream. For example:
|
|
477
|
-
* ```js
|
|
478
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
479
|
-
* if (optionList.needsAppearancesUpdate()) console.log('Needs update')
|
|
480
|
-
* ```
|
|
481
|
-
* @returns Whether or not this option list needs an appearance update.
|
|
482
|
-
*/
|
|
483
|
-
needsAppearancesUpdate(): boolean {
|
|
484
|
-
if (this.isDirty()) return true;
|
|
485
|
-
|
|
486
|
-
const widgets = this.acroField.getWidgets();
|
|
487
|
-
for (let idx = 0, len = widgets.length; idx < len; idx++) {
|
|
488
|
-
const widget = widgets[idx];
|
|
489
|
-
const hasAppearances = widget.getAppearances()?.normal instanceof PDFStream;
|
|
490
|
-
if (!hasAppearances) return true;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
return false;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Update the appearance streams for each of this option list's widgets using
|
|
498
|
-
* the default appearance provider for option lists. For example:
|
|
499
|
-
* ```js
|
|
500
|
-
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
|
501
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
502
|
-
* optionList.defaultUpdateAppearances(helvetica)
|
|
503
|
-
* ```
|
|
504
|
-
* @param font The font to be used for creating the appearance streams.
|
|
505
|
-
*/
|
|
506
|
-
defaultUpdateAppearances(font: PDFFont) {
|
|
507
|
-
assertIs(font, 'font', [[PDFFont, 'PDFFont']]);
|
|
508
|
-
this.updateAppearances(font);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* Update the appearance streams for each of this option list's widgets using
|
|
513
|
-
* the given appearance provider. If no `provider` is passed, the default
|
|
514
|
-
* appearance provider for option lists will be used. For example:
|
|
515
|
-
* ```js
|
|
516
|
-
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
|
517
|
-
* const optionList = form.getOptionList('some.optionList.field')
|
|
518
|
-
* optionList.updateAppearances(helvetica, (field, widget, font) => {
|
|
519
|
-
* ...
|
|
520
|
-
* return drawOptionList(...)
|
|
521
|
-
* })
|
|
522
|
-
* ```
|
|
523
|
-
* @param font The font to be used for creating the appearance streams.
|
|
524
|
-
* @param provider Optionally, the appearance provider to be used for
|
|
525
|
-
* generating the contents of the appearance streams.
|
|
526
|
-
*/
|
|
527
|
-
updateAppearances(font: PDFFont, provider?: AppearanceProviderFor<PDFOptionList>) {
|
|
528
|
-
assertIs(font, 'font', [[PDFFont, 'PDFFont']]);
|
|
529
|
-
assertOrUndefined(provider, 'provider', [Function]);
|
|
530
|
-
|
|
531
|
-
const widgets = this.acroField.getWidgets();
|
|
532
|
-
for (let idx = 0, len = widgets.length; idx < len; idx++) {
|
|
533
|
-
const widget = widgets[idx];
|
|
534
|
-
this.updateWidgetAppearance(widget, font, provider);
|
|
535
|
-
}
|
|
536
|
-
this.markAsClean();
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
// getOption(index: number): string {}
|
|
540
|
-
// getSelectedIndices(): number[] {}
|
|
541
|
-
// removeOptions(option: string | string[]) {}
|
|
542
|
-
// removeIndices(option: number[]) {}
|
|
543
|
-
// deselect(options: string | string[]) {}
|
|
544
|
-
// deselectIndices(optionIndices: number[]) {}
|
|
545
|
-
|
|
546
|
-
private updateWidgetAppearance(
|
|
547
|
-
widget: PDFWidgetAnnotation,
|
|
548
|
-
font: PDFFont,
|
|
549
|
-
provider?: AppearanceProviderFor<PDFOptionList>,
|
|
550
|
-
) {
|
|
551
|
-
const apProvider = provider ?? defaultOptionListAppearanceProvider;
|
|
552
|
-
const appearances = normalizeAppearance(apProvider(this, widget, font));
|
|
553
|
-
this.updateWidgetAppearanceWithFont(widget, font, appearances);
|
|
554
|
-
}
|
|
555
|
-
}
|