@pdfme/pdf-lib 6.0.3 → 6.0.4-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,96 +0,0 @@
1
- import PDFContext from '../PDFContext';
2
- import PDFDict from '../objects/PDFDict';
3
- import PDFArray from '../objects/PDFArray';
4
- import PDFName from '../objects/PDFName';
5
- import PDFRef from '../objects/PDFRef';
6
- import PDFAcroField from './PDFAcroField';
7
- import PDFAcroNonTerminal from './PDFAcroNonTerminal';
8
- import { createPDFAcroField, createPDFAcroFields } from './utils';
9
-
10
- class PDFAcroForm {
11
- readonly dict: PDFDict;
12
-
13
- static fromDict = (dict: PDFDict) => new PDFAcroForm(dict);
14
-
15
- static create = (context: PDFContext) => {
16
- const dict = context.obj({ Fields: [] });
17
- return new PDFAcroForm(dict);
18
- };
19
-
20
- private constructor(dict: PDFDict) {
21
- this.dict = dict;
22
- }
23
-
24
- Fields(): PDFArray | undefined {
25
- const fields = this.dict.lookup(PDFName.of('Fields'));
26
- if (fields instanceof PDFArray) return fields;
27
- return undefined;
28
- }
29
-
30
- getFields(): [PDFAcroField, PDFRef][] {
31
- const { Fields } = this.normalizedEntries();
32
-
33
- const fields = Array(Fields.size());
34
- for (let idx = 0, len = Fields.size(); idx < len; idx++) {
35
- const ref = Fields.get(idx) as PDFRef;
36
- const dict = Fields.lookup(idx, PDFDict);
37
- fields[idx] = [createPDFAcroField(dict, ref), ref];
38
- }
39
-
40
- return fields;
41
- }
42
-
43
- getAllFields(): [PDFAcroField, PDFRef][] {
44
- const allFields: [PDFAcroField, PDFRef][] = [];
45
-
46
- const pushFields = (fields?: [PDFAcroField, PDFRef][]) => {
47
- if (!fields) return;
48
- for (let idx = 0, len = fields.length; idx < len; idx++) {
49
- const field = fields[idx];
50
- allFields.push(field);
51
- const [fieldModel] = field;
52
- if (fieldModel instanceof PDFAcroNonTerminal) {
53
- pushFields(createPDFAcroFields(fieldModel.Kids()));
54
- }
55
- }
56
- };
57
-
58
- pushFields(this.getFields());
59
-
60
- return allFields;
61
- }
62
-
63
- addField(field: PDFRef) {
64
- const { Fields } = this.normalizedEntries();
65
- Fields?.push(field);
66
- }
67
-
68
- removeField(field: PDFAcroField): void {
69
- const parent = field.getParent();
70
- const fields = parent === undefined ? this.normalizedEntries().Fields : parent.Kids();
71
-
72
- const index = fields?.indexOf(field.ref);
73
- if (fields === undefined || index === undefined) {
74
- throw new Error(`Tried to remove inexistent field ${field.getFullyQualifiedName()}`);
75
- }
76
-
77
- fields.remove(index);
78
-
79
- if (parent !== undefined && fields.size() === 0) {
80
- this.removeField(parent);
81
- }
82
- }
83
-
84
- normalizedEntries() {
85
- let Fields = this.Fields();
86
-
87
- if (!Fields) {
88
- Fields = this.dict.context.obj([]);
89
- this.dict.set(PDFName.of('Fields'), Fields);
90
- }
91
-
92
- return { Fields };
93
- }
94
- }
95
-
96
- export default PDFAcroForm;
@@ -1,19 +0,0 @@
1
- import PDFDict from '../objects/PDFDict';
2
- import PDFAcroChoice from './PDFAcroChoice';
3
- import PDFContext from '../PDFContext';
4
- import PDFRef from '../objects/PDFRef';
5
-
6
- class PDFAcroListBox extends PDFAcroChoice {
7
- static fromDict = (dict: PDFDict, ref: PDFRef) => new PDFAcroListBox(dict, ref);
8
-
9
- static create = (context: PDFContext) => {
10
- const dict = context.obj({
11
- FT: 'Ch',
12
- Kids: [],
13
- });
14
- const ref = context.register(dict);
15
- return new PDFAcroListBox(dict, ref);
16
- };
17
- }
18
-
19
- export default PDFAcroListBox;
@@ -1,33 +0,0 @@
1
- import PDFDict from '../objects/PDFDict';
2
- import PDFRef from '../objects/PDFRef';
3
- import PDFName from '../objects/PDFName';
4
- import PDFContext from '../PDFContext';
5
- import PDFAcroField from './PDFAcroField';
6
-
7
- class PDFAcroNonTerminal extends PDFAcroField {
8
- static fromDict = (dict: PDFDict, ref: PDFRef) => new PDFAcroNonTerminal(dict, ref);
9
-
10
- static create = (context: PDFContext) => {
11
- const dict = context.obj({});
12
- const ref = context.register(dict);
13
- return new PDFAcroNonTerminal(dict, ref);
14
- };
15
-
16
- addField(field: PDFRef) {
17
- const { Kids } = this.normalizedEntries();
18
- Kids?.push(field);
19
- }
20
-
21
- normalizedEntries() {
22
- let Kids = this.Kids();
23
-
24
- if (!Kids) {
25
- Kids = this.dict.context.obj([]);
26
- this.dict.set(PDFName.of('Kids'), Kids);
27
- }
28
-
29
- return { Kids };
30
- }
31
- }
32
-
33
- export default PDFAcroNonTerminal;
@@ -1,21 +0,0 @@
1
- import PDFDict from '../objects/PDFDict';
2
- import PDFAcroButton from './PDFAcroButton';
3
- import PDFContext from '../PDFContext';
4
- import PDFRef from '../objects/PDFRef';
5
- import { AcroButtonFlags } from './flags';
6
-
7
- class PDFAcroPushButton extends PDFAcroButton {
8
- static fromDict = (dict: PDFDict, ref: PDFRef) => new PDFAcroPushButton(dict, ref);
9
-
10
- static create = (context: PDFContext) => {
11
- const dict = context.obj({
12
- FT: 'Btn',
13
- Ff: AcroButtonFlags.PushButton,
14
- Kids: [],
15
- });
16
- const ref = context.register(dict);
17
- return new PDFAcroPushButton(dict, ref);
18
- };
19
- }
20
-
21
- export default PDFAcroPushButton;
@@ -1,57 +0,0 @@
1
- import PDFRef from '../objects/PDFRef';
2
- import PDFDict from '../objects/PDFDict';
3
- import PDFName from '../objects/PDFName';
4
- import PDFAcroButton from './PDFAcroButton';
5
- import PDFContext from '../PDFContext';
6
- import { AcroButtonFlags } from './flags';
7
- import { InvalidAcroFieldValueError } from '../errors';
8
-
9
- class PDFAcroRadioButton extends PDFAcroButton {
10
- static fromDict = (dict: PDFDict, ref: PDFRef) => new PDFAcroRadioButton(dict, ref);
11
-
12
- static create = (context: PDFContext) => {
13
- const dict = context.obj({
14
- FT: 'Btn',
15
- Ff: AcroButtonFlags.Radio,
16
- Kids: [],
17
- });
18
- const ref = context.register(dict);
19
- return new PDFAcroRadioButton(dict, ref);
20
- };
21
-
22
- setValue(value: PDFName) {
23
- const onValues = this.getOnValues();
24
- if (!onValues.includes(value) && value !== PDFName.of('Off')) {
25
- throw new InvalidAcroFieldValueError();
26
- }
27
-
28
- this.dict.set(PDFName.of('V'), value);
29
-
30
- const widgets = this.getWidgets();
31
- for (let idx = 0, len = widgets.length; idx < len; idx++) {
32
- const widget = widgets[idx];
33
- const state = widget.getOnValue() === value ? value : PDFName.of('Off');
34
- widget.setAppearanceState(state);
35
- }
36
- }
37
-
38
- getValue(): PDFName {
39
- const v = this.V();
40
- if (v instanceof PDFName) return v;
41
- return PDFName.of('Off');
42
- }
43
-
44
- getOnValues(): PDFName[] {
45
- const widgets = this.getWidgets();
46
-
47
- const onValues: PDFName[] = [];
48
- for (let idx = 0, len = widgets.length; idx < len; idx++) {
49
- const onValue = widgets[idx].getOnValue();
50
- if (onValue) onValues.push(onValue);
51
- }
52
-
53
- return onValues;
54
- }
55
- }
56
-
57
- export default PDFAcroRadioButton;
@@ -1,70 +0,0 @@
1
- import PDFDict from '../objects/PDFDict';
2
- import PDFName from '../objects/PDFName';
3
- import PDFRef from '../objects/PDFRef';
4
- import PDFAcroField from './PDFAcroField';
5
- import PDFWidgetAnnotation from '../annotation/PDFWidgetAnnotation';
6
- import { IndexOutOfBoundsError } from '../errors';
7
-
8
- class PDFAcroTerminal extends PDFAcroField {
9
- static fromDict = (dict: PDFDict, ref: PDFRef) => new PDFAcroTerminal(dict, ref);
10
-
11
- FT(): PDFName {
12
- const nameOrRef = this.getInheritableAttribute(PDFName.of('FT'));
13
- return this.dict.context.lookup(nameOrRef, PDFName);
14
- }
15
-
16
- getWidgets(): PDFWidgetAnnotation[] {
17
- const kidDicts = this.Kids();
18
-
19
- // This field is itself a widget
20
- if (!kidDicts) return [PDFWidgetAnnotation.fromDict(this.dict)];
21
-
22
- // This field's kids are its widgets
23
- const widgets = Array<PDFWidgetAnnotation>(kidDicts.size());
24
- for (let idx = 0, len = kidDicts.size(); idx < len; idx++) {
25
- const dict = kidDicts.lookup(idx, PDFDict);
26
- widgets[idx] = PDFWidgetAnnotation.fromDict(dict);
27
- }
28
-
29
- return widgets;
30
- }
31
-
32
- addWidget(ref: PDFRef) {
33
- const { Kids } = this.normalizedEntries();
34
- Kids.push(ref);
35
- }
36
-
37
- removeWidget(idx: number) {
38
- const kidDicts = this.Kids();
39
-
40
- if (!kidDicts) {
41
- // This field is itself a widget
42
- if (idx !== 0) throw new IndexOutOfBoundsError(idx, 0, 0);
43
- this.setKids([]);
44
- } else {
45
- // This field's kids are its widgets
46
- if (idx < 0 || idx > kidDicts.size()) {
47
- throw new IndexOutOfBoundsError(idx, 0, kidDicts.size());
48
- }
49
- kidDicts.remove(idx);
50
- }
51
- }
52
-
53
- normalizedEntries() {
54
- let Kids = this.Kids();
55
-
56
- // If this field is itself a widget (because it was only rendered once in
57
- // the document, so the field and widget properties were merged) then we
58
- // add itself to the `Kids` array. The alternative would be to try
59
- // splitting apart the widget properties and creating a separate object
60
- // for them.
61
- if (!Kids) {
62
- Kids = this.dict.context.obj([this.ref]);
63
- this.dict.set(PDFName.of('Kids'), Kids);
64
- }
65
-
66
- return { Kids };
67
- }
68
- }
69
-
70
- export default PDFAcroTerminal;
@@ -1,76 +0,0 @@
1
- import PDFContext from '../PDFContext';
2
- import PDFDict from '../objects/PDFDict';
3
- import PDFNumber from '../objects/PDFNumber';
4
- import PDFString from '../objects/PDFString';
5
- import PDFHexString from '../objects/PDFHexString';
6
- import PDFName from '../objects/PDFName';
7
- import PDFRef from '../objects/PDFRef';
8
- import PDFAcroTerminal from './PDFAcroTerminal';
9
-
10
- class PDFAcroText extends PDFAcroTerminal {
11
- static fromDict = (dict: PDFDict, ref: PDFRef) => new PDFAcroText(dict, ref);
12
-
13
- static create = (context: PDFContext) => {
14
- const dict = context.obj({
15
- FT: 'Tx',
16
- Kids: [],
17
- });
18
- const ref = context.register(dict);
19
- return new PDFAcroText(dict, ref);
20
- };
21
-
22
- MaxLen(): PDFNumber | undefined {
23
- const maxLen = this.dict.lookup(PDFName.of('MaxLen'));
24
- if (maxLen instanceof PDFNumber) return maxLen;
25
- return undefined;
26
- }
27
-
28
- Q(): PDFNumber | undefined {
29
- const q = this.dict.lookup(PDFName.of('Q'));
30
- if (q instanceof PDFNumber) return q;
31
- return undefined;
32
- }
33
-
34
- setMaxLength(maxLength: number) {
35
- this.dict.set(PDFName.of('MaxLen'), PDFNumber.of(maxLength));
36
- }
37
-
38
- removeMaxLength() {
39
- this.dict.delete(PDFName.of('MaxLen'));
40
- }
41
-
42
- getMaxLength(): number | undefined {
43
- return this.MaxLen()?.asNumber();
44
- }
45
-
46
- setQuadding(quadding: 0 | 1 | 2) {
47
- this.dict.set(PDFName.of('Q'), PDFNumber.of(quadding));
48
- }
49
-
50
- getQuadding(): number | undefined {
51
- return this.Q()?.asNumber();
52
- }
53
-
54
- setValue(value: PDFHexString | PDFString) {
55
- this.dict.set(PDFName.of('V'), value);
56
-
57
- // const widgets = this.getWidgets();
58
- // for (let idx = 0, len = widgets.length; idx < len; idx++) {
59
- // const widget = widgets[idx];
60
- // const state = widget.getOnValue() === value ? value : PDFName.of('Off');
61
- // widget.setAppearanceState(state);
62
- // }
63
- }
64
-
65
- removeValue() {
66
- this.dict.delete(PDFName.of('V'));
67
- }
68
-
69
- getValue(): PDFString | PDFHexString | undefined {
70
- const v = this.V();
71
- if (v instanceof PDFString || v instanceof PDFHexString) return v;
72
- return undefined;
73
- }
74
- }
75
-
76
- export default PDFAcroText;
@@ -1,162 +0,0 @@
1
- const flag = (bitIndex: number) => 1 << bitIndex;
2
-
3
- /** From PDF spec table 221 */
4
- export enum AcroFieldFlags {
5
- /**
6
- * If set, the user may not change the value of the field. Any associated
7
- * widget annotations will not interact with the user; that is, they will not
8
- * respond to mouse clicks or change their appearance in response to mouse
9
- * motions. This flag is useful for fields whose values are computed or
10
- * imported from a database.
11
- */
12
- ReadOnly = flag(1 - 1),
13
-
14
- /**
15
- * If set, the field shall have a value at the time it is exported by a
16
- * submit-form action (see 12.7.5.2, "Submit-Form Action").
17
- */
18
- Required = flag(2 - 1),
19
-
20
- /**
21
- * If set, the field shall not be exported by a submit-form action
22
- * (see 12.7.5.2, "Submit-Form Action").
23
- */
24
- NoExport = flag(3 - 1),
25
- }
26
-
27
- /** From PDF spec table 226 */
28
- export enum AcroButtonFlags {
29
- /**
30
- * (Radio buttons only) If set, exactly one radio button shall be selected at
31
- * all times; selecting the currently selected button has no effect. If clear,
32
- * clicking the selected button deselects it, leaving no button selected.
33
- */
34
- NoToggleToOff = flag(15 - 1),
35
-
36
- /**
37
- * If set, the field is a set of radio buttons; if clear, the field is a check
38
- * box. This flag may be set only if the Pushbutton flag is clear.
39
- */
40
- Radio = flag(16 - 1),
41
-
42
- /**
43
- * If set, the field is a pushbutton that does not retain a permanent value.
44
- */
45
- PushButton = flag(17 - 1),
46
-
47
- /**
48
- * If set, a group of radio buttons within a radio button field that use the
49
- * same value for the on state will turn on and off in unison; that is if one
50
- * is checked, they are all checked. If clear, the buttons are mutually
51
- * exclusive (the same behavior as HTML radio buttons).
52
- */
53
- RadiosInUnison = flag(26 - 1),
54
- }
55
-
56
- /** From PDF spec table 228 */
57
- export enum AcroTextFlags {
58
- /**
59
- * If set, the field may contain multiple lines of text; if clear, the field's
60
- * text shall be restricted to a single line.
61
- */
62
- Multiline = flag(13 - 1),
63
-
64
- /**
65
- * If set, the field is intended for entering a secure password that should
66
- * not be echoed visibly to the screen. Characters typed from the keyboard
67
- * shall instead be echoed in some unreadable form, such as asterisks or
68
- * bullet characters.
69
- * > NOTE To protect password confidentiality, readers should never store
70
- * > the value of the text field in the PDF file if this flag is set.
71
- */
72
- Password = flag(14 - 1),
73
-
74
- /**
75
- * If set, the text entered in the field represents the pathname of a file
76
- * whose contents shall be submitted as the value of the field.
77
- */
78
- FileSelect = flag(21 - 1),
79
-
80
- /**
81
- * If set, text entered in the field shall not be spell-checked.
82
- */
83
- DoNotSpellCheck = flag(23 - 1),
84
-
85
- /**
86
- * If set, the field shall not scroll (horizontally for single-line fields,
87
- * vertically for multiple-line fields) to accommodate more text than fits
88
- * within its annotation rectangle. Once the field is full, no further text
89
- * shall be accepted for interactive form filling; for non-interactive form
90
- * filling, the filler should take care not to add more character than will
91
- * visibly fit in the defined area.
92
- */
93
- DoNotScroll = flag(24 - 1),
94
-
95
- /**
96
- * May be set only if the MaxLen entry is present in the text field dictionary
97
- * (see Table 229) and if the Multiline, Password, and FileSelect flags are
98
- * clear. If set, the field shall be automatically divided into as many
99
- * equally spaced positions, or combs, as the value of MaxLen, and the text
100
- * is laid out into those combs.
101
- */
102
- Comb = flag(25 - 1),
103
-
104
- /**
105
- * If set, the value of this field shall be a rich text string
106
- * (see 12.7.3.4, "Rich Text Strings"). If the field has a value, the RV
107
- * entry of the field dictionary (Table 222) shall specify the rich text
108
- * string.
109
- */
110
- RichText = flag(26 - 1),
111
- }
112
-
113
- /** From PDF spec table 230 */
114
- export enum AcroChoiceFlags {
115
- /**
116
- * If set, the field is a combo box; if clear, the field is a list box.
117
- */
118
- Combo = flag(18 - 1),
119
-
120
- /**
121
- * If set, the combo box shall include an editable text box as well as a
122
- * drop-down list; if clear, it shall include only a drop-down list. This
123
- * flag shall be used only if the Combo flag is set.
124
- */
125
- Edit = flag(19 - 1),
126
-
127
- /**
128
- * If set, the field's option items shall be sorted alphabetically. This flag
129
- * is intended for use by writers, not by readers. Conforming readers shall
130
- * display the options in the order in which they occur in the Opt array
131
- * (see Table 231).
132
- */
133
- Sort = flag(20 - 1),
134
-
135
- /**
136
- * If set, more than one of the field's option items may be selected
137
- * simultaneously; if clear, at most one item shall be selected.
138
- */
139
- MultiSelect = flag(22 - 1),
140
-
141
- /**
142
- * If set, text entered in the field shall not be spell-checked. This flag
143
- * shall not be used unless the Combo and Edit flags are both set.
144
- */
145
- DoNotSpellCheck = flag(23 - 1),
146
-
147
- /**
148
- * If set, the new value shall be committed as soon as a selection is made
149
- * (commonly with the pointing device). In this case, supplying a value for
150
- * a field involves three actions: selecting the field for fill-in,
151
- * selecting a choice for the fill-in value, and leaving that field, which
152
- * finalizes or "commits" the data choice and triggers any actions associated
153
- * with the entry or changing of this data. If this flag is on, then
154
- * processing does not wait for leaving the field action to occur, but
155
- * immediately proceeds to the third step.
156
- *
157
- * This option enables applications to perform an action once a selection is
158
- * made, without requiring the user to exit the field. If clear, the new
159
- * value is not committed until the user exits the field.
160
- */
161
- CommitOnSelChange = flag(27 - 1),
162
- }
@@ -1,129 +0,0 @@
1
- import PDFObject from '../objects/PDFObject';
2
- import PDFNumber from '../objects/PDFNumber';
3
- import PDFDict from '../objects/PDFDict';
4
- import PDFName from '../objects/PDFName';
5
- import PDFArray from '../objects/PDFArray';
6
- import PDFRef from '../objects/PDFRef';
7
-
8
- import PDFAcroField from './PDFAcroField';
9
- import PDFAcroTerminal from './PDFAcroTerminal';
10
- import PDFAcroNonTerminal from './PDFAcroNonTerminal';
11
- import PDFAcroButton from './PDFAcroButton';
12
- import PDFAcroSignature from './PDFAcroSignature';
13
- import PDFAcroChoice from './PDFAcroChoice';
14
- import PDFAcroText from './PDFAcroText';
15
- import PDFAcroPushButton from './PDFAcroPushButton';
16
- import PDFAcroRadioButton from './PDFAcroRadioButton';
17
- import PDFAcroCheckBox from './PDFAcroCheckBox';
18
- import PDFAcroComboBox from './PDFAcroComboBox';
19
- import PDFAcroListBox from './PDFAcroListBox';
20
- import { AcroButtonFlags, AcroChoiceFlags } from './flags';
21
-
22
- export const createPDFAcroFields = (kidDicts?: PDFArray): [PDFAcroField, PDFRef][] => {
23
- if (!kidDicts) return [];
24
-
25
- const kids: [PDFAcroField, PDFRef][] = [];
26
- for (let idx = 0, len = kidDicts.size(); idx < len; idx++) {
27
- const ref = kidDicts.get(idx);
28
- const dict = kidDicts.lookup(idx);
29
- // if (dict instanceof PDFDict) kids.push(PDFAcroField.fromDict(dict));
30
- if (ref instanceof PDFRef && dict instanceof PDFDict) {
31
- kids.push([createPDFAcroField(dict, ref), ref]);
32
- }
33
- }
34
-
35
- return kids;
36
- };
37
-
38
- export const createPDFAcroField = (dict: PDFDict, ref: PDFRef): PDFAcroField => {
39
- const isNonTerminal = isNonTerminalAcroField(dict);
40
- if (isNonTerminal) return PDFAcroNonTerminal.fromDict(dict, ref);
41
- return createPDFAcroTerminal(dict, ref);
42
- };
43
-
44
- // TODO: Maybe just check if the dict is *not* a widget? That might be better.
45
-
46
- // According to the PDF spec:
47
- //
48
- // > A field's children in the hierarchy may also include widget annotations
49
- // > that define its appearance on the page. A field that has children that
50
- // > are fields is called a non-terminal field. A field that does not have
51
- // > children that are fields is called a terminal field.
52
- //
53
- // The spec is not entirely clear about how to determine whether a given
54
- // dictionary represents an acrofield or a widget annotation. So we will assume
55
- // that a dictionary is an acrofield if it is a member of the `/Kids` array
56
- // and it contains a `/T` entry (widgets do not have `/T` entries). This isn't
57
- // a bullet proof solution, because the `/T` entry is technically defined as
58
- // optional for acrofields by the PDF spec. But in practice all acrofields seem
59
- // to have a `/T` entry defined.
60
- const isNonTerminalAcroField = (dict: PDFDict): boolean => {
61
- const kids = dict.lookup(PDFName.of('Kids'));
62
-
63
- if (kids instanceof PDFArray) {
64
- for (let idx = 0, len = kids.size(); idx < len; idx++) {
65
- const kid = kids.lookup(idx);
66
- const kidIsField = kid instanceof PDFDict && kid.has(PDFName.of('T'));
67
- if (kidIsField) return true;
68
- }
69
- }
70
-
71
- return false;
72
- };
73
-
74
- const createPDFAcroTerminal = (dict: PDFDict, ref: PDFRef): PDFAcroTerminal => {
75
- const ftNameOrRef = getInheritableAttribute(dict, PDFName.of('FT'));
76
- const type = dict.context.lookup(ftNameOrRef, PDFName);
77
-
78
- if (type === PDFName.of('Btn')) return createPDFAcroButton(dict, ref);
79
- if (type === PDFName.of('Ch')) return createPDFAcroChoice(dict, ref);
80
- if (type === PDFName.of('Tx')) return PDFAcroText.fromDict(dict, ref);
81
- if (type === PDFName.of('Sig')) return PDFAcroSignature.fromDict(dict, ref);
82
-
83
- // We should never reach this line. But there are a lot of weird PDFs out
84
- // there. So, just to be safe, we'll try to handle things gracefully instead
85
- // of throwing an error.
86
- return PDFAcroTerminal.fromDict(dict, ref);
87
- };
88
-
89
- const createPDFAcroButton = (dict: PDFDict, ref: PDFRef): PDFAcroButton => {
90
- const ffNumberOrRef = getInheritableAttribute(dict, PDFName.of('Ff'));
91
- const ffNumber = dict.context.lookupMaybe(ffNumberOrRef, PDFNumber);
92
- const flags = ffNumber?.asNumber() ?? 0;
93
-
94
- if (flagIsSet(flags, AcroButtonFlags.PushButton)) {
95
- return PDFAcroPushButton.fromDict(dict, ref);
96
- } else if (flagIsSet(flags, AcroButtonFlags.Radio)) {
97
- return PDFAcroRadioButton.fromDict(dict, ref);
98
- } else {
99
- return PDFAcroCheckBox.fromDict(dict, ref);
100
- }
101
- };
102
-
103
- const createPDFAcroChoice = (dict: PDFDict, ref: PDFRef): PDFAcroChoice => {
104
- const ffNumberOrRef = getInheritableAttribute(dict, PDFName.of('Ff'));
105
- const ffNumber = dict.context.lookupMaybe(ffNumberOrRef, PDFNumber);
106
- const flags = ffNumber?.asNumber() ?? 0;
107
-
108
- if (flagIsSet(flags, AcroChoiceFlags.Combo)) {
109
- return PDFAcroComboBox.fromDict(dict, ref);
110
- } else {
111
- return PDFAcroListBox.fromDict(dict, ref);
112
- }
113
- };
114
-
115
- const flagIsSet = (flags: number, flag: number): boolean => (flags & flag) !== 0;
116
-
117
- const getInheritableAttribute = (startNode: PDFDict, name: PDFName) => {
118
- let attribute: PDFObject | undefined;
119
- ascend(startNode, (node) => {
120
- if (!attribute) attribute = node.get(name);
121
- });
122
- return attribute;
123
- };
124
-
125
- const ascend = (startNode: PDFDict, visitor: (node: PDFDict) => any) => {
126
- visitor(startNode);
127
- const Parent = startNode.lookupMaybe(PDFName.of('Parent'), PDFDict);
128
- if (Parent) ascend(Parent, visitor);
129
- };