@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,77 +0,0 @@
|
|
|
1
|
-
import PDFString from '../objects/PDFString';
|
|
2
|
-
import PDFHexString from '../objects/PDFHexString';
|
|
3
|
-
import PDFContext from '../PDFContext';
|
|
4
|
-
import PDFRef from '../objects/PDFRef';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* From the PDF-A3 specification, section **3.1. Requirements - General**.
|
|
8
|
-
* See:
|
|
9
|
-
* * https://www.pdfa.org/wp-content/uploads/2018/10/PDF20_AN002-AF.pdf
|
|
10
|
-
*/
|
|
11
|
-
export enum AFRelationship {
|
|
12
|
-
Source = 'Source',
|
|
13
|
-
Data = 'Data',
|
|
14
|
-
Alternative = 'Alternative',
|
|
15
|
-
Supplement = 'Supplement',
|
|
16
|
-
EncryptedPayload = 'EncryptedPayload',
|
|
17
|
-
FormData = EncryptedPayload,
|
|
18
|
-
Schema = 'Schema',
|
|
19
|
-
Unspecified = 'Unspecified',
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface EmbeddedFileOptions {
|
|
23
|
-
mimeType?: string;
|
|
24
|
-
description?: string;
|
|
25
|
-
creationDate?: Date;
|
|
26
|
-
modificationDate?: Date;
|
|
27
|
-
afRelationship?: AFRelationship;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
class FileEmbedder {
|
|
31
|
-
static for(bytes: Uint8Array, fileName: string, options: EmbeddedFileOptions = {}) {
|
|
32
|
-
return new FileEmbedder(bytes, fileName, options);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private readonly fileData: Uint8Array;
|
|
36
|
-
readonly fileName: string;
|
|
37
|
-
readonly options: EmbeddedFileOptions;
|
|
38
|
-
|
|
39
|
-
private constructor(fileData: Uint8Array, fileName: string, options: EmbeddedFileOptions = {}) {
|
|
40
|
-
this.fileData = fileData;
|
|
41
|
-
this.fileName = fileName;
|
|
42
|
-
this.options = options;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async embedIntoContext(context: PDFContext, ref?: PDFRef): Promise<PDFRef> {
|
|
46
|
-
const { mimeType, description, creationDate, modificationDate, afRelationship } = this.options;
|
|
47
|
-
|
|
48
|
-
const embeddedFileStream = context.flateStream(this.fileData, {
|
|
49
|
-
Type: 'EmbeddedFile',
|
|
50
|
-
Subtype: mimeType ?? undefined,
|
|
51
|
-
Params: {
|
|
52
|
-
Size: this.fileData.length,
|
|
53
|
-
CreationDate: creationDate ? PDFString.fromDate(creationDate) : undefined,
|
|
54
|
-
ModDate: modificationDate ? PDFString.fromDate(modificationDate) : undefined,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
const embeddedFileStreamRef = context.register(embeddedFileStream);
|
|
58
|
-
|
|
59
|
-
const fileSpecDict = context.obj({
|
|
60
|
-
Type: 'Filespec',
|
|
61
|
-
F: PDFString.of(this.fileName), // TODO: Assert that this is plain ASCII
|
|
62
|
-
UF: PDFHexString.fromText(this.fileName),
|
|
63
|
-
EF: { F: embeddedFileStreamRef },
|
|
64
|
-
Desc: description ? PDFHexString.fromText(description) : undefined,
|
|
65
|
-
AFRelationship: afRelationship ?? undefined,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (ref) {
|
|
69
|
-
context.assign(ref, fileSpecDict);
|
|
70
|
-
return ref;
|
|
71
|
-
} else {
|
|
72
|
-
return context.register(fileSpecDict);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export default FileEmbedder;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Font } from '../../types/fontkit';
|
|
2
|
-
|
|
3
|
-
export interface FontFlagOptions {
|
|
4
|
-
fixedPitch?: boolean;
|
|
5
|
-
serif?: boolean;
|
|
6
|
-
symbolic?: boolean;
|
|
7
|
-
script?: boolean;
|
|
8
|
-
nonsymbolic?: boolean;
|
|
9
|
-
italic?: boolean;
|
|
10
|
-
allCap?: boolean;
|
|
11
|
-
smallCap?: boolean;
|
|
12
|
-
forceBold?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// prettier-ignore
|
|
16
|
-
const makeFontFlags = (options: FontFlagOptions) => {
|
|
17
|
-
let flags = 0;
|
|
18
|
-
|
|
19
|
-
const flipBit = (bit: number) => { flags |= (1 << (bit - 1)); };
|
|
20
|
-
|
|
21
|
-
if (options.fixedPitch) flipBit(1);
|
|
22
|
-
if (options.serif) flipBit(2);
|
|
23
|
-
if (options.symbolic) flipBit(3);
|
|
24
|
-
if (options.script) flipBit(4);
|
|
25
|
-
if (options.nonsymbolic) flipBit(6);
|
|
26
|
-
if (options.italic) flipBit(7);
|
|
27
|
-
if (options.allCap) flipBit(17);
|
|
28
|
-
if (options.smallCap) flipBit(18);
|
|
29
|
-
if (options.forceBold) flipBit(19);
|
|
30
|
-
|
|
31
|
-
return flags;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// From: https://github.com/foliojs/pdfkit/blob/83f5f7243172a017adcf6a7faa5547c55982c57b/lib/font/embedded.js#L123-L129
|
|
35
|
-
export const deriveFontFlags = (font: Font): number => {
|
|
36
|
-
const familyClass = font['OS/2'] ? font['OS/2'].sFamilyClass : 0;
|
|
37
|
-
const flags = makeFontFlags({
|
|
38
|
-
fixedPitch: font.post.isFixedPitch,
|
|
39
|
-
serif: 1 <= familyClass && familyClass <= 7,
|
|
40
|
-
symbolic: true, // Assume the font uses non-latin characters
|
|
41
|
-
script: familyClass === 10,
|
|
42
|
-
italic: font.head.macStyle.italic,
|
|
43
|
-
});
|
|
44
|
-
return flags;
|
|
45
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import PDFHexString from '../objects/PDFHexString';
|
|
2
|
-
import PDFContext from '../PDFContext';
|
|
3
|
-
import PDFRef from '../objects/PDFRef';
|
|
4
|
-
|
|
5
|
-
class JavaScriptEmbedder {
|
|
6
|
-
static for(script: string, scriptName: string) {
|
|
7
|
-
return new JavaScriptEmbedder(script, scriptName);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
private readonly script: string;
|
|
11
|
-
readonly scriptName: string;
|
|
12
|
-
|
|
13
|
-
private constructor(script: string, scriptName: string) {
|
|
14
|
-
this.script = script;
|
|
15
|
-
this.scriptName = scriptName;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async embedIntoContext(context: PDFContext, ref?: PDFRef): Promise<PDFRef> {
|
|
19
|
-
const jsActionDict = context.obj({
|
|
20
|
-
Type: 'Action',
|
|
21
|
-
S: 'JavaScript',
|
|
22
|
-
JS: PDFHexString.fromText(this.script),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
if (ref) {
|
|
26
|
-
context.assign(ref, jsActionDict);
|
|
27
|
-
return ref;
|
|
28
|
-
} else {
|
|
29
|
-
return context.register(jsActionDict);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default JavaScriptEmbedder;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import PDFRef from '../objects/PDFRef';
|
|
2
|
-
import PDFContext from '../PDFContext';
|
|
3
|
-
|
|
4
|
-
// prettier-ignore
|
|
5
|
-
const MARKERS = [
|
|
6
|
-
0xffc0, 0xffc1, 0xffc2,
|
|
7
|
-
0xffc3, 0xffc5, 0xffc6,
|
|
8
|
-
0xffc7, 0xffc8, 0xffc9,
|
|
9
|
-
0xffca, 0xffcb, 0xffcc,
|
|
10
|
-
0xffcd, 0xffce, 0xffcf,
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
enum ColorSpace {
|
|
14
|
-
DeviceGray = 'DeviceGray',
|
|
15
|
-
DeviceRGB = 'DeviceRGB',
|
|
16
|
-
DeviceCMYK = 'DeviceCMYK',
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const ChannelToColorSpace: { [idx: number]: ColorSpace | undefined } = {
|
|
20
|
-
1: ColorSpace.DeviceGray,
|
|
21
|
-
3: ColorSpace.DeviceRGB,
|
|
22
|
-
4: ColorSpace.DeviceCMYK,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A note of thanks to the developers of https://github.com/foliojs/pdfkit, as
|
|
27
|
-
* this class borrows from:
|
|
28
|
-
* https://github.com/foliojs/pdfkit/blob/a6af76467ce06bd6a2af4aa7271ccac9ff152a7d/lib/image/jpeg.js
|
|
29
|
-
*/
|
|
30
|
-
class JpegEmbedder {
|
|
31
|
-
static async for(imageData: Uint8Array) {
|
|
32
|
-
const dataView = new DataView(imageData.buffer);
|
|
33
|
-
|
|
34
|
-
const soi = dataView.getUint16(0);
|
|
35
|
-
if (soi !== 0xffd8) throw new Error('SOI not found in JPEG');
|
|
36
|
-
|
|
37
|
-
let pos = 2;
|
|
38
|
-
let marker: number;
|
|
39
|
-
|
|
40
|
-
while (pos < dataView.byteLength) {
|
|
41
|
-
marker = dataView.getUint16(pos);
|
|
42
|
-
pos += 2;
|
|
43
|
-
if (MARKERS.includes(marker)) break;
|
|
44
|
-
pos += dataView.getUint16(pos);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (!MARKERS.includes(marker!)) throw new Error('Invalid JPEG');
|
|
48
|
-
pos += 2;
|
|
49
|
-
|
|
50
|
-
const bitsPerComponent = dataView.getUint8(pos++);
|
|
51
|
-
const height = dataView.getUint16(pos);
|
|
52
|
-
pos += 2;
|
|
53
|
-
|
|
54
|
-
const width = dataView.getUint16(pos);
|
|
55
|
-
pos += 2;
|
|
56
|
-
|
|
57
|
-
const channelByte = dataView.getUint8(pos++);
|
|
58
|
-
const channelName = ChannelToColorSpace[channelByte];
|
|
59
|
-
|
|
60
|
-
if (!channelName) throw new Error('Unknown JPEG channel.');
|
|
61
|
-
|
|
62
|
-
const colorSpace = channelName;
|
|
63
|
-
|
|
64
|
-
return new JpegEmbedder(imageData, bitsPerComponent, width, height, colorSpace);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
readonly bitsPerComponent: number;
|
|
68
|
-
readonly height: number;
|
|
69
|
-
readonly width: number;
|
|
70
|
-
readonly colorSpace: ColorSpace;
|
|
71
|
-
|
|
72
|
-
private readonly imageData: Uint8Array;
|
|
73
|
-
|
|
74
|
-
private constructor(
|
|
75
|
-
imageData: Uint8Array,
|
|
76
|
-
bitsPerComponent: number,
|
|
77
|
-
width: number,
|
|
78
|
-
height: number,
|
|
79
|
-
colorSpace: ColorSpace,
|
|
80
|
-
) {
|
|
81
|
-
this.imageData = imageData;
|
|
82
|
-
this.bitsPerComponent = bitsPerComponent;
|
|
83
|
-
this.width = width;
|
|
84
|
-
this.height = height;
|
|
85
|
-
this.colorSpace = colorSpace;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async embedIntoContext(context: PDFContext, ref?: PDFRef): Promise<PDFRef> {
|
|
89
|
-
const xObject = context.stream(this.imageData, {
|
|
90
|
-
Type: 'XObject',
|
|
91
|
-
Subtype: 'Image',
|
|
92
|
-
BitsPerComponent: this.bitsPerComponent,
|
|
93
|
-
Width: this.width,
|
|
94
|
-
Height: this.height,
|
|
95
|
-
ColorSpace: this.colorSpace,
|
|
96
|
-
Filter: 'DCTDecode',
|
|
97
|
-
|
|
98
|
-
// CMYK JPEG streams in PDF are typically stored complemented,
|
|
99
|
-
// with 1 as 'off' and 0 as 'on' (PDF 32000-1:2008, 8.6.4.4).
|
|
100
|
-
//
|
|
101
|
-
// Standalone CMYK JPEG (usually exported by Photoshop) are
|
|
102
|
-
// stored inverse, with 0 as 'off' and 1 as 'on', like RGB.
|
|
103
|
-
//
|
|
104
|
-
// Applying a swap here as a hedge that most bytes passing
|
|
105
|
-
// through this method will benefit from it.
|
|
106
|
-
Decode: this.colorSpace === ColorSpace.DeviceCMYK ? [1, 0, 1, 0, 1, 0, 1, 0] : undefined,
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
if (ref) {
|
|
110
|
-
context.assign(ref, xObject);
|
|
111
|
-
return ref;
|
|
112
|
-
} else {
|
|
113
|
-
return context.register(xObject);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export default JpegEmbedder;
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { MissingPageContentsEmbeddingError, UnrecognizedStreamTypeError } from '../errors';
|
|
2
|
-
import PDFArray from '../objects/PDFArray';
|
|
3
|
-
import PDFNumber from '../objects/PDFNumber';
|
|
4
|
-
import PDFRawStream from '../objects/PDFRawStream';
|
|
5
|
-
import PDFRef from '../objects/PDFRef';
|
|
6
|
-
import PDFStream from '../objects/PDFStream';
|
|
7
|
-
import PDFContext from '../PDFContext';
|
|
8
|
-
import { decodePDFRawStream } from '../streams/decode';
|
|
9
|
-
import PDFContentStream from '../structures/PDFContentStream';
|
|
10
|
-
import PDFPageLeaf from '../structures/PDFPageLeaf';
|
|
11
|
-
import CharCodes from '../syntax/CharCodes';
|
|
12
|
-
import { TransformationMatrix } from '../../types/matrix';
|
|
13
|
-
import { mergeIntoTypedArray } from '../../utils';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Represents a page bounding box.
|
|
17
|
-
* Usually `left` and `bottom` are 0 and right, top are equal
|
|
18
|
-
* to width, height if you want to clip to the whole page.
|
|
19
|
-
*
|
|
20
|
-
* y
|
|
21
|
-
* ^
|
|
22
|
-
* | +--------+ (width,height)
|
|
23
|
-
* | | |
|
|
24
|
-
* | | Page |
|
|
25
|
-
* | | |
|
|
26
|
-
* | | |
|
|
27
|
-
* (0,0) | +--------+
|
|
28
|
-
* +----------> x
|
|
29
|
-
*/
|
|
30
|
-
export interface PageBoundingBox {
|
|
31
|
-
left: number /** The left of the bounding box */;
|
|
32
|
-
bottom: number /** The bottom of the bounding box */;
|
|
33
|
-
right: number /** The right of the bounding box */;
|
|
34
|
-
top: number /** The top of the bounding box */;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const fullPageBoundingBox = (page: PDFPageLeaf) => {
|
|
38
|
-
const mediaBox = page.MediaBox();
|
|
39
|
-
|
|
40
|
-
const width = mediaBox.lookup(2, PDFNumber).asNumber() - mediaBox.lookup(0, PDFNumber).asNumber();
|
|
41
|
-
|
|
42
|
-
const height =
|
|
43
|
-
mediaBox.lookup(3, PDFNumber).asNumber() - mediaBox.lookup(1, PDFNumber).asNumber();
|
|
44
|
-
|
|
45
|
-
return { left: 0, bottom: 0, right: width, top: height };
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// Returns the identity matrix, modified to position the content of the given
|
|
49
|
-
// bounding box at (0, 0).
|
|
50
|
-
const boundingBoxAdjustedMatrix = (bb: PageBoundingBox): TransformationMatrix => [
|
|
51
|
-
1,
|
|
52
|
-
0,
|
|
53
|
-
0,
|
|
54
|
-
1,
|
|
55
|
-
-bb.left,
|
|
56
|
-
-bb.bottom,
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
class PDFPageEmbedder {
|
|
60
|
-
static async for(
|
|
61
|
-
page: PDFPageLeaf,
|
|
62
|
-
boundingBox?: PageBoundingBox,
|
|
63
|
-
transformationMatrix?: TransformationMatrix,
|
|
64
|
-
) {
|
|
65
|
-
return new PDFPageEmbedder(page, boundingBox, transformationMatrix);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
readonly width: number;
|
|
69
|
-
readonly height: number;
|
|
70
|
-
readonly boundingBox: PageBoundingBox;
|
|
71
|
-
readonly transformationMatrix: TransformationMatrix;
|
|
72
|
-
|
|
73
|
-
private readonly page: PDFPageLeaf;
|
|
74
|
-
|
|
75
|
-
private constructor(
|
|
76
|
-
page: PDFPageLeaf,
|
|
77
|
-
boundingBox?: PageBoundingBox,
|
|
78
|
-
transformationMatrix?: TransformationMatrix,
|
|
79
|
-
) {
|
|
80
|
-
this.page = page;
|
|
81
|
-
|
|
82
|
-
const bb = boundingBox ?? fullPageBoundingBox(page);
|
|
83
|
-
|
|
84
|
-
this.width = bb.right - bb.left;
|
|
85
|
-
this.height = bb.top - bb.bottom;
|
|
86
|
-
this.boundingBox = bb;
|
|
87
|
-
this.transformationMatrix = transformationMatrix ?? boundingBoxAdjustedMatrix(bb);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async embedIntoContext(context: PDFContext, ref?: PDFRef): Promise<PDFRef> {
|
|
91
|
-
const { Contents, Resources } = this.page.normalizedEntries();
|
|
92
|
-
|
|
93
|
-
if (!Contents) throw new MissingPageContentsEmbeddingError();
|
|
94
|
-
const decodedContents = this.decodeContents(Contents);
|
|
95
|
-
|
|
96
|
-
const { left, bottom, right, top } = this.boundingBox;
|
|
97
|
-
const xObject = context.flateStream(decodedContents, {
|
|
98
|
-
Type: 'XObject',
|
|
99
|
-
Subtype: 'Form',
|
|
100
|
-
FormType: 1,
|
|
101
|
-
BBox: [left, bottom, right, top],
|
|
102
|
-
Matrix: this.transformationMatrix,
|
|
103
|
-
Resources,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
if (ref) {
|
|
107
|
-
context.assign(ref, xObject);
|
|
108
|
-
return ref;
|
|
109
|
-
} else {
|
|
110
|
-
return context.register(xObject);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// `contents` is an array of streams which are merged to include them in the XObject.
|
|
115
|
-
// This methods extracts each stream and joins them with a newline character.
|
|
116
|
-
private decodeContents(contents: PDFArray) {
|
|
117
|
-
const newline = Uint8Array.of(CharCodes.Newline);
|
|
118
|
-
const decodedContents: Uint8Array[] = [];
|
|
119
|
-
|
|
120
|
-
for (let idx = 0, len = contents.size(); idx < len; idx++) {
|
|
121
|
-
const stream = contents.lookup(idx, PDFStream);
|
|
122
|
-
|
|
123
|
-
let content: Uint8Array;
|
|
124
|
-
if (stream instanceof PDFRawStream) {
|
|
125
|
-
content = decodePDFRawStream(stream).decode();
|
|
126
|
-
} else if (stream instanceof PDFContentStream) {
|
|
127
|
-
content = stream.getUnencodedContents();
|
|
128
|
-
} else {
|
|
129
|
-
throw new UnrecognizedStreamTypeError(stream);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
decodedContents.push(content, newline);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return mergeIntoTypedArray(...decodedContents);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export default PDFPageEmbedder;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import PDFRef from '../objects/PDFRef';
|
|
2
|
-
import PDFContext from '../PDFContext';
|
|
3
|
-
import { PNG } from '../../utils/png';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A note of thanks to the developers of https://github.com/foliojs/pdfkit, as
|
|
7
|
-
* this class borrows from:
|
|
8
|
-
* https://github.com/devongovett/pdfkit/blob/e71edab0dd4657b5a767804ba86c94c58d01fbca/lib/image/png.coffee
|
|
9
|
-
*/
|
|
10
|
-
class PngEmbedder {
|
|
11
|
-
static async for(imageData: Uint8Array) {
|
|
12
|
-
const png = PNG.load(imageData);
|
|
13
|
-
return new PngEmbedder(png);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
readonly bitsPerComponent: number;
|
|
17
|
-
readonly height: number;
|
|
18
|
-
readonly width: number;
|
|
19
|
-
readonly colorSpace: 'DeviceRGB';
|
|
20
|
-
|
|
21
|
-
private readonly image: PNG;
|
|
22
|
-
|
|
23
|
-
private constructor(png: PNG) {
|
|
24
|
-
this.image = png;
|
|
25
|
-
this.bitsPerComponent = png.bitsPerComponent;
|
|
26
|
-
this.width = png.width;
|
|
27
|
-
this.height = png.height;
|
|
28
|
-
this.colorSpace = 'DeviceRGB';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async embedIntoContext(context: PDFContext, ref?: PDFRef): Promise<PDFRef> {
|
|
32
|
-
const SMask = this.embedAlphaChannel(context);
|
|
33
|
-
|
|
34
|
-
const xObject = context.flateStream(this.image.rgbChannel, {
|
|
35
|
-
Type: 'XObject',
|
|
36
|
-
Subtype: 'Image',
|
|
37
|
-
BitsPerComponent: this.image.bitsPerComponent,
|
|
38
|
-
Width: this.image.width,
|
|
39
|
-
Height: this.image.height,
|
|
40
|
-
ColorSpace: this.colorSpace,
|
|
41
|
-
SMask,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
if (ref) {
|
|
45
|
-
context.assign(ref, xObject);
|
|
46
|
-
return ref;
|
|
47
|
-
} else {
|
|
48
|
-
return context.register(xObject);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private embedAlphaChannel(context: PDFContext): PDFRef | undefined {
|
|
53
|
-
if (!this.image.alphaChannel) return undefined;
|
|
54
|
-
|
|
55
|
-
const xObject = context.flateStream(this.image.alphaChannel, {
|
|
56
|
-
Type: 'XObject',
|
|
57
|
-
Subtype: 'Image',
|
|
58
|
-
Height: this.image.height,
|
|
59
|
-
Width: this.image.width,
|
|
60
|
-
BitsPerComponent: this.image.bitsPerComponent,
|
|
61
|
-
ColorSpace: 'DeviceGray',
|
|
62
|
-
Decode: [0, 1],
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return context.register(xObject);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default PngEmbedder;
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { Encodings, Font, FontNames, EncodingType } from '@pdf-lib/standard-fonts';
|
|
2
|
-
|
|
3
|
-
import PDFHexString from '../objects/PDFHexString';
|
|
4
|
-
import PDFRef from '../objects/PDFRef';
|
|
5
|
-
import PDFContext from '../PDFContext';
|
|
6
|
-
import { toCodePoint, toHexString } from '../../utils';
|
|
7
|
-
|
|
8
|
-
export interface Glyph {
|
|
9
|
-
code: number;
|
|
10
|
-
name: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A note of thanks to the developers of https://github.com/foliojs/pdfkit, as
|
|
15
|
-
* this class borrows from:
|
|
16
|
-
* https://github.com/foliojs/pdfkit/blob/f91bdd61c164a72ea06be1a43dc0a412afc3925f/lib/font/afm.coffee
|
|
17
|
-
*/
|
|
18
|
-
class StandardFontEmbedder {
|
|
19
|
-
static for = (fontName: FontNames, customName?: string) =>
|
|
20
|
-
new StandardFontEmbedder(fontName, customName);
|
|
21
|
-
|
|
22
|
-
readonly font: Font;
|
|
23
|
-
readonly encoding: EncodingType;
|
|
24
|
-
readonly fontName: string;
|
|
25
|
-
readonly customName: string | undefined;
|
|
26
|
-
|
|
27
|
-
private constructor(fontName: FontNames, customName?: string) {
|
|
28
|
-
// prettier-ignore
|
|
29
|
-
this.encoding = (
|
|
30
|
-
fontName === FontNames.ZapfDingbats ? Encodings.ZapfDingbats
|
|
31
|
-
: fontName === FontNames.Symbol ? Encodings.Symbol
|
|
32
|
-
: Encodings.WinAnsi
|
|
33
|
-
);
|
|
34
|
-
this.font = Font.load(fontName);
|
|
35
|
-
this.fontName = this.font.FontName;
|
|
36
|
-
this.customName = customName;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Encode the JavaScript string into this font. (JavaScript encodes strings in
|
|
41
|
-
* Unicode, but standard fonts use either WinAnsi, ZapfDingbats, or Symbol
|
|
42
|
-
* encodings)
|
|
43
|
-
*/
|
|
44
|
-
encodeText(text: string): PDFHexString {
|
|
45
|
-
const glyphs = this.encodeTextAsGlyphs(text);
|
|
46
|
-
const hexCodes = Array(glyphs.length);
|
|
47
|
-
for (let idx = 0, len = glyphs.length; idx < len; idx++) {
|
|
48
|
-
hexCodes[idx] = toHexString(glyphs[idx].code);
|
|
49
|
-
}
|
|
50
|
-
return PDFHexString.of(hexCodes.join(''));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
widthOfTextAtSize(text: string, size: number): number {
|
|
54
|
-
const glyphs = this.encodeTextAsGlyphs(text);
|
|
55
|
-
let totalWidth = 0;
|
|
56
|
-
|
|
57
|
-
for (let idx = 0, len = glyphs.length; idx < len; idx++) {
|
|
58
|
-
const left = glyphs[idx].name;
|
|
59
|
-
const right = (glyphs[idx + 1] || {}).name;
|
|
60
|
-
const kernAmount = this.font.getXAxisKerningForPair(left, right) || 0;
|
|
61
|
-
totalWidth += this.widthOfGlyph(left) + kernAmount;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const scale = size / 1000;
|
|
65
|
-
return totalWidth * scale;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
heightOfFontAtSize(size: number, options: { descender?: boolean } = {}): number {
|
|
69
|
-
const { descender = true } = options;
|
|
70
|
-
|
|
71
|
-
const { Ascender, Descender, FontBBox } = this.font;
|
|
72
|
-
const yTop = Ascender || FontBBox[3];
|
|
73
|
-
const yBottom = Descender || FontBBox[1];
|
|
74
|
-
|
|
75
|
-
let height = yTop - yBottom;
|
|
76
|
-
if (!descender) height += Descender || 0;
|
|
77
|
-
|
|
78
|
-
return (height / 1000) * size;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
sizeOfFontAtHeight(height: number): number {
|
|
82
|
-
const { Ascender, Descender, FontBBox } = this.font;
|
|
83
|
-
const yTop = Ascender || FontBBox[3];
|
|
84
|
-
const yBottom = Descender || FontBBox[1];
|
|
85
|
-
return (1000 * height) / (yTop - yBottom);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
embedIntoContext(context: PDFContext, ref?: PDFRef): PDFRef {
|
|
89
|
-
const fontDict = context.obj({
|
|
90
|
-
Type: 'Font',
|
|
91
|
-
Subtype: 'Type1',
|
|
92
|
-
BaseFont: this.customName || this.fontName,
|
|
93
|
-
|
|
94
|
-
Encoding: this.encoding === Encodings.WinAnsi ? 'WinAnsiEncoding' : undefined,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
if (ref) {
|
|
98
|
-
context.assign(ref, fontDict);
|
|
99
|
-
return ref;
|
|
100
|
-
} else {
|
|
101
|
-
return context.register(fontDict);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private widthOfGlyph(glyphName: string): number {
|
|
106
|
-
// Default to 250 if font doesn't specify a width
|
|
107
|
-
return this.font.getWidthOfGlyph(glyphName) || 250;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
private encodeTextAsGlyphs(text: string): Glyph[] {
|
|
111
|
-
const codePoints = Array.from(text);
|
|
112
|
-
const glyphs: Glyph[] = Array(codePoints.length);
|
|
113
|
-
for (let idx = 0, len = codePoints.length; idx < len; idx++) {
|
|
114
|
-
const codePoint = toCodePoint(codePoints[idx])!;
|
|
115
|
-
glyphs[idx] = this.encoding.encodeUnicodeCodePoint(codePoint);
|
|
116
|
-
}
|
|
117
|
-
return glyphs;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export default StandardFontEmbedder;
|