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