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