@pdfme/pdf-lib 6.0.3-dev.0 → 6.0.4-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src/api/Embeddable.ts → dist/api/Embeddable.d.ts} +1 -1
- package/dist/api/PDFDocument.d.ts +778 -0
- package/dist/api/PDFDocumentOptions.d.ts +38 -0
- package/dist/api/PDFEmbeddedFile.d.ts +38 -0
- package/dist/api/PDFEmbeddedPage.d.ts +73 -0
- package/dist/api/PDFFont.d.ts +94 -0
- package/dist/api/PDFImage.d.ts +95 -0
- package/dist/api/PDFJavaScript.d.ts +38 -0
- package/dist/api/PDFPage.d.ts +910 -0
- package/dist/api/PDFPageOptions.d.ts +172 -0
- package/dist/api/StandardFonts.d.ts +16 -0
- package/dist/api/colors.d.ts +34 -0
- package/dist/api/errors.d.ts +42 -0
- package/dist/api/form/PDFButton.d.ts +137 -0
- package/dist/api/form/PDFCheckBox.d.ts +142 -0
- package/dist/api/form/PDFDropdown.d.ts +402 -0
- package/dist/api/form/PDFField.d.ts +203 -0
- package/dist/api/form/PDFForm.d.ts +411 -0
- package/dist/api/form/PDFOptionList.d.ts +335 -0
- package/dist/api/form/PDFRadioGroup.d.ts +252 -0
- package/dist/api/form/PDFSignature.d.ts +29 -0
- package/dist/api/form/PDFTextField.d.ts +537 -0
- package/dist/api/form/appearances.d.ts +41 -0
- package/dist/api/image/alignment.d.ts +5 -0
- package/dist/api/objects.d.ts +4 -0
- package/dist/api/operations.d.ts +226 -0
- package/dist/api/operators.d.ts +90 -0
- package/dist/api/rotations.d.ts +38 -0
- package/dist/api/sizes.d.ts +52 -0
- package/dist/api/svg.d.ts +70 -0
- package/dist/api/svgPath.d.ts +2 -0
- package/dist/api/text/alignment.d.ts +5 -0
- package/dist/api/text/layout.d.ts +54 -0
- package/dist/core/PDFContext.d.ts +84 -0
- package/dist/core/PDFObjectCopier.d.ts +37 -0
- package/dist/core/acroform/PDFAcroButton.d.ts +21 -0
- package/dist/core/acroform/PDFAcroCheckBox.d.ts +13 -0
- package/dist/core/acroform/PDFAcroChoice.d.ts +20 -0
- package/dist/core/acroform/PDFAcroComboBox.d.ts +9 -0
- package/dist/core/acroform/PDFAcroField.d.ts +36 -0
- package/dist/core/acroform/PDFAcroForm.d.ts +20 -0
- package/dist/core/acroform/PDFAcroListBox.d.ts +9 -0
- package/dist/core/acroform/PDFAcroNonTerminal.d.ts +13 -0
- package/dist/core/acroform/PDFAcroPushButton.d.ts +9 -0
- package/dist/core/acroform/PDFAcroRadioButton.d.ts +13 -0
- package/{src/core/acroform/PDFAcroSignature.ts → dist/core/acroform/PDFAcroSignature.d.ts} +2 -4
- package/dist/core/acroform/PDFAcroTerminal.d.ts +16 -0
- package/dist/core/acroform/PDFAcroText.d.ts +22 -0
- package/dist/core/acroform/flags.d.ts +141 -0
- package/dist/core/acroform/utils.d.ts +6 -0
- package/dist/core/annotation/AppearanceCharacteristics.d.ts +33 -0
- package/dist/core/annotation/BorderStyle.d.ts +11 -0
- package/dist/core/annotation/PDFAnnotation.d.ts +51 -0
- package/dist/core/annotation/PDFWidgetAnnotation.d.ts +26 -0
- package/dist/core/annotation/flags.d.ts +79 -0
- package/dist/core/crypto.d.ts +95 -0
- package/dist/core/document/PDFCrossRefSection.d.ts +27 -0
- package/dist/core/document/PDFHeader.d.ts +10 -0
- package/dist/core/document/PDFTrailer.d.ts +9 -0
- package/dist/core/document/PDFTrailerDict.d.ts +10 -0
- package/dist/core/embedders/CMap.d.ts +3 -0
- package/dist/core/embedders/CustomFontEmbedder.d.ts +44 -0
- package/dist/core/embedders/CustomFontSubsetEmbedder.d.ts +20 -0
- package/dist/core/embedders/FileEmbedder.d.ts +33 -0
- package/dist/core/embedders/FontFlags.d.ts +13 -0
- package/dist/core/embedders/JavaScriptEmbedder.d.ts +10 -0
- package/dist/core/embedders/JpegEmbedder.d.ts +23 -0
- package/dist/core/embedders/PDFPageEmbedder.d.ts +37 -0
- package/dist/core/embedders/PngEmbedder.d.ts +19 -0
- package/dist/core/embedders/StandardFontEmbedder.d.ts +36 -0
- package/dist/core/errors.d.ts +94 -0
- package/{src/core/index.ts → dist/core/index.d.ts} +1 -17
- package/dist/core/interactive/ViewerPreferences.d.ts +347 -0
- package/dist/core/objects/PDFArray.d.ts +63 -0
- package/dist/core/objects/PDFBool.d.ts +13 -0
- package/dist/core/objects/PDFDict.d.ts +62 -0
- package/dist/core/objects/PDFHexString.d.ts +16 -0
- package/dist/core/objects/PDFInvalidObject.d.ts +11 -0
- package/dist/core/objects/PDFName.d.ts +41 -0
- package/dist/core/objects/PDFNull.d.ts +10 -0
- package/dist/core/objects/PDFNumber.d.ts +15 -0
- package/dist/core/objects/PDFObject.d.ts +8 -0
- package/dist/core/objects/PDFRawStream.d.ts +16 -0
- package/dist/core/objects/PDFRef.d.ts +13 -0
- package/dist/core/objects/PDFStream.d.ts +16 -0
- package/dist/core/objects/PDFString.d.ts +16 -0
- package/dist/core/operators/PDFOperator.d.ts +19 -0
- package/dist/core/operators/PDFOperatorNames.d.ts +76 -0
- package/dist/core/parser/BaseParser.d.ts +14 -0
- package/dist/core/parser/ByteStream.d.ts +26 -0
- package/dist/core/parser/PDFObjectParser.d.ts +31 -0
- package/dist/core/parser/PDFObjectStreamParser.d.ts +13 -0
- package/dist/core/parser/PDFParser.d.ts +46 -0
- package/dist/core/parser/PDFXRefStreamParser.d.ts +21 -0
- package/dist/core/streams/Ascii85Stream.d.ts +9 -0
- package/dist/core/streams/AsciiHexStream.d.ts +9 -0
- package/dist/core/streams/DecodeStream.d.ts +26 -0
- package/dist/core/streams/DecryptStream.d.ts +12 -0
- package/dist/core/streams/FlateStream.d.ts +13 -0
- package/dist/core/streams/LZWStream.d.ts +12 -0
- package/dist/core/streams/RunLengthStream.d.ts +8 -0
- package/dist/core/streams/Stream.d.ts +34 -0
- package/dist/core/streams/decode.d.ts +3 -0
- package/dist/core/structures/PDFCatalog.d.ts +27 -0
- package/dist/core/structures/PDFContentStream.d.ts +15 -0
- package/dist/core/structures/PDFCrossRefStream.d.ts +53 -0
- package/dist/core/structures/PDFFlateStream.d.ts +13 -0
- package/dist/core/structures/PDFObjectStream.d.ts +20 -0
- package/dist/core/structures/PDFPageLeaf.d.ts +54 -0
- package/dist/core/structures/PDFPageTree.d.ts +41 -0
- package/dist/core/syntax/CharCodes.d.ts +61 -0
- package/dist/core/syntax/Delimiters.d.ts +1 -0
- package/dist/core/syntax/Irregular.d.ts +1 -0
- package/dist/core/syntax/Keywords.d.ts +22 -0
- package/dist/core/syntax/Numeric.d.ts +3 -0
- package/dist/core/syntax/Whitespace.d.ts +1 -0
- package/dist/core/writers/PDFStreamWriter.d.ts +19 -0
- package/dist/core/writers/PDFWriter.d.ts +29 -0
- package/dist/index.js +19124 -0
- package/dist/index.js.map +1 -0
- package/dist/types/fontkit.d.ts +597 -0
- package/{src/types/index.ts → dist/types/index.d.ts} +8 -13
- package/{src/types/matrix.ts → dist/types/matrix.d.ts} +1 -2
- package/dist/utils/Cache.d.ts +10 -0
- package/dist/utils/arrays.d.ts +16 -0
- package/dist/utils/async.d.ts +5 -0
- package/dist/utils/base64.d.ts +10 -0
- package/dist/utils/elements/Arc.d.ts +22 -0
- package/dist/utils/elements/Circle.d.ts +14 -0
- package/dist/utils/elements/Ellipse.d.ts +20 -0
- package/dist/utils/elements/GraphElement.d.ts +6 -0
- package/dist/utils/elements/Line.d.ts +23 -0
- package/dist/utils/elements/Plot.d.ts +11 -0
- package/dist/utils/elements/Point.d.ts +18 -0
- package/dist/utils/elements/Rectangle.d.ts +21 -0
- package/dist/utils/elements/Segment.d.ts +19 -0
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/intersections.d.ts +9 -0
- package/dist/utils/maths.d.ts +45 -0
- package/dist/utils/numbers.d.ts +23 -0
- package/dist/utils/objects.d.ts +15 -0
- package/dist/utils/pdfDocEncoding.d.ts +7 -0
- package/dist/utils/png.d.ts +17 -0
- package/dist/utils/rng.d.ts +13 -0
- package/dist/utils/strings.d.ts +25 -0
- package/{src/utils/unicode.ts → dist/utils/unicode.d.ts} +8 -195
- package/dist/utils/validators.d.ts +26 -0
- package/package.json +6 -1
- package/__tests__/api/PDFDocument.spec.ts +0 -576
- package/__tests__/api/PDFImage.spec.ts +0 -60
- package/__tests__/api/PDFPage.spec.ts +0 -151
- package/__tests__/api/form/PDFCheckBox.spec.ts +0 -71
- package/__tests__/api/form/PDFDropdown.spec.ts +0 -118
- package/__tests__/api/form/PDFForm.spec.ts +0 -370
- package/__tests__/api/form/PDFOptionList.spec.ts +0 -104
- package/__tests__/api/form/PDFRadioGroup.spec.ts +0 -183
- package/__tests__/api/form/PDFTextField.spec.ts +0 -148
- package/__tests__/api/svgPath.spec.ts +0 -153
- package/__tests__/api/text/layout.spec.ts +0 -166
- package/__tests__/core/PDFContext.spec.ts +0 -194
- package/__tests__/core/PDFObjectCopier.spec.ts +0 -421
- package/__tests__/core/acroform/PDFAcroField.spec.ts +0 -98
- package/__tests__/core/acroform/PDFAcroTerminal.spec.ts +0 -39
- package/__tests__/core/annotation/PDFWidgetAnnotation.spec.ts +0 -40
- package/__tests__/core/document/PDFCrossRefSection.spec.ts +0 -88
- package/__tests__/core/document/PDFHeader.spec.ts +0 -22
- package/__tests__/core/document/PDFTrailer.spec.ts +0 -28
- package/__tests__/core/document/PDFTrailerDict.spec.ts +0 -24
- package/__tests__/core/embedders/CMap.spec.ts +0 -47
- package/__tests__/core/embedders/CustomFontEmbedder.spec.ts +0 -96
- package/__tests__/core/embedders/CustomFontSubsetEmbedder.spec.ts +0 -62
- package/__tests__/core/embedders/FileEmbedder.spec.ts +0 -54
- package/__tests__/core/embedders/JpegEmbedder.spec.ts +0 -67
- package/__tests__/core/embedders/PDFPageEmbedder.spec.ts +0 -65
- package/__tests__/core/embedders/PngEmbedder.spec.ts +0 -87
- package/__tests__/core/embedders/StandardFontEmbedder.spec.ts +0 -79
- package/__tests__/core/embedders/data/SourceHanSerifJP-Regular.otf.cmap +0 -16096
- package/__tests__/core/embedders/data/Ubuntu-R.ttf.cmap +0 -1211
- package/__tests__/core/objects/PDFArray.spec.ts +0 -134
- package/__tests__/core/objects/PDFBool.spec.ts +0 -42
- package/__tests__/core/objects/PDFDict.spec.ts +0 -195
- package/__tests__/core/objects/PDFHexString.spec.ts +0 -168
- package/__tests__/core/objects/PDFInvalidObject.spec.ts +0 -32
- package/__tests__/core/objects/PDFName.spec.ts +0 -122
- package/__tests__/core/objects/PDFNull.spec.ts +0 -30
- package/__tests__/core/objects/PDFNumber.spec.ts +0 -50
- package/__tests__/core/objects/PDFObject.spec.ts +0 -29
- package/__tests__/core/objects/PDFRawStream.spec.ts +0 -45
- package/__tests__/core/objects/PDFRef.spec.ts +0 -60
- package/__tests__/core/objects/PDFString.spec.ts +0 -237
- package/__tests__/core/operators/PDFOperator.spec.ts +0 -77
- package/__tests__/core/parser/PDFObjectParser.spec.ts +0 -730
- package/__tests__/core/parser/PDFObjectStreamParser.spec.ts +0 -158
- package/__tests__/core/parser/PDFParser.spec.ts +0 -398
- package/__tests__/core/parser/PDFXRefStreamParser.spec.ts +0 -187
- package/__tests__/core/parser/data/object-stream-invalid +0 -2
- package/__tests__/core/parser/data/object-stream1 +0 -16
- package/__tests__/core/parser/data/object-stream2 +0 -10
- package/__tests__/core/parser/data/object-stream3 +0 -0
- package/__tests__/core/parser/data/object-stream4 +0 -0
- package/__tests__/core/parser/data/xref-stream1 +0 -0
- package/__tests__/core/parser/data/xref-stream2 +0 -0
- package/__tests__/core/parser/data/xref-stream3 +0 -0
- package/__tests__/core/parser/data/xref-stream4 +0 -0
- package/__tests__/core/streams/Ascii85Stream.spec.ts +0 -20
- package/__tests__/core/streams/AsciiHexStream.spec.ts +0 -20
- package/__tests__/core/streams/FlateStream.spec.ts +0 -20
- package/__tests__/core/streams/LZWStream.spec.ts +0 -20
- package/__tests__/core/streams/RunLengthStream.spec.ts +0 -20
- package/__tests__/core/streams/Stream.spec.ts +0 -128
- package/__tests__/core/streams/data/ascii85/1.decoded +0 -0
- package/__tests__/core/streams/data/ascii85/1.encoded +0 -43
- package/__tests__/core/streams/data/asciihex/1.decoded +0 -1
- package/__tests__/core/streams/data/asciihex/1.encoded +0 -1
- package/__tests__/core/streams/data/asciihex/2.decoded +0 -7
- package/__tests__/core/streams/data/asciihex/2.encoded +0 -1
- package/__tests__/core/streams/data/flate/1.corrupt.encoded +0 -1
- package/__tests__/core/streams/data/flate/1.decoded +0 -0
- package/__tests__/core/streams/data/flate/1.encoded +0 -2
- package/__tests__/core/streams/data/flate/2.decoded +0 -33
- package/__tests__/core/streams/data/flate/2.encoded +0 -0
- package/__tests__/core/streams/data/flate/3.decoded +0 -15
- package/__tests__/core/streams/data/flate/3.encoded +0 -0
- package/__tests__/core/streams/data/flate/4.decoded +0 -16
- package/__tests__/core/streams/data/flate/4.encoded +0 -0
- package/__tests__/core/streams/data/flate/5.decoded +0 -0
- package/__tests__/core/streams/data/flate/5.encoded +0 -0
- package/__tests__/core/streams/data/flate/6.decoded +0 -17
- package/__tests__/core/streams/data/flate/6.encoded +0 -0
- package/__tests__/core/streams/data/flate/7.decoded +0 -20
- package/__tests__/core/streams/data/flate/7.encoded +0 -1
- package/__tests__/core/streams/data/lzw/1.decoded +0 -0
- package/__tests__/core/streams/data/lzw/1.encoded +0 -0
- package/__tests__/core/streams/data/lzw/2.decoded +0 -0
- package/__tests__/core/streams/data/lzw/2.encoded +0 -0
- package/__tests__/core/streams/data/lzw/3.decoded +0 -14
- package/__tests__/core/streams/data/lzw/3.encoded +0 -2
- package/__tests__/core/streams/data/lzw/4.decoded +0 -14
- package/__tests__/core/streams/data/lzw/4.encoded +0 -2
- package/__tests__/core/streams/data/runlength/1.decoded +0 -1
- package/__tests__/core/streams/data/runlength/1.encoded +0 -1
- package/__tests__/core/streams/data/runlength/2.decoded +0 -1
- package/__tests__/core/streams/data/runlength/2.encoded +0 -1
- package/__tests__/core/streams/data/runlength/3.decoded +0 -0
- package/__tests__/core/streams/data/runlength/3.encoded +0 -0
- package/__tests__/core/streams/data/runlength/4.decoded +0 -1
- package/__tests__/core/streams/data/runlength/4.encoded +0 -1
- package/__tests__/core/streams/data/runlength/5.decoded +0 -1
- package/__tests__/core/streams/data/runlength/5.encoded +0 -1
- package/__tests__/core/streams/data/runlength/empty.encoded +0 -1
- package/__tests__/core/structures/PDFCatalog.spec.ts +0 -108
- package/__tests__/core/structures/PDFContentStream.spec.ts +0 -117
- package/__tests__/core/structures/PDFCrossRefStream.spec.ts +0 -145
- package/__tests__/core/structures/PDFObjectStream.spec.ts +0 -138
- package/__tests__/core/structures/PDFPageLeaf.spec.ts +0 -355
- package/__tests__/core/structures/PDFPageTree.spec.ts +0 -592
- package/__tests__/core/writers/PDFStreamWriter.spec.ts +0 -71
- package/__tests__/core/writers/PDFWriter.spec.ts +0 -144
- package/__tests__/core/writers/data/stream-writer-1.pdf +0 -0
- package/__tests__/index.test.ts +0 -12
- package/__tests__/utils/base64.spec.ts +0 -61
- package/__tests__/utils/data/simple.pdf +0 -201
- package/__tests__/utils/data/simple.pdf.base64 +0 -1
- package/__tests__/utils/pdfDocEncoding.spec.ts +0 -82
- package/__tests__/utils/png.spec.ts +0 -53
- package/__tests__/utils/rng.spec.ts +0 -14
- package/__tests__/utils/strings.spec.ts +0 -98
- package/__tests__/utils/unicode.spec.ts +0 -337
- package/assets/fonts/source_hans_jp/SourceHanSerifJP-Regular.otf +0 -0
- package/assets/fonts/ubuntu/Ubuntu-B.ttf +0 -0
- package/assets/fonts/ubuntu/Ubuntu-R.ttf +0 -0
- package/assets/images/cat_riding_unicorn.jpg +0 -0
- package/assets/images/cmyk_colorspace.jpg +0 -0
- package/assets/images/greyscale_bird.png +0 -0
- package/assets/images/minions_banana_alpha.png +0 -0
- package/assets/images/minions_banana_no_alpha.png +0 -0
- package/assets/images/minions_laughing.jpg +0 -0
- package/assets/pdfs/bixby_guide.pdf +0 -0
- package/assets/pdfs/encrypted_new.pdf +0 -0
- package/assets/pdfs/encrypted_old.pdf +0 -0
- package/assets/pdfs/fancy_fields.pdf +0 -0
- package/assets/pdfs/giraffe.pdf +0 -0
- package/assets/pdfs/invalid_root_ref.pdf +0 -0
- package/assets/pdfs/just_metadata.pdf +0 -49
- package/assets/pdfs/missing_endobj_keyword.pdf +0 -70
- package/assets/pdfs/missing_xref_trailer_dict.pdf +0 -141
- package/assets/pdfs/normal.pdf +0 -0
- package/assets/pdfs/pdf20examples/PDF 2.0 with offset start.pdf +0 -179
- package/assets/pdfs/stuff_following_header.pdf +0 -0
- package/assets/pdfs/us_constitution.pdf +0 -0
- package/assets/pdfs/with_comments.pdf +0 -0
- package/assets/pdfs/with_invalid_objects.pdf +0 -53
- package/assets/pdfs/with_invalid_stream_EOL.pdf +0 -0
- package/assets/pdfs/with_null_parent_entry.pdf +0 -0
- package/assets/pdfs/with_signature.pdf +0 -0
- package/assets/pdfs/with_update_sections.pdf +0 -0
- package/assets/pdfs/with_viewer_prefs.pdf +0 -0
- package/assets/pdfs/with_xfa_fields.pdf +0 -0
- package/src/api/PDFDocument.ts +0 -1389
- package/src/api/PDFDocumentOptions.ts +0 -45
- package/src/api/PDFEmbeddedFile.ts +0 -87
- package/src/api/PDFEmbeddedPage.ts +0 -100
- package/src/api/PDFFont.ts +0 -149
- package/src/api/PDFImage.ts +0 -143
- package/src/api/PDFJavaScript.ts +0 -75
- package/src/api/PDFPage.ts +0 -1604
- package/src/api/PDFPageOptions.ts +0 -175
- package/src/api/StandardFonts.ts +0 -16
- package/src/api/colors.ts +0 -109
- package/src/api/errors.ts +0 -110
- package/src/api/form/PDFButton.ts +0 -242
- package/src/api/form/PDFCheckBox.ts +0 -247
- package/src/api/form/PDFDropdown.ts +0 -637
- package/src/api/form/PDFField.ts +0 -491
- package/src/api/form/PDFForm.ts +0 -842
- package/src/api/form/PDFOptionList.ts +0 -555
- package/src/api/form/PDFRadioGroup.ts +0 -455
- package/src/api/form/PDFSignature.ts +0 -44
- package/src/api/form/PDFTextField.ts +0 -811
- package/src/api/form/appearances.ts +0 -655
- package/src/api/image/alignment.ts +0 -5
- package/src/api/objects.ts +0 -10
- package/src/api/operations.ts +0 -873
- package/src/api/operators.ts +0 -335
- package/src/api/rotations.ts +0 -84
- package/src/api/sizes.ts +0 -52
- package/src/api/svg.ts +0 -888
- package/src/api/svgPath.ts +0 -460
- package/src/api/text/alignment.ts +0 -5
- package/src/api/text/layout.ts +0 -328
- package/src/core/PDFContext.ts +0 -274
- package/src/core/PDFObjectCopier.ts +0 -142
- package/src/core/acroform/PDFAcroButton.ts +0 -104
- package/src/core/acroform/PDFAcroCheckBox.ts +0 -48
- package/src/core/acroform/PDFAcroChoice.ts +0 -143
- package/src/core/acroform/PDFAcroComboBox.ts +0 -21
- package/src/core/acroform/PDFAcroField.ts +0 -168
- package/src/core/acroform/PDFAcroForm.ts +0 -96
- package/src/core/acroform/PDFAcroListBox.ts +0 -19
- package/src/core/acroform/PDFAcroNonTerminal.ts +0 -33
- package/src/core/acroform/PDFAcroPushButton.ts +0 -21
- package/src/core/acroform/PDFAcroRadioButton.ts +0 -57
- package/src/core/acroform/PDFAcroTerminal.ts +0 -70
- package/src/core/acroform/PDFAcroText.ts +0 -76
- package/src/core/acroform/flags.ts +0 -162
- package/src/core/acroform/utils.ts +0 -129
- package/src/core/annotation/AppearanceCharacteristics.ts +0 -133
- package/src/core/annotation/BorderStyle.ts +0 -31
- package/src/core/annotation/PDFAnnotation.ts +0 -148
- package/src/core/annotation/PDFWidgetAnnotation.ts +0 -111
- package/src/core/annotation/flags.ts +0 -90
- package/src/core/crypto.ts +0 -1844
- package/src/core/document/PDFCrossRefSection.ts +0 -161
- package/src/core/document/PDFHeader.ts +0 -48
- package/src/core/document/PDFTrailer.ts +0 -48
- package/src/core/document/PDFTrailerDict.ts +0 -39
- package/src/core/embedders/CMap.ts +0 -65
- package/src/core/embedders/CustomFontEmbedder.ts +0 -237
- package/src/core/embedders/CustomFontSubsetEmbedder.ts +0 -89
- package/src/core/embedders/FileEmbedder.ts +0 -77
- package/src/core/embedders/FontFlags.ts +0 -45
- package/src/core/embedders/JavaScriptEmbedder.ts +0 -34
- package/src/core/embedders/JpegEmbedder.ts +0 -118
- package/src/core/embedders/PDFPageEmbedder.ts +0 -139
- package/src/core/embedders/PngEmbedder.ts +0 -69
- package/src/core/embedders/StandardFontEmbedder.ts +0 -121
- package/src/core/errors.ts +0 -226
- package/src/core/interactive/ViewerPreferences.ts +0 -565
- package/src/core/objects/PDFArray.ts +0 -179
- package/src/core/objects/PDFBool.ts +0 -53
- package/src/core/objects/PDFDict.ts +0 -220
- package/src/core/objects/PDFHexString.ts +0 -94
- package/src/core/objects/PDFInvalidObject.ts +0 -34
- package/src/core/objects/PDFName.ts +0 -152
- package/src/core/objects/PDFNull.ts +0 -30
- package/src/core/objects/PDFNumber.ts +0 -44
- package/src/core/objects/PDFObject.ts +0 -22
- package/src/core/objects/PDFRawStream.ts +0 -41
- package/src/core/objects/PDFRef.ts +0 -51
- package/src/core/objects/PDFStream.ts +0 -87
- package/src/core/objects/PDFString.ts +0 -118
- package/src/core/operators/PDFOperator.ts +0 -72
- package/src/core/operators/PDFOperatorNames.ts +0 -92
- package/src/core/parser/BaseParser.ts +0 -119
- package/src/core/parser/ByteStream.ts +0 -76
- package/src/core/parser/PDFObjectParser.ts +0 -302
- package/src/core/parser/PDFObjectStreamParser.ts +0 -65
- package/src/core/parser/PDFParser.ts +0 -363
- package/src/core/parser/PDFXRefStreamParser.ts +0 -129
- package/src/core/streams/Ascii85Stream.ts +0 -97
- package/src/core/streams/AsciiHexStream.ts +0 -77
- package/src/core/streams/DecodeStream.ts +0 -188
- package/src/core/streams/DecryptStream.ts +0 -49
- package/src/core/streams/FlateStream.ts +0 -397
- package/src/core/streams/LZWStream.ts +0 -157
- package/src/core/streams/RunLengthStream.ts +0 -55
- package/src/core/streams/Stream.ts +0 -126
- package/src/core/streams/decode.ts +0 -70
- package/src/core/structures/PDFCatalog.ts +0 -81
- package/src/core/structures/PDFContentStream.ts +0 -58
- package/src/core/structures/PDFCrossRefStream.ts +0 -238
- package/src/core/structures/PDFFlateStream.ts +0 -40
- package/src/core/structures/PDFObjectStream.ts +0 -91
- package/src/core/structures/PDFPageLeaf.ts +0 -244
- package/src/core/structures/PDFPageTree.ts +0 -192
- package/src/core/syntax/CharCodes.ts +0 -62
- package/src/core/syntax/Delimiters.ts +0 -14
- package/src/core/syntax/Irregular.ts +0 -10
- package/src/core/syntax/Keywords.ts +0 -57
- package/src/core/syntax/Numeric.ts +0 -26
- package/src/core/syntax/Whitespace.ts +0 -10
- package/src/core/writers/PDFStreamWriter.ts +0 -114
- package/src/core/writers/PDFWriter.ts +0 -146
- package/src/types/fontkit.ts +0 -643
- package/src/utils/Cache.ts +0 -26
- package/src/utils/arrays.ts +0 -153
- package/src/utils/async.ts +0 -8
- package/src/utils/base64.ts +0 -98
- package/src/utils/elements/Arc.ts +0 -97
- package/src/utils/elements/Circle.ts +0 -47
- package/src/utils/elements/Ellipse.ts +0 -117
- package/src/utils/elements/GraphElement.ts +0 -14
- package/src/utils/elements/Line.ts +0 -83
- package/src/utils/elements/Plot.ts +0 -50
- package/src/utils/elements/Point.ts +0 -37
- package/src/utils/elements/Rectangle.ts +0 -65
- package/src/utils/elements/Segment.ts +0 -81
- package/src/utils/errors.ts +0 -3
- package/src/utils/intersections.ts +0 -237
- package/src/utils/maths.ts +0 -96
- package/src/utils/numbers.ts +0 -55
- package/src/utils/objects.ts +0 -13
- package/src/utils/pdfDocEncoding.ts +0 -69
- package/src/utils/png.ts +0 -100
- package/src/utils/rng.ts +0 -21
- package/src/utils/strings.ts +0 -191
- package/src/utils/validators.ts +0 -192
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -15
- package/vite.config.mts +0 -39
- /package/{src/api/form/index.ts → dist/api/form/index.d.ts} +0 -0
- /package/{src/api/image/index.ts → dist/api/image/index.d.ts} +0 -0
- /package/{src/api/index.ts → dist/api/index.d.ts} +0 -0
- /package/{src/api/text/index.ts → dist/api/text/index.d.ts} +0 -0
- /package/{src/core/acroform/index.ts → dist/core/acroform/index.d.ts} +0 -0
- /package/{src/core/annotation/index.ts → dist/core/annotation/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/utils/elements/index.ts → dist/utils/elements/index.d.ts} +0 -0
- /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import {
|
|
3
|
-
PDFDocument,
|
|
4
|
-
TextAlignment,
|
|
5
|
-
AnnotationFlags,
|
|
6
|
-
} from '../../../src/index';
|
|
7
|
-
|
|
8
|
-
const fancyFieldsPdfBytes = fs.readFileSync('assets/pdfs/fancy_fields.pdf');
|
|
9
|
-
|
|
10
|
-
describe(`PDFTextField`, () => {
|
|
11
|
-
it(`can read its value`, async () => {
|
|
12
|
-
const pdfDoc = await PDFDocument.load(fancyFieldsPdfBytes);
|
|
13
|
-
|
|
14
|
-
const form = pdfDoc.getForm();
|
|
15
|
-
|
|
16
|
-
const prefix = form.getTextField('Prefix ⚽️');
|
|
17
|
-
const firstName = form.getTextField('First Name 🚀');
|
|
18
|
-
const middleInitial = form.getTextField('MiddleInitial 🎳');
|
|
19
|
-
const lastName = form.getTextField('LastName 🛩');
|
|
20
|
-
|
|
21
|
-
expect(prefix.getText()).toEqual('Ms.');
|
|
22
|
-
expect(firstName.getText()).toEqual('Cedar');
|
|
23
|
-
expect(middleInitial.getText()).toEqual('M');
|
|
24
|
-
expect(lastName.getText()).toEqual('Lightningtwirls');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it(`can read its alignment`, async () => {
|
|
28
|
-
const pdfDoc = await PDFDocument.load(fancyFieldsPdfBytes);
|
|
29
|
-
|
|
30
|
-
const form = pdfDoc.getForm();
|
|
31
|
-
|
|
32
|
-
const prefix = form.getTextField('Prefix ⚽️');
|
|
33
|
-
const firstName = form.getTextField('First Name 🚀');
|
|
34
|
-
const middleInitial = form.getTextField('MiddleInitial 🎳');
|
|
35
|
-
const lastName = form.getTextField('LastName 🛩');
|
|
36
|
-
|
|
37
|
-
expect(prefix.getAlignment()).toEqual(TextAlignment.Center);
|
|
38
|
-
expect(firstName.getAlignment()).toEqual(TextAlignment.Left);
|
|
39
|
-
expect(middleInitial.getAlignment()).toEqual(TextAlignment.Center);
|
|
40
|
-
expect(lastName.getAlignment()).toEqual(TextAlignment.Right);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it(`can write a value`, async () => {
|
|
44
|
-
const pdfDoc = await PDFDocument.load(fancyFieldsPdfBytes);
|
|
45
|
-
|
|
46
|
-
const form = pdfDoc.getForm();
|
|
47
|
-
|
|
48
|
-
const prefix = form.getTextField('Prefix ⚽️');
|
|
49
|
-
const firstName = form.getTextField('First Name 🚀');
|
|
50
|
-
const middleInitial = form.getTextField('MiddleInitial 🎳');
|
|
51
|
-
const lastName = form.getTextField('LastName 🛩');
|
|
52
|
-
|
|
53
|
-
prefix.setText('Some boats 🚤');
|
|
54
|
-
firstName.setText('Chili peppers 🌶');
|
|
55
|
-
middleInitial.setText('Pineapplez 🍍');
|
|
56
|
-
lastName.setText('And christmas trees! 🎄');
|
|
57
|
-
|
|
58
|
-
expect(prefix.getText()).toEqual('Some boats 🚤');
|
|
59
|
-
expect(firstName.getText()).toEqual('Chili peppers 🌶');
|
|
60
|
-
expect(middleInitial.getText()).toEqual('Pineapplez 🍍');
|
|
61
|
-
expect(lastName.getText()).toEqual('And christmas trees! 🎄');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it(`can read its flag states`, async () => {
|
|
65
|
-
const pdfDoc = await PDFDocument.load(fancyFieldsPdfBytes);
|
|
66
|
-
const form = pdfDoc.getForm();
|
|
67
|
-
const prefix = form.getTextField('Prefix ⚽️');
|
|
68
|
-
|
|
69
|
-
expect(prefix.isExported()).toBe(true);
|
|
70
|
-
expect(prefix.isReadOnly()).toBe(false);
|
|
71
|
-
expect(prefix.isRequired()).toBe(false);
|
|
72
|
-
expect(prefix.isFileSelector()).toBe(false);
|
|
73
|
-
expect(prefix.isMultiline()).toBe(false);
|
|
74
|
-
expect(prefix.isPassword()).toBe(false);
|
|
75
|
-
expect(prefix.isRichFormatted()).toBe(false);
|
|
76
|
-
expect(prefix.isScrollable()).toBe(true);
|
|
77
|
-
expect(prefix.isSpellChecked()).toBe(true);
|
|
78
|
-
expect(prefix.isCombed()).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it(`throws an error when setting text that exceeds the max length`, async () => {
|
|
82
|
-
const pdfDoc = await PDFDocument.create();
|
|
83
|
-
const form = pdfDoc.getForm();
|
|
84
|
-
const textField = form.createTextField('foo.bar');
|
|
85
|
-
|
|
86
|
-
textField.setMaxLength(5);
|
|
87
|
-
expect(() => textField.setText('abcde')).not.toThrow();
|
|
88
|
-
expect(() => textField.setText('abcdef')).toThrow();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it(`throws an error when setting a max length less than the text length`, async () => {
|
|
92
|
-
const pdfDoc = await PDFDocument.create();
|
|
93
|
-
const form = pdfDoc.getForm();
|
|
94
|
-
const textField = form.createTextField('foo.bar');
|
|
95
|
-
|
|
96
|
-
textField.setText('abcdef');
|
|
97
|
-
expect(() => textField.setMaxLength(undefined)).not.toThrow();
|
|
98
|
-
expect(() => textField.setMaxLength(6)).not.toThrow();
|
|
99
|
-
expect(() => textField.setMaxLength(7)).not.toThrow();
|
|
100
|
-
expect(() => textField.setMaxLength(5)).toThrow();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it(`produces printable widgets when added to a page`, async () => {
|
|
104
|
-
const pdfDoc = await PDFDocument.create();
|
|
105
|
-
const page = pdfDoc.addPage();
|
|
106
|
-
|
|
107
|
-
const form = pdfDoc.getForm();
|
|
108
|
-
|
|
109
|
-
const textField = form.createTextField('a.new.text.field');
|
|
110
|
-
|
|
111
|
-
const widgets = () => textField.acroField.getWidgets();
|
|
112
|
-
expect(widgets().length).toBe(0);
|
|
113
|
-
|
|
114
|
-
textField.addToPage(page);
|
|
115
|
-
expect(widgets().length).toBe(1);
|
|
116
|
-
expect(widgets()[0].hasFlag(AnnotationFlags.Print)).toBe(true);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it(`sets page reference when added to a page`, async () => {
|
|
120
|
-
const pdfDoc = await PDFDocument.create();
|
|
121
|
-
const page = pdfDoc.addPage();
|
|
122
|
-
|
|
123
|
-
const form = pdfDoc.getForm();
|
|
124
|
-
|
|
125
|
-
const textField = form.createTextField('a.new.text.field');
|
|
126
|
-
|
|
127
|
-
const widgets = () => textField.acroField.getWidgets();
|
|
128
|
-
expect(widgets().length).toBe(0);
|
|
129
|
-
|
|
130
|
-
textField.addToPage(page);
|
|
131
|
-
expect(widgets().length).toBe(1);
|
|
132
|
-
expect(widgets()[0].P()).toBe(page.ref);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it(`sets the 'hidden' flag when passed options.hidden`, async () => {
|
|
136
|
-
const pdfDoc = await PDFDocument.create();
|
|
137
|
-
const page = pdfDoc.addPage();
|
|
138
|
-
const form = pdfDoc.getForm();
|
|
139
|
-
|
|
140
|
-
const textField = form.createTextField('a.hidden.text.field');
|
|
141
|
-
const widgets = () => textField.acroField.getWidgets();
|
|
142
|
-
|
|
143
|
-
textField.addToPage(page, { hidden: true });
|
|
144
|
-
|
|
145
|
-
expect(widgets().length).toBe(1);
|
|
146
|
-
expect(widgets()[0].hasFlag(AnnotationFlags.Hidden)).toBe(true);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { svgPathToOperators } from '../../src/api/svgPath';
|
|
2
|
-
|
|
3
|
-
// Test paths adapted from https://svgwg.org/svg2-draft/paths.html
|
|
4
|
-
describe(`svgPathToOperators`, () => {
|
|
5
|
-
it(`can map triangle paths to PDF operators`, () => {
|
|
6
|
-
const operators = svgPathToOperators('M 100 100 L 300 100 L 200 300 z');
|
|
7
|
-
expect(operators.length).toBe(4);
|
|
8
|
-
expect(operators.toString()).toBe('100 100 m,300 100 l,200 300 l,h');
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it(`can map relative triangle paths to PDF operators`, () => {
|
|
12
|
-
const operators = svgPathToOperators('m 100 100 l 200 0 l -100 200 z');
|
|
13
|
-
expect(operators.length).toBe(4);
|
|
14
|
-
expect(operators.toString()).toBe('100 100 m,300 100 l,200 300 l,h');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it(`can map triangle decimal paths to PDF operators`, () => {
|
|
18
|
-
const operators = svgPathToOperators('M 50.5 100 L 250.5 100 150.5 300 z');
|
|
19
|
-
expect(operators.length).toBe(4);
|
|
20
|
-
expect(operators.toString()).toBe('50.5 100 m,250.5 100 l,150.5 300 l,h');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it(`can map rectangle with lines paths to PDF operators`, () => {
|
|
24
|
-
const operators = svgPathToOperators('M 50 50 V 100 H 100 v -100 h -50 Z');
|
|
25
|
-
expect(operators.length).toBe(6);
|
|
26
|
-
expect(operators.toString()).toBe(
|
|
27
|
-
'50 50 m,50 100 l,100 100 l,100 0 l,50 0 l,h',
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it(`can map bezier curve paths to PDF operators`, () => {
|
|
32
|
-
const operators = svgPathToOperators(
|
|
33
|
-
'M100,200 C100,100 250,100 250,200 S400,300 400,200',
|
|
34
|
-
);
|
|
35
|
-
expect(operators.length).toBe(3);
|
|
36
|
-
expect(operators.toString()).toBe(
|
|
37
|
-
'100 200 m,100 100 250 100 250 200 c,250 300 400 300 400 200 c',
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it(`can map relative bezier curve paths to PDF operators`, () => {
|
|
42
|
-
const operators = svgPathToOperators(
|
|
43
|
-
'M100,200 c0,-100 150,-100 150,0 s150,100 150,0',
|
|
44
|
-
);
|
|
45
|
-
expect(operators.length).toBe(3);
|
|
46
|
-
expect(operators.toString()).toBe(
|
|
47
|
-
'100 200 m,100 100 250 100 250 200 c,250 300 400 300 400 200 c',
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it(`can map quadratic curve paths to PDF operators`, () => {
|
|
52
|
-
const operators = svgPathToOperators('M200,300 Q400,50 600,300 T1000,300');
|
|
53
|
-
expect(operators.length).toBe(3);
|
|
54
|
-
expect(operators.toString()).toBe(
|
|
55
|
-
'200 300 m,400 50 600 300 v,800 550 1000 300 v',
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it(`can map relative quadratic curve paths to PDF operators`, () => {
|
|
60
|
-
const operators = svgPathToOperators('M200,300 q200,-250 400,0 t400,0');
|
|
61
|
-
expect(operators.length).toBe(3);
|
|
62
|
-
expect(operators.toString()).toBe(
|
|
63
|
-
'200 300 m,400 50 600 300 v,800 550 1000 300 v',
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it(`can map arc paths to PDF operators`, () => {
|
|
68
|
-
const operators = svgPathToOperators(
|
|
69
|
-
'M300,200 h-150 a150,150 0 1,0 150,-150 z',
|
|
70
|
-
);
|
|
71
|
-
expect(operators.length).toBe(6);
|
|
72
|
-
expect(operators.toString()).toBe(
|
|
73
|
-
'300 200 m,150 200 l,150 282.8427124746191 217.15728752538098 350 300 350 c,382.84271247461896 350 450 282.842712474619 450 200.00000000000003 c,450 117.15728752538101 382.84271247461896 50.00000000000003 300 50.00000000000002 c,h',
|
|
74
|
-
);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it(`can map relative arc paths to PDF operators`, () => {
|
|
78
|
-
const operators = svgPathToOperators(
|
|
79
|
-
'M300,200 h-150 A150,150 0 1,0 300,50 z',
|
|
80
|
-
);
|
|
81
|
-
expect(operators.length).toBe(6);
|
|
82
|
-
expect(operators.toString()).toBe(
|
|
83
|
-
'300 200 m,150 200 l,150 282.8427124746191 217.15728752538098 350 300 350 c,382.84271247461896 350 450 282.842712474619 450 200.00000000000003 c,450 117.15728752538101 382.84271247461896 50.00000000000003 300 50.00000000000002 c,h',
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it(`can map cubic bezier paths to PDF operators`, () => {
|
|
88
|
-
const operators = svgPathToOperators(
|
|
89
|
-
'm 100 100 S 200,100 200,200 200,200 100,200 T 0,250',
|
|
90
|
-
);
|
|
91
|
-
expect(operators.length).toBe(4);
|
|
92
|
-
expect(operators.toString()).toBe(
|
|
93
|
-
'100 100 m,100 100 200 100 200 200 c,200 300 200 200 100 200 c,0 200 0 250 v',
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it(`can map dashed line paths to PDF operators`, () => {
|
|
98
|
-
const operators = svgPathToOperators(
|
|
99
|
-
'M 0,25 5,25 M 10,25 15,25 M 20,25 25,25',
|
|
100
|
-
);
|
|
101
|
-
expect(operators.length).toBe(6);
|
|
102
|
-
expect(operators.toString()).toBe(
|
|
103
|
-
'0 25 m,5 25 l,10 25 m,15 25 l,20 25 m,25 25 l',
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it(`can map relative dashed line paths to PDF operators`, () => {
|
|
108
|
-
const operators = svgPathToOperators('m 0,25 5,0 m 5,0 5,0 m 5,0 5,0');
|
|
109
|
-
expect(operators.length).toBe(6);
|
|
110
|
-
expect(operators.toString()).toBe(
|
|
111
|
-
'0 25 m,5 25 l,10 25 m,15 25 l,20 25 m,25 25 l',
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it(`can map paths with odd inputs to PDF operators`, () => {
|
|
116
|
-
const operators = svgPathToOperators('M 0,25 5,25 m 5-0 5..0 m 5,0 5,0');
|
|
117
|
-
expect(operators.length).toBe(6);
|
|
118
|
-
expect(operators.toString()).toBe(
|
|
119
|
-
'0 25 m,5 25 l,10 25 m,15 25 l,20 25 m,25 25 l',
|
|
120
|
-
);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it(`can map paths that reset cubic bezier control points to PDF operators`, () => {
|
|
124
|
-
const operators = svgPathToOperators(
|
|
125
|
-
'M100 100 S200,100 200,200 M95 105 s100,0 100,100',
|
|
126
|
-
);
|
|
127
|
-
expect(operators.length).toBe(4);
|
|
128
|
-
expect(operators.toString()).toBe(
|
|
129
|
-
'100 100 m,100 100 200 100 200 200 c,95 105 m,95 105 195 105 195 205 c',
|
|
130
|
-
);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it(`can map paths that reset quadratic bezier control points to PDF operators`, () => {
|
|
134
|
-
const operators = svgPathToOperators(
|
|
135
|
-
'M100 100 T100,200 200,200 M90,120 t0,100 100,0',
|
|
136
|
-
);
|
|
137
|
-
expect(operators.length).toBe(6);
|
|
138
|
-
expect(operators.toString()).toBe(
|
|
139
|
-
'100 100 m,100 100 100 200 v,100 300 200 200 v,90 120 m,90 120 90 220 v,90 320 190 220 v',
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it(`correctly updates control points for T command`, () => {
|
|
144
|
-
// See https://github.com/Hopding/pdf-lib/issues/1443
|
|
145
|
-
const operators = svgPathToOperators(
|
|
146
|
-
'M 10,25 Q 30,0 50,25 Q 70,50 90,25 T 130,25 T 170,25',
|
|
147
|
-
);
|
|
148
|
-
expect(operators.length).toBe(5);
|
|
149
|
-
expect(operators.toString()).toBe(
|
|
150
|
-
'10 25 m,30 0 50 25 v,70 50 90 25 v,110 0 130 25 v,150 50 170 25 v'
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { PDFDocument, StandardFonts, TextAlignment } from '../../../src/index';
|
|
2
|
-
|
|
3
|
-
import { layoutMultilineText } from '../../../src/api/text/layout';
|
|
4
|
-
|
|
5
|
-
const MIN_FONT_SIZE = 4;
|
|
6
|
-
const MAX_FONT_SIZE = 500;
|
|
7
|
-
|
|
8
|
-
describe(`layoutMultilineText`, () => {
|
|
9
|
-
it('should layout the text on one line when it fits near-perfectly', async () => {
|
|
10
|
-
const pdfDoc = await PDFDocument.create();
|
|
11
|
-
const font = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
|
12
|
-
const alignment = TextAlignment.Left;
|
|
13
|
-
const padding = 0;
|
|
14
|
-
const borderWidth = 0;
|
|
15
|
-
const text = 'Super Mario Bros.';
|
|
16
|
-
|
|
17
|
-
for (let fontSize = MIN_FONT_SIZE; fontSize <= MAX_FONT_SIZE; fontSize++) {
|
|
18
|
-
const height = font.heightAtSize(fontSize) - (borderWidth + padding) * 2;
|
|
19
|
-
|
|
20
|
-
const width =
|
|
21
|
-
font.widthOfTextAtSize(text, fontSize) - (borderWidth + padding) * 2;
|
|
22
|
-
|
|
23
|
-
const bounds = {
|
|
24
|
-
x: borderWidth + padding,
|
|
25
|
-
y: borderWidth + padding,
|
|
26
|
-
width,
|
|
27
|
-
height,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const multilineTextLayout = layoutMultilineText(text, {
|
|
31
|
-
alignment,
|
|
32
|
-
bounds,
|
|
33
|
-
font,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
expect(multilineTextLayout.lines.length).toStrictEqual(1);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should layout the text on one line when it fits comfortably', async () => {
|
|
41
|
-
const pdfDoc = await PDFDocument.create();
|
|
42
|
-
const font = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
|
43
|
-
const alignment = TextAlignment.Left;
|
|
44
|
-
const padding = 0;
|
|
45
|
-
const borderWidth = 0;
|
|
46
|
-
const text = 'Super Mario Bros.';
|
|
47
|
-
const fontSize = 12;
|
|
48
|
-
const height = font.heightAtSize(fontSize) - (borderWidth + padding) * 2;
|
|
49
|
-
|
|
50
|
-
// Bounds width twice that of the text
|
|
51
|
-
const width =
|
|
52
|
-
(font.widthOfTextAtSize(text, fontSize) - (borderWidth + padding) * 2) *
|
|
53
|
-
2;
|
|
54
|
-
|
|
55
|
-
const bounds = {
|
|
56
|
-
x: borderWidth + padding,
|
|
57
|
-
y: borderWidth + padding,
|
|
58
|
-
width,
|
|
59
|
-
height,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const multilineTextLayout = layoutMultilineText(text, {
|
|
63
|
-
alignment,
|
|
64
|
-
bounds,
|
|
65
|
-
font,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(multilineTextLayout.lines.length).toStrictEqual(1);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should layout the text on multiple lines when it does not fit horizontally but there is space vertically', async () => {
|
|
72
|
-
const pdfDoc = await PDFDocument.create();
|
|
73
|
-
const font = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
|
74
|
-
const alignment = TextAlignment.Left;
|
|
75
|
-
const padding = 0;
|
|
76
|
-
const borderWidth = 0;
|
|
77
|
-
const text = 'Super Mario Bros.';
|
|
78
|
-
|
|
79
|
-
for (let fontSize = MIN_FONT_SIZE; fontSize <= MAX_FONT_SIZE; fontSize++) {
|
|
80
|
-
// Height twice that of the text
|
|
81
|
-
const height =
|
|
82
|
-
(font.heightAtSize(fontSize) - (borderWidth + padding) * 2) * 2;
|
|
83
|
-
|
|
84
|
-
// Width half that of the text
|
|
85
|
-
const width =
|
|
86
|
-
(font.widthOfTextAtSize(text, fontSize) - (borderWidth + padding) * 2) /
|
|
87
|
-
2;
|
|
88
|
-
|
|
89
|
-
const bounds = {
|
|
90
|
-
x: borderWidth + padding,
|
|
91
|
-
y: borderWidth + padding,
|
|
92
|
-
width,
|
|
93
|
-
height,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const multilineTextLayout = layoutMultilineText(text, {
|
|
97
|
-
alignment,
|
|
98
|
-
bounds,
|
|
99
|
-
font,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
expect(multilineTextLayout.lines.length).toStrictEqual(2);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should never exceed the maximum font size', async () => {
|
|
107
|
-
const pdfDoc = await PDFDocument.create();
|
|
108
|
-
const font = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
|
109
|
-
const alignment = TextAlignment.Left;
|
|
110
|
-
const padding = 0;
|
|
111
|
-
const borderWidth = 0;
|
|
112
|
-
const text = 'Super Mario Bros.';
|
|
113
|
-
|
|
114
|
-
const height = Number.MAX_VALUE;
|
|
115
|
-
const width = Number.MAX_VALUE;
|
|
116
|
-
|
|
117
|
-
const bounds = {
|
|
118
|
-
x: borderWidth + padding,
|
|
119
|
-
y: borderWidth + padding,
|
|
120
|
-
width,
|
|
121
|
-
height,
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const multilineTextLayout = layoutMultilineText(text, {
|
|
125
|
-
alignment,
|
|
126
|
-
bounds,
|
|
127
|
-
font,
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
expect(multilineTextLayout.lines.length).toStrictEqual(1);
|
|
131
|
-
expect(multilineTextLayout.fontSize).toStrictEqual(MAX_FONT_SIZE);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should respect empty lines', async () => {
|
|
135
|
-
const pdfDoc = await PDFDocument.create();
|
|
136
|
-
const font = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
|
137
|
-
const alignment = TextAlignment.Left;
|
|
138
|
-
const padding = 0;
|
|
139
|
-
const borderWidth = 0;
|
|
140
|
-
const lines = ['Super Mario Bros.', '', 'Boop'];
|
|
141
|
-
const text = lines.join('\n');
|
|
142
|
-
|
|
143
|
-
for (let fontSize = MIN_FONT_SIZE; fontSize <= MAX_FONT_SIZE; fontSize++) {
|
|
144
|
-
const height = font.heightAtSize(fontSize) - (borderWidth + padding) * 2;
|
|
145
|
-
|
|
146
|
-
const width =
|
|
147
|
-
font.widthOfTextAtSize(lines[0], fontSize) -
|
|
148
|
-
(borderWidth + padding) * 2;
|
|
149
|
-
|
|
150
|
-
const bounds = {
|
|
151
|
-
x: borderWidth + padding,
|
|
152
|
-
y: borderWidth + padding,
|
|
153
|
-
width,
|
|
154
|
-
height,
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const multilineTextLayout = layoutMultilineText(text, {
|
|
158
|
-
alignment,
|
|
159
|
-
bounds,
|
|
160
|
-
font,
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
expect(multilineTextLayout.lines.length).toStrictEqual(3);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
});
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import pako from 'pako';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
PDFArray,
|
|
5
|
-
PDFBool,
|
|
6
|
-
PDFContentStream,
|
|
7
|
-
PDFContext,
|
|
8
|
-
PDFDict,
|
|
9
|
-
PDFHexString,
|
|
10
|
-
PDFName,
|
|
11
|
-
PDFNull,
|
|
12
|
-
PDFNumber,
|
|
13
|
-
PDFRef,
|
|
14
|
-
PDFString,
|
|
15
|
-
} from '../../src/core';
|
|
16
|
-
import { mergeIntoTypedArray } from '../../src/utils';
|
|
17
|
-
|
|
18
|
-
describe(`PDFContext`, () => {
|
|
19
|
-
it(`retains assigned objects`, () => {
|
|
20
|
-
const context = PDFContext.create();
|
|
21
|
-
|
|
22
|
-
const pdfBool = PDFBool.True;
|
|
23
|
-
const pdfHexString = PDFHexString.of('ABC123');
|
|
24
|
-
const pdfName = PDFName.of('Foo#Bar!');
|
|
25
|
-
const pdfNull = PDFNull;
|
|
26
|
-
const pdfNumber = PDFNumber.of(-24.179);
|
|
27
|
-
const pdfString = PDFString.of('foobar');
|
|
28
|
-
const pdfDict = context.obj({ Foo: PDFName.of('Bar') });
|
|
29
|
-
const pdfArray = context.obj([PDFBool.True, pdfDict]);
|
|
30
|
-
|
|
31
|
-
context.assign(PDFRef.of(0), pdfBool);
|
|
32
|
-
context.assign(PDFRef.of(1), pdfHexString);
|
|
33
|
-
context.assign(PDFRef.of(2), pdfName);
|
|
34
|
-
context.assign(PDFRef.of(3), pdfNull);
|
|
35
|
-
context.assign(PDFRef.of(4), pdfNumber);
|
|
36
|
-
context.assign(PDFRef.of(5), pdfString);
|
|
37
|
-
context.assign(PDFRef.of(6), pdfDict);
|
|
38
|
-
context.assign(PDFRef.of(7), pdfArray);
|
|
39
|
-
|
|
40
|
-
expect(context.lookup(PDFRef.of(0))).toBe(pdfBool);
|
|
41
|
-
expect(context.lookup(PDFRef.of(1))).toBe(pdfHexString);
|
|
42
|
-
expect(context.lookup(PDFRef.of(2))).toBe(pdfName);
|
|
43
|
-
expect(context.lookup(PDFRef.of(3))).toBe(pdfNull);
|
|
44
|
-
expect(context.lookup(PDFRef.of(4))).toBe(pdfNumber);
|
|
45
|
-
expect(context.lookup(PDFRef.of(5))).toBe(pdfString);
|
|
46
|
-
expect(context.lookup(PDFRef.of(6))).toBe(pdfDict);
|
|
47
|
-
expect(context.lookup(PDFRef.of(7))).toBe(pdfArray);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it(`does not use object number 0 during registration`, () => {
|
|
51
|
-
const context = PDFContext.create();
|
|
52
|
-
expect(context.register(PDFBool.True)).toBe(PDFRef.of(1));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it(`returns the given object during lookup if it is not a PDFRef`, () => {
|
|
56
|
-
const context = PDFContext.create();
|
|
57
|
-
const pdfNumber = PDFNumber.of(21);
|
|
58
|
-
expect(context.lookup(pdfNumber)).toBe(pdfNumber);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it(`assigns the next highest object number during registration`, () => {
|
|
62
|
-
const context = PDFContext.create();
|
|
63
|
-
|
|
64
|
-
const pdfBool = PDFBool.True;
|
|
65
|
-
const pdfName = PDFName.of('FooBar');
|
|
66
|
-
const pdfNumber = PDFNumber.of(-21.436);
|
|
67
|
-
|
|
68
|
-
const boolRef = context.register(pdfBool);
|
|
69
|
-
expect(boolRef).toBe(PDFRef.of(1));
|
|
70
|
-
expect(context.lookup(boolRef)).toBe(pdfBool);
|
|
71
|
-
|
|
72
|
-
context.assign(PDFRef.of(9000), pdfName);
|
|
73
|
-
|
|
74
|
-
const numberRef = context.register(pdfNumber);
|
|
75
|
-
expect(numberRef).toBe(PDFRef.of(9001));
|
|
76
|
-
expect(context.lookup(numberRef)).toBe(pdfNumber);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it(`stream creation`, () => {
|
|
80
|
-
const context = PDFContext.create();
|
|
81
|
-
|
|
82
|
-
const stream = context.flateStream('stuff and things!');
|
|
83
|
-
const buffer = new Uint8Array(stream.sizeInBytes());
|
|
84
|
-
stream.copyBytesInto(buffer, 0);
|
|
85
|
-
|
|
86
|
-
expect(buffer).toEqual(
|
|
87
|
-
mergeIntoTypedArray(
|
|
88
|
-
'<<\n',
|
|
89
|
-
'/Filter /FlateDecode\n',
|
|
90
|
-
'/Length 25\n',
|
|
91
|
-
'>>\n',
|
|
92
|
-
'stream\n',
|
|
93
|
-
pako.deflate('stuff and things!'),
|
|
94
|
-
'\nendstream',
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe(`literal conversions`, () => {
|
|
100
|
-
const context = PDFContext.create();
|
|
101
|
-
|
|
102
|
-
it(`converts null literals to the PDFNull instance`, () => {
|
|
103
|
-
expect(context.obj(null)).toBe(PDFNull);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it(`converts string literals to PDFName instances`, () => {
|
|
107
|
-
expect(context.obj('foobar')).toBeInstanceOf(PDFName);
|
|
108
|
-
expect(context.obj('foobar').toString()).toBe('/foobar');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it(`converts number literals to PDFNumber instances`, () => {
|
|
112
|
-
expect(context.obj(-21.4e-3)).toBeInstanceOf(PDFNumber);
|
|
113
|
-
expect(context.obj(-21.4e-3).toString()).toBe('-0.0214');
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it(`converts boolean literals to PDFBool instances`, () => {
|
|
117
|
-
expect(context.obj(true)).toBe(PDFBool.True);
|
|
118
|
-
expect(context.obj(false)).toBe(PDFBool.False);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it(`converts array literals to PDFArray instances`, () => {
|
|
122
|
-
const array = [
|
|
123
|
-
PDFRef.of(21),
|
|
124
|
-
true,
|
|
125
|
-
PDFHexString.of('ABC123'),
|
|
126
|
-
'Foo#Bar!',
|
|
127
|
-
[null, -24.179],
|
|
128
|
-
{ Foo: PDFName.of('Bar') },
|
|
129
|
-
];
|
|
130
|
-
expect(context.obj(array)).toBeInstanceOf(PDFArray);
|
|
131
|
-
expect(context.obj(array).toString()).toEqual(
|
|
132
|
-
'[ 21 0 R true <ABC123> /Foo#23Bar! [ null -24.179 ] <<\n/Foo /Bar\n>> ]',
|
|
133
|
-
);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it(`converts object literals to PDFDict instances`, () => {
|
|
137
|
-
const dict = {
|
|
138
|
-
Ref: PDFRef.of(21),
|
|
139
|
-
Boolean: true,
|
|
140
|
-
HexString: PDFHexString.of('ABC123'),
|
|
141
|
-
Null: null,
|
|
142
|
-
Number: -24.179,
|
|
143
|
-
Name: 'Foo#Bar!',
|
|
144
|
-
Dictionary: { Array: [true, null] },
|
|
145
|
-
};
|
|
146
|
-
expect(context.obj(dict)).toBeInstanceOf(PDFDict);
|
|
147
|
-
expect(context.obj(dict).toString()).toEqual(
|
|
148
|
-
`<<
|
|
149
|
-
/Ref 21 0 R
|
|
150
|
-
/Boolean true
|
|
151
|
-
/HexString <ABC123>
|
|
152
|
-
/Null null
|
|
153
|
-
/Number -24.179
|
|
154
|
-
/Name /Foo#23Bar!
|
|
155
|
-
/Dictionary <<
|
|
156
|
-
/Array [ true null ]
|
|
157
|
-
>>
|
|
158
|
-
>>`,
|
|
159
|
-
);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it(`can provide a reference to a "pushGraphicsState" content stream`, () => {
|
|
164
|
-
const context = PDFContext.create();
|
|
165
|
-
expect(context.enumerateIndirectObjects().length).toBe(0);
|
|
166
|
-
|
|
167
|
-
const ref1 = context.getPushGraphicsStateContentStream();
|
|
168
|
-
expect(ref1).toBeInstanceOf(PDFRef);
|
|
169
|
-
expect(context.enumerateIndirectObjects().length).toBe(1);
|
|
170
|
-
|
|
171
|
-
const ref2 = context.getPushGraphicsStateContentStream();
|
|
172
|
-
expect(ref2).toBeInstanceOf(PDFRef);
|
|
173
|
-
expect(context.enumerateIndirectObjects().length).toBe(1);
|
|
174
|
-
|
|
175
|
-
expect(ref1).toBe(ref2);
|
|
176
|
-
expect(context.lookup(ref1)).toBeInstanceOf(PDFContentStream);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it(`can provide a reference to a "popGraphicsState" content stream`, () => {
|
|
180
|
-
const context = PDFContext.create();
|
|
181
|
-
expect(context.enumerateIndirectObjects().length).toBe(0);
|
|
182
|
-
|
|
183
|
-
const ref1 = context.getPopGraphicsStateContentStream();
|
|
184
|
-
expect(ref1).toBeInstanceOf(PDFRef);
|
|
185
|
-
expect(context.enumerateIndirectObjects().length).toBe(1);
|
|
186
|
-
|
|
187
|
-
const ref2 = context.getPopGraphicsStateContentStream();
|
|
188
|
-
expect(ref2).toBeInstanceOf(PDFRef);
|
|
189
|
-
expect(context.enumerateIndirectObjects().length).toBe(1);
|
|
190
|
-
|
|
191
|
-
expect(ref1).toBe(ref2);
|
|
192
|
-
expect(context.lookup(ref1)).toBeInstanceOf(PDFContentStream);
|
|
193
|
-
});
|
|
194
|
-
});
|