@syncfusion/ej2-pdf 1.0.22 → 23.1.36

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 (518) hide show
  1. package/.eslintrc.json +260 -0
  2. package/.gitleaksignore +1 -0
  3. package/CHANGELOG.md +17 -0
  4. package/README.md +17 -0
  5. package/dist/ej2-pdf.umd.min.js +3 -13
  6. package/dist/ej2-pdf.umd.min.js.map +1 -11
  7. package/dist/es6/ej2-pdf.es2015.js +48245 -0
  8. package/dist/es6/ej2-pdf.es2015.js.map +1 -0
  9. package/dist/es6/ej2-pdf.es5.js +50124 -0
  10. package/dist/es6/ej2-pdf.es5.js.map +1 -0
  11. package/dist/global/ej2-pdf.min.js +11 -0
  12. package/dist/global/ej2-pdf.min.js.map +1 -0
  13. package/dist/global/index.d.ts +14 -0
  14. package/index.js +4 -8
  15. package/license +10 -3
  16. package/package.json +57 -15
  17. package/pdf.d.ts +4 -0
  18. package/pdf.js +4 -0
  19. package/src/global.js +1 -0
  20. package/src/index.d.ts +45 -98
  21. package/src/index.js +45 -96
  22. package/src/pdf/core/annotations/annotation-collection.d.ts +289 -0
  23. package/src/pdf/core/annotations/annotation-collection.js +744 -0
  24. package/src/pdf/core/annotations/annotation.d.ts +5845 -0
  25. package/src/pdf/core/annotations/annotation.js +14195 -0
  26. package/src/pdf/core/annotations/index.d.ts +4 -0
  27. package/src/pdf/core/annotations/index.js +4 -0
  28. package/src/pdf/core/annotations/pdf-appearance.d.ts +102 -0
  29. package/src/pdf/core/annotations/pdf-appearance.js +124 -0
  30. package/src/pdf/core/annotations/pdf-paddings.d.ts +8 -0
  31. package/src/pdf/core/annotations/pdf-paddings.js +22 -0
  32. package/src/pdf/core/base-stream.d.ts +86 -0
  33. package/src/pdf/core/base-stream.js +332 -0
  34. package/src/pdf/core/content-parser.d.ts +38 -0
  35. package/src/pdf/core/content-parser.js +359 -0
  36. package/src/pdf/core/decode-stream.d.ts +21 -0
  37. package/src/pdf/core/decode-stream.js +120 -0
  38. package/src/pdf/core/decrypt-stream.d.ts +11 -0
  39. package/src/pdf/core/decrypt-stream.js +53 -0
  40. package/src/pdf/core/enumerator.d.ts +1668 -0
  41. package/src/pdf/core/enumerator.js +1717 -0
  42. package/src/pdf/core/flate-stream.d.ts +13 -0
  43. package/src/pdf/core/flate-stream.js +329 -0
  44. package/src/pdf/core/fonts/index.d.ts +7 -0
  45. package/{dist/es6/implementation/graphics → src/pdf/core}/fonts/index.js +3 -4
  46. package/src/pdf/core/fonts/pdf-font-metrics.d.ts +66 -0
  47. package/src/pdf/core/fonts/pdf-font-metrics.js +192 -0
  48. package/src/pdf/core/fonts/pdf-standard-font.d.ts +1023 -0
  49. package/src/pdf/core/fonts/pdf-standard-font.js +1682 -0
  50. package/src/pdf/core/fonts/pdf-string-format.d.ts +236 -0
  51. package/src/pdf/core/fonts/pdf-string-format.js +213 -0
  52. package/src/pdf/core/fonts/string-layouter.d.ts +68 -0
  53. package/src/pdf/core/fonts/string-layouter.js +437 -0
  54. package/src/pdf/core/fonts/ttf-reader.d.ts +167 -0
  55. package/src/pdf/core/fonts/ttf-reader.js +1150 -0
  56. package/src/pdf/core/fonts/ttf-table.d.ts +132 -0
  57. package/src/pdf/core/fonts/ttf-table.js +74 -0
  58. package/src/pdf/core/fonts/unicode-true-type-font.d.ts +50 -0
  59. package/src/pdf/core/fonts/unicode-true-type-font.js +289 -0
  60. package/src/pdf/core/form/field.d.ts +3011 -0
  61. package/src/pdf/core/form/field.js +6828 -0
  62. package/src/pdf/core/form/form.d.ts +279 -0
  63. package/src/pdf/core/form/form.js +782 -0
  64. package/src/pdf/core/form/index.d.ts +2 -0
  65. package/src/pdf/core/form/index.js +2 -0
  66. package/src/pdf/core/graphics/images/image-decoder.d.ts +31 -0
  67. package/src/pdf/core/graphics/images/image-decoder.js +130 -0
  68. package/src/{implementation → pdf/core}/graphics/images/index.d.ts +0 -5
  69. package/{dist/es6/implementation → src/pdf/core}/graphics/images/index.js +0 -1
  70. package/src/pdf/core/graphics/images/pdf-bitmap.d.ts +73 -0
  71. package/src/pdf/core/graphics/images/pdf-bitmap.js +68 -0
  72. package/src/pdf/core/graphics/images/pdf-image.d.ts +201 -0
  73. package/src/pdf/core/graphics/images/pdf-image.js +201 -0
  74. package/src/pdf/core/graphics/index.d.ts +10 -0
  75. package/src/pdf/core/graphics/index.js +10 -0
  76. package/src/pdf/core/graphics/pdf-graphics.d.ts +956 -0
  77. package/src/pdf/core/graphics/pdf-graphics.js +1860 -0
  78. package/src/pdf/core/graphics/pdf-path.d.ts +34 -0
  79. package/src/pdf/core/graphics/pdf-path.js +177 -0
  80. package/src/pdf/core/graphics/pdf-stream-writer.d.ts +56 -0
  81. package/src/pdf/core/graphics/pdf-stream-writer.js +231 -0
  82. package/src/pdf/core/graphics/pdf-template.d.ts +79 -0
  83. package/src/pdf/core/graphics/pdf-template.js +100 -0
  84. package/src/pdf/core/graphics/rightToLeft/bidirectional.d.ts +69 -0
  85. package/src/pdf/core/graphics/rightToLeft/bidirectional.js +831 -0
  86. package/src/pdf/core/graphics/rightToLeft/index.d.ts +3 -0
  87. package/src/pdf/core/graphics/rightToLeft/index.js +3 -0
  88. package/src/pdf/core/graphics/rightToLeft/text-renderer.d.ts +13 -0
  89. package/src/pdf/core/graphics/rightToLeft/text-renderer.js +116 -0
  90. package/src/pdf/core/graphics/rightToLeft/text-shape.d.ts +48 -0
  91. package/src/pdf/core/graphics/rightToLeft/text-shape.js +289 -0
  92. package/src/pdf/core/import-export/fdf-document.d.ts +37 -0
  93. package/src/pdf/core/import-export/fdf-document.js +667 -0
  94. package/src/pdf/core/import-export/index.d.ts +5 -0
  95. package/src/pdf/core/import-export/index.js +5 -0
  96. package/src/pdf/core/import-export/json-document.d.ts +47 -0
  97. package/src/pdf/core/import-export/json-document.js +1547 -0
  98. package/src/pdf/core/import-export/xfdf-document.d.ts +146 -0
  99. package/src/pdf/core/import-export/xfdf-document.js +2920 -0
  100. package/src/pdf/core/import-export/xml-document.d.ts +14 -0
  101. package/src/pdf/core/import-export/xml-document.js +166 -0
  102. package/src/pdf/core/import-export/xml-writer.d.ts +69 -0
  103. package/src/pdf/core/import-export/xml-writer.js +494 -0
  104. package/src/pdf/core/pdf-catalog.d.ts +18 -0
  105. package/src/pdf/core/pdf-catalog.js +166 -0
  106. package/src/pdf/core/pdf-cross-reference.d.ts +80 -0
  107. package/src/pdf/core/pdf-cross-reference.js +1049 -0
  108. package/src/pdf/core/pdf-document.d.ts +821 -0
  109. package/src/pdf/core/pdf-document.js +1022 -0
  110. package/src/pdf/core/pdf-file-structure.d.ts +54 -0
  111. package/src/pdf/core/pdf-file-structure.js +65 -0
  112. package/src/pdf/core/pdf-outline.d.ts +362 -0
  113. package/src/pdf/core/pdf-outline.js +860 -0
  114. package/src/pdf/core/pdf-page.d.ts +589 -0
  115. package/src/pdf/core/pdf-page.js +1049 -0
  116. package/src/pdf/core/pdf-parser.d.ts +62 -0
  117. package/src/pdf/core/pdf-parser.js +1035 -0
  118. package/src/pdf/core/pdf-primitives.d.ts +87 -0
  119. package/src/pdf/core/pdf-primitives.js +305 -0
  120. package/src/pdf/core/predictor-stream.d.ts +15 -0
  121. package/src/pdf/core/predictor-stream.js +214 -0
  122. package/src/pdf/core/security/encryptor.d.ts +140 -0
  123. package/src/pdf/core/security/encryptor.js +1616 -0
  124. package/src/pdf/core/security/index.d.ts +1 -0
  125. package/src/pdf/core/security/index.js +1 -0
  126. package/src/pdf/core/utils.d.ts +678 -0
  127. package/src/pdf/core/utils.js +3607 -0
  128. package/src/pdf/index.d.ts +44 -0
  129. package/src/pdf/index.js +44 -0
  130. package/tslint.json +111 -0
  131. package/ReadMe.md +0 -17
  132. package/dist/es6/implementation/actions/action.js +0 -44
  133. package/dist/es6/implementation/actions/index.js +0 -2
  134. package/dist/es6/implementation/actions/uri-action.js +0 -38
  135. package/dist/es6/implementation/annotations/action-link-annotation.js +0 -29
  136. package/dist/es6/implementation/annotations/annotation-collection.js +0 -93
  137. package/dist/es6/implementation/annotations/annotation.js +0 -156
  138. package/dist/es6/implementation/annotations/document-link-annotation.js +0 -48
  139. package/dist/es6/implementation/annotations/index.js +0 -7
  140. package/dist/es6/implementation/annotations/link-annotation.js +0 -31
  141. package/dist/es6/implementation/annotations/pdf-text-web-link.js +0 -178
  142. package/dist/es6/implementation/annotations/uri-annotation.js +0 -64
  143. package/dist/es6/implementation/collections/dictionary.js +0 -71
  144. package/dist/es6/implementation/collections/index.js +0 -3
  145. package/dist/es6/implementation/collections/object-object-pair/dictionary.js +0 -84
  146. package/dist/es6/implementation/collections/object-object-pair/index.js +0 -1
  147. package/dist/es6/implementation/collections/utils.js +0 -8
  148. package/dist/es6/implementation/document/automatic-fields/automatic-field-info-collection.js +0 -17
  149. package/dist/es6/implementation/document/automatic-fields/automatic-field-info.js +0 -68
  150. package/dist/es6/implementation/document/automatic-fields/automatic-field.js +0 -145
  151. package/dist/es6/implementation/document/automatic-fields/composite-field.js +0 -61
  152. package/dist/es6/implementation/document/automatic-fields/index.js +0 -7
  153. package/dist/es6/implementation/document/automatic-fields/multiple-value-field.js +0 -36
  154. package/dist/es6/implementation/document/automatic-fields/page-count-field.js +0 -53
  155. package/dist/es6/implementation/document/automatic-fields/pdf-numbers-convertor.js +0 -91
  156. package/dist/es6/implementation/document/automatic-fields/pdf-page-number-field.js +0 -56
  157. package/dist/es6/implementation/document/automatic-fields/pdf-template-value-pair.js +0 -34
  158. package/dist/es6/implementation/document/automatic-fields/single-value-field.js +0 -47
  159. package/dist/es6/implementation/document/index.js +0 -11
  160. package/dist/es6/implementation/document/pdf-catalog.js +0 -38
  161. package/dist/es6/implementation/document/pdf-document-base.js +0 -71
  162. package/dist/es6/implementation/document/pdf-document-template.js +0 -204
  163. package/dist/es6/implementation/document/pdf-document.js +0 -175
  164. package/dist/es6/implementation/drawing/index.js +0 -1
  165. package/dist/es6/implementation/drawing/pdf-drawing.js +0 -80
  166. package/dist/es6/implementation/general/enum.js +0 -6
  167. package/dist/es6/implementation/general/index.js +0 -3
  168. package/dist/es6/implementation/general/pdf-cache-collection.js +0 -24
  169. package/dist/es6/implementation/general/pdf-collection.js +0 -26
  170. package/dist/es6/implementation/general/pdf-destination.js +0 -107
  171. package/dist/es6/implementation/graphics/brushes/index.js +0 -2
  172. package/dist/es6/implementation/graphics/brushes/pdf-brush.js +0 -6
  173. package/dist/es6/implementation/graphics/brushes/pdf-solid-brush.js +0 -53
  174. package/dist/es6/implementation/graphics/constants.js +0 -11
  175. package/dist/es6/implementation/graphics/enum.js +0 -100
  176. package/dist/es6/implementation/graphics/figures/base/element-layouter.js +0 -154
  177. package/dist/es6/implementation/graphics/figures/base/graphics-element.js +0 -18
  178. package/dist/es6/implementation/graphics/figures/base/index.js +0 -3
  179. package/dist/es6/implementation/graphics/figures/base/pdf-shape-element.js +0 -32
  180. package/dist/es6/implementation/graphics/figures/base/shape-layouter.js +0 -55
  181. package/dist/es6/implementation/graphics/figures/base/text-layouter.js +0 -123
  182. package/dist/es6/implementation/graphics/figures/enum.js +0 -11
  183. package/dist/es6/implementation/graphics/figures/index.js +0 -5
  184. package/dist/es6/implementation/graphics/figures/layout-element.js +0 -41
  185. package/dist/es6/implementation/graphics/figures/pdf-template.js +0 -110
  186. package/dist/es6/implementation/graphics/figures/text-element.js +0 -298
  187. package/dist/es6/implementation/graphics/fonts/enum.js +0 -45
  188. package/dist/es6/implementation/graphics/fonts/pdf-font-metrics.js +0 -122
  189. package/dist/es6/implementation/graphics/fonts/pdf-font.js +0 -159
  190. package/dist/es6/implementation/graphics/fonts/pdf-standard-font-metrics-factory.js +0 -357
  191. package/dist/es6/implementation/graphics/fonts/pdf-standard-font.js +0 -124
  192. package/dist/es6/implementation/graphics/fonts/pdf-string-format.js +0 -239
  193. package/dist/es6/implementation/graphics/fonts/string-layouter.js +0 -335
  194. package/dist/es6/implementation/graphics/fonts/string-tokenizer.js +0 -162
  195. package/dist/es6/implementation/graphics/images/byte-array.js +0 -82
  196. package/dist/es6/implementation/graphics/images/image-decoder.js +0 -167
  197. package/dist/es6/implementation/graphics/images/pdf-bitmap.js +0 -41
  198. package/dist/es6/implementation/graphics/images/pdf-image.js +0 -68
  199. package/dist/es6/implementation/graphics/index.js +0 -20
  200. package/dist/es6/implementation/graphics/pdf-color.js +0 -205
  201. package/dist/es6/implementation/graphics/pdf-graphics.js +0 -1034
  202. package/dist/es6/implementation/graphics/pdf-margins.js +0 -75
  203. package/dist/es6/implementation/graphics/pdf-pen.js +0 -180
  204. package/dist/es6/implementation/graphics/pdf-resources.js +0 -223
  205. package/dist/es6/implementation/graphics/pdf-transformation-matrix.js +0 -134
  206. package/dist/es6/implementation/graphics/pdf-transparency.js +0 -22
  207. package/dist/es6/implementation/graphics/unit-convertor.js +0 -33
  208. package/dist/es6/implementation/index.js +0 -85
  209. package/dist/es6/implementation/input-output/cross-table.js +0 -6
  210. package/dist/es6/implementation/input-output/enum.js +0 -5
  211. package/dist/es6/implementation/input-output/index.js +0 -8
  212. package/dist/es6/implementation/input-output/pdf-cross-table.js +0 -346
  213. package/dist/es6/implementation/input-output/pdf-dictionary-properties.js +0 -60
  214. package/dist/es6/implementation/input-output/pdf-main-object-collection.js +0 -115
  215. package/dist/es6/implementation/input-output/pdf-operators.js +0 -75
  216. package/dist/es6/implementation/input-output/pdf-stream-writer.js +0 -364
  217. package/dist/es6/implementation/input-output/pdf-writer.js +0 -44
  218. package/dist/es6/implementation/pages/enum.js +0 -51
  219. package/dist/es6/implementation/pages/index.js +0 -13
  220. package/dist/es6/implementation/pages/page-added-event-arguments.js +0 -19
  221. package/dist/es6/implementation/pages/pdf-document-page-collection.js +0 -120
  222. package/dist/es6/implementation/pages/pdf-page-base.js +0 -104
  223. package/dist/es6/implementation/pages/pdf-page-layer-collection.js +0 -115
  224. package/dist/es6/implementation/pages/pdf-page-layer.js +0 -160
  225. package/dist/es6/implementation/pages/pdf-page-settings.js +0 -126
  226. package/dist/es6/implementation/pages/pdf-page-size.js +0 -36
  227. package/dist/es6/implementation/pages/pdf-page-template-element.js +0 -510
  228. package/dist/es6/implementation/pages/pdf-page.js +0 -130
  229. package/dist/es6/implementation/pages/pdf-section-collection.js +0 -95
  230. package/dist/es6/implementation/pages/pdf-section-page-collection.js +0 -30
  231. package/dist/es6/implementation/pages/pdf-section-templates.js +0 -71
  232. package/dist/es6/implementation/pages/pdf-section.js +0 -388
  233. package/dist/es6/implementation/primitives/index.js +0 -8
  234. package/dist/es6/implementation/primitives/pdf-array.js +0 -199
  235. package/dist/es6/implementation/primitives/pdf-boolean.js +0 -66
  236. package/dist/es6/implementation/primitives/pdf-dictionary.js +0 -220
  237. package/dist/es6/implementation/primitives/pdf-name.js +0 -102
  238. package/dist/es6/implementation/primitives/pdf-number.js +0 -94
  239. package/dist/es6/implementation/primitives/pdf-reference.js +0 -195
  240. package/dist/es6/implementation/primitives/pdf-stream.js +0 -149
  241. package/dist/es6/implementation/primitives/pdf-string.js +0 -143
  242. package/dist/es6/implementation/structured-elements/grid/index.js +0 -1
  243. package/dist/es6/implementation/structured-elements/grid/pdf-grid-cell.js +0 -512
  244. package/dist/es6/implementation/structured-elements/grid/pdf-grid-column.js +0 -125
  245. package/dist/es6/implementation/structured-elements/grid/pdf-grid-row.js +0 -244
  246. package/dist/es6/implementation/structured-elements/grid/pdf-grid.js +0 -989
  247. package/dist/es6/implementation/structured-elements/grid/styles/index.js +0 -2
  248. package/dist/es6/implementation/structured-elements/grid/styles/pdf-borders.js +0 -145
  249. package/dist/es6/implementation/structured-elements/grid/styles/style.js +0 -267
  250. package/dist/es6/implementation/structured-elements/index.js +0 -1
  251. package/dist/es6/implementation/structured-elements/tables/light-tables/enum.js +0 -5
  252. package/dist/es6/index.js +0 -89
  253. package/dist/es6/interfaces/i-pdf-cache.js +0 -1
  254. package/dist/es6/interfaces/i-pdf-changable.js +0 -1
  255. package/dist/es6/interfaces/i-pdf-primitives.js +0 -1
  256. package/dist/es6/interfaces/i-pdf-wrapper.js +0 -1
  257. package/dist/es6/interfaces/i-pdf-writer.js +0 -1
  258. package/dist/es6/interfaces/index.js +0 -1
  259. package/dist//global//ej2-pdf.js +0 -15979
  260. package/implementation.d.ts +0 -4
  261. package/implementation.js +0 -8
  262. package/interfaces.d.ts +0 -4
  263. package/interfaces.js +0 -4
  264. package/src/implementation/actions/action.d.ts +0 -50
  265. package/src/implementation/actions/action.js +0 -44
  266. package/src/implementation/actions/index.d.ts +0 -6
  267. package/src/implementation/actions/index.js +0 -9
  268. package/src/implementation/actions/uri-action.d.ts +0 -33
  269. package/src/implementation/actions/uri-action.js +0 -39
  270. package/src/implementation/annotations/action-link-annotation.d.ts +0 -30
  271. package/src/implementation/annotations/action-link-annotation.js +0 -32
  272. package/src/implementation/annotations/annotation-collection.d.ts +0 -77
  273. package/src/implementation/annotations/annotation-collection.js +0 -91
  274. package/src/implementation/annotations/annotation.d.ts +0 -152
  275. package/src/implementation/annotations/annotation.js +0 -146
  276. package/src/implementation/annotations/document-link-annotation.d.ts +0 -89
  277. package/src/implementation/annotations/document-link-annotation.js +0 -51
  278. package/src/implementation/annotations/index.d.ts +0 -11
  279. package/src/implementation/annotations/index.js +0 -14
  280. package/src/implementation/annotations/link-annotation.d.ts +0 -23
  281. package/src/implementation/annotations/link-annotation.js +0 -33
  282. package/src/implementation/annotations/pdf-text-web-link.d.ts +0 -118
  283. package/src/implementation/annotations/pdf-text-web-link.js +0 -173
  284. package/src/implementation/annotations/uri-annotation.d.ts +0 -48
  285. package/src/implementation/annotations/uri-annotation.js +0 -65
  286. package/src/implementation/collections/dictionary.d.ts +0 -76
  287. package/src/implementation/collections/dictionary.js +0 -74
  288. package/src/implementation/collections/index.d.ts +0 -7
  289. package/src/implementation/collections/index.js +0 -10
  290. package/src/implementation/collections/object-object-pair/dictionary.d.ts +0 -62
  291. package/src/implementation/collections/object-object-pair/dictionary.js +0 -88
  292. package/src/implementation/collections/object-object-pair/index.d.ts +0 -5
  293. package/src/implementation/collections/object-object-pair/index.js +0 -8
  294. package/src/implementation/collections/utils.d.ts +0 -27
  295. package/src/implementation/collections/utils.js +0 -13
  296. package/src/implementation/document/automatic-fields/automatic-field-info-collection.d.ts +0 -31
  297. package/src/implementation/document/automatic-fields/automatic-field-info-collection.js +0 -21
  298. package/src/implementation/document/automatic-fields/automatic-field-info.d.ts +0 -67
  299. package/src/implementation/document/automatic-fields/automatic-field-info.js +0 -70
  300. package/src/implementation/document/automatic-fields/automatic-field.d.ts +0 -41
  301. package/src/implementation/document/automatic-fields/automatic-field.js +0 -143
  302. package/src/implementation/document/automatic-fields/composite-field.d.ts +0 -46
  303. package/src/implementation/document/automatic-fields/composite-field.js +0 -64
  304. package/src/implementation/document/automatic-fields/index.d.ts +0 -11
  305. package/src/implementation/document/automatic-fields/index.js +0 -14
  306. package/src/implementation/document/automatic-fields/multiple-value-field.d.ts +0 -18
  307. package/src/implementation/document/automatic-fields/multiple-value-field.js +0 -35
  308. package/src/implementation/document/automatic-fields/page-count-field.d.ts +0 -44
  309. package/src/implementation/document/automatic-fields/page-count-field.js +0 -53
  310. package/src/implementation/document/automatic-fields/pdf-numbers-convertor.d.ts +0 -53
  311. package/src/implementation/document/automatic-fields/pdf-numbers-convertor.js +0 -94
  312. package/src/implementation/document/automatic-fields/pdf-page-number-field.d.ts +0 -51
  313. package/src/implementation/document/automatic-fields/pdf-page-number-field.js +0 -56
  314. package/src/implementation/document/automatic-fields/pdf-template-value-pair.d.ts +0 -38
  315. package/src/implementation/document/automatic-fields/pdf-template-value-pair.js +0 -38
  316. package/src/implementation/document/automatic-fields/single-value-field.d.ts +0 -15
  317. package/src/implementation/document/automatic-fields/single-value-field.js +0 -46
  318. package/src/implementation/document/index.d.ts +0 -15
  319. package/src/implementation/document/index.js +0 -18
  320. package/src/implementation/document/pdf-catalog.d.ts +0 -32
  321. package/src/implementation/document/pdf-catalog.js +0 -38
  322. package/src/implementation/document/pdf-document-base.d.ts +0 -117
  323. package/src/implementation/document/pdf-document-base.js +0 -72
  324. package/src/implementation/document/pdf-document-template.d.ts +0 -166
  325. package/src/implementation/document/pdf-document-template.js +0 -207
  326. package/src/implementation/document/pdf-document.d.ts +0 -206
  327. package/src/implementation/document/pdf-document.js +0 -166
  328. package/src/implementation/drawing/index.d.ts +0 -5
  329. package/src/implementation/drawing/index.js +0 -8
  330. package/src/implementation/drawing/pdf-drawing.d.ts +0 -93
  331. package/src/implementation/drawing/pdf-drawing.js +0 -84
  332. package/src/implementation/general/enum.d.ts +0 -21
  333. package/src/implementation/general/enum.js +0 -10
  334. package/src/implementation/general/index.d.ts +0 -7
  335. package/src/implementation/general/index.js +0 -10
  336. package/src/implementation/general/pdf-cache-collection.d.ts +0 -33
  337. package/src/implementation/general/pdf-cache-collection.js +0 -27
  338. package/src/implementation/general/pdf-collection.d.ts +0 -26
  339. package/src/implementation/general/pdf-collection.js +0 -30
  340. package/src/implementation/general/pdf-destination.d.ts +0 -103
  341. package/src/implementation/general/pdf-destination.js +0 -103
  342. package/src/implementation/graphics/brushes/index.d.ts +0 -6
  343. package/src/implementation/graphics/brushes/index.js +0 -9
  344. package/src/implementation/graphics/brushes/pdf-brush.d.ts +0 -55
  345. package/src/implementation/graphics/brushes/pdf-brush.js +0 -10
  346. package/src/implementation/graphics/brushes/pdf-solid-brush.d.ts +0 -77
  347. package/src/implementation/graphics/brushes/pdf-solid-brush.js +0 -54
  348. package/src/implementation/graphics/constants.d.ts +0 -31
  349. package/src/implementation/graphics/constants.js +0 -15
  350. package/src/implementation/graphics/enum.d.ts +0 -392
  351. package/src/implementation/graphics/enum.js +0 -104
  352. package/src/implementation/graphics/figures/base/element-layouter.d.ts +0 -160
  353. package/src/implementation/graphics/figures/base/element-layouter.js +0 -156
  354. package/src/implementation/graphics/figures/base/graphics-element.d.ts +0 -16
  355. package/src/implementation/graphics/figures/base/graphics-element.js +0 -22
  356. package/src/implementation/graphics/figures/base/index.d.ts +0 -7
  357. package/src/implementation/graphics/figures/base/index.js +0 -10
  358. package/src/implementation/graphics/figures/base/pdf-shape-element.d.ts +0 -28
  359. package/src/implementation/graphics/figures/base/pdf-shape-element.js +0 -34
  360. package/src/implementation/graphics/figures/base/shape-layouter.d.ts +0 -80
  361. package/src/implementation/graphics/figures/base/shape-layouter.js +0 -57
  362. package/src/implementation/graphics/figures/base/text-layouter.d.ts +0 -107
  363. package/src/implementation/graphics/figures/base/text-layouter.js +0 -121
  364. package/src/implementation/graphics/figures/enum.d.ts +0 -37
  365. package/src/implementation/graphics/figures/enum.js +0 -15
  366. package/src/implementation/graphics/figures/index.d.ts +0 -9
  367. package/src/implementation/graphics/figures/index.js +0 -12
  368. package/src/implementation/graphics/figures/layout-element.d.ts +0 -57
  369. package/src/implementation/graphics/figures/layout-element.js +0 -43
  370. package/src/implementation/graphics/figures/pdf-template.d.ts +0 -113
  371. package/src/implementation/graphics/figures/pdf-template.js +0 -106
  372. package/src/implementation/graphics/figures/text-element.d.ts +0 -213
  373. package/src/implementation/graphics/figures/text-element.js +0 -289
  374. package/src/implementation/graphics/fonts/enum.d.ts +0 -179
  375. package/src/implementation/graphics/fonts/enum.js +0 -49
  376. package/src/implementation/graphics/fonts/index.d.ts +0 -12
  377. package/src/implementation/graphics/fonts/index.js +0 -15
  378. package/src/implementation/graphics/fonts/pdf-font-metrics.d.ts +0 -160
  379. package/src/implementation/graphics/fonts/pdf-font-metrics.js +0 -123
  380. package/src/implementation/graphics/fonts/pdf-font.d.ts +0 -187
  381. package/src/implementation/graphics/fonts/pdf-font.js +0 -158
  382. package/src/implementation/graphics/fonts/pdf-standard-font-metrics-factory.d.ts +0 -301
  383. package/src/implementation/graphics/fonts/pdf-standard-font-metrics-factory.js +0 -359
  384. package/src/implementation/graphics/fonts/pdf-standard-font.d.ts +0 -143
  385. package/src/implementation/graphics/fonts/pdf-standard-font.js +0 -121
  386. package/src/implementation/graphics/fonts/pdf-string-format.d.ts +0 -319
  387. package/src/implementation/graphics/fonts/pdf-string-format.js +0 -241
  388. package/src/implementation/graphics/fonts/string-layouter.d.ts +0 -255
  389. package/src/implementation/graphics/fonts/string-layouter.js +0 -336
  390. package/src/implementation/graphics/fonts/string-tokenizer.d.ts +0 -107
  391. package/src/implementation/graphics/fonts/string-tokenizer.js +0 -166
  392. package/src/implementation/graphics/images/byte-array.d.ts +0 -68
  393. package/src/implementation/graphics/images/byte-array.js +0 -86
  394. package/src/implementation/graphics/images/image-decoder.d.ts +0 -227
  395. package/src/implementation/graphics/images/image-decoder.js +0 -164
  396. package/src/implementation/graphics/images/index.js +0 -11
  397. package/src/implementation/graphics/images/pdf-bitmap.d.ts +0 -90
  398. package/src/implementation/graphics/images/pdf-bitmap.js +0 -41
  399. package/src/implementation/graphics/images/pdf-image.d.ts +0 -88
  400. package/src/implementation/graphics/images/pdf-image.js +0 -69
  401. package/src/implementation/graphics/index.d.ts +0 -24
  402. package/src/implementation/graphics/index.js +0 -27
  403. package/src/implementation/graphics/pdf-color.d.ts +0 -170
  404. package/src/implementation/graphics/pdf-color.js +0 -204
  405. package/src/implementation/graphics/pdf-graphics.d.ts +0 -1085
  406. package/src/implementation/graphics/pdf-graphics.js +0 -1017
  407. package/src/implementation/graphics/pdf-margins.d.ts +0 -82
  408. package/src/implementation/graphics/pdf-margins.js +0 -79
  409. package/src/implementation/graphics/pdf-pen.d.ts +0 -237
  410. package/src/implementation/graphics/pdf-pen.js +0 -181
  411. package/src/implementation/graphics/pdf-resources.d.ts +0 -147
  412. package/src/implementation/graphics/pdf-resources.js +0 -215
  413. package/src/implementation/graphics/pdf-transformation-matrix.d.ts +0 -143
  414. package/src/implementation/graphics/pdf-transformation-matrix.js +0 -136
  415. package/src/implementation/graphics/pdf-transparency.d.ts +0 -34
  416. package/src/implementation/graphics/pdf-transparency.js +0 -22
  417. package/src/implementation/graphics/unit-convertor.d.ts +0 -72
  418. package/src/implementation/graphics/unit-convertor.js +0 -37
  419. package/src/implementation/index.d.ts +0 -89
  420. package/src/implementation/index.js +0 -92
  421. package/src/implementation/input-output/cross-table.d.ts +0 -21
  422. package/src/implementation/input-output/cross-table.js +0 -10
  423. package/src/implementation/input-output/enum.d.ts +0 -16
  424. package/src/implementation/input-output/enum.js +0 -9
  425. package/src/implementation/input-output/index.d.ts +0 -12
  426. package/src/implementation/input-output/index.js +0 -15
  427. package/src/implementation/input-output/pdf-cross-table.d.ts +0 -249
  428. package/src/implementation/input-output/pdf-cross-table.js +0 -340
  429. package/src/implementation/input-output/pdf-dictionary-properties.d.ts +0 -283
  430. package/src/implementation/input-output/pdf-dictionary-properties.js +0 -64
  431. package/src/implementation/input-output/pdf-main-object-collection.d.ts +0 -120
  432. package/src/implementation/input-output/pdf-main-object-collection.js +0 -117
  433. package/src/implementation/input-output/pdf-operators.d.ts +0 -352
  434. package/src/implementation/input-output/pdf-operators.js +0 -79
  435. package/src/implementation/input-output/pdf-stream-writer.d.ts +0 -314
  436. package/src/implementation/input-output/pdf-stream-writer.js +0 -363
  437. package/src/implementation/input-output/pdf-writer.d.ts +0 -68
  438. package/src/implementation/input-output/pdf-writer.js +0 -48
  439. package/src/implementation/pages/enum.d.ts +0 -201
  440. package/src/implementation/pages/enum.js +0 -55
  441. package/src/implementation/pages/index.d.ts +0 -17
  442. package/src/implementation/pages/index.js +0 -20
  443. package/src/implementation/pages/page-added-event-arguments.d.ts +0 -30
  444. package/src/implementation/pages/page-added-event-arguments.js +0 -23
  445. package/src/implementation/pages/pdf-document-page-collection.d.ts +0 -92
  446. package/src/implementation/pages/pdf-document-page-collection.js +0 -121
  447. package/src/implementation/pages/pdf-page-base.d.ts +0 -121
  448. package/src/implementation/pages/pdf-page-base.js +0 -104
  449. package/src/implementation/pages/pdf-page-layer-collection.d.ts +0 -99
  450. package/src/implementation/pages/pdf-page-layer-collection.js +0 -113
  451. package/src/implementation/pages/pdf-page-layer.d.ts +0 -160
  452. package/src/implementation/pages/pdf-page-layer.js +0 -159
  453. package/src/implementation/pages/pdf-page-settings.d.ts +0 -111
  454. package/src/implementation/pages/pdf-page-settings.js +0 -126
  455. package/src/implementation/pages/pdf-page-size.d.ts +0 -159
  456. package/src/implementation/pages/pdf-page-size.js +0 -39
  457. package/src/implementation/pages/pdf-page-template-element.d.ts +0 -230
  458. package/src/implementation/pages/pdf-page-template-element.js +0 -509
  459. package/src/implementation/pages/pdf-page.d.ts +0 -153
  460. package/src/implementation/pages/pdf-page.js +0 -127
  461. package/src/implementation/pages/pdf-section-collection.d.ts +0 -109
  462. package/src/implementation/pages/pdf-section-collection.js +0 -91
  463. package/src/implementation/pages/pdf-section-page-collection.d.ts +0 -41
  464. package/src/implementation/pages/pdf-section-page-collection.js +0 -34
  465. package/src/implementation/pages/pdf-section-templates.d.ts +0 -64
  466. package/src/implementation/pages/pdf-section-templates.js +0 -74
  467. package/src/implementation/pages/pdf-section.d.ts +0 -319
  468. package/src/implementation/pages/pdf-section.js +0 -379
  469. package/src/implementation/primitives/index.d.ts +0 -12
  470. package/src/implementation/primitives/index.js +0 -15
  471. package/src/implementation/primitives/pdf-array.d.ts +0 -186
  472. package/src/implementation/primitives/pdf-array.js +0 -201
  473. package/src/implementation/primitives/pdf-boolean.d.ts +0 -84
  474. package/src/implementation/primitives/pdf-boolean.js +0 -70
  475. package/src/implementation/primitives/pdf-dictionary.d.ts +0 -311
  476. package/src/implementation/primitives/pdf-dictionary.js +0 -220
  477. package/src/implementation/primitives/pdf-name.d.ts +0 -121
  478. package/src/implementation/primitives/pdf-name.js +0 -106
  479. package/src/implementation/primitives/pdf-number.d.ts +0 -104
  480. package/src/implementation/primitives/pdf-number.js +0 -98
  481. package/src/implementation/primitives/pdf-reference.d.ts +0 -222
  482. package/src/implementation/primitives/pdf-reference.js +0 -192
  483. package/src/implementation/primitives/pdf-stream.d.ts +0 -111
  484. package/src/implementation/primitives/pdf-stream.js +0 -146
  485. package/src/implementation/primitives/pdf-string.d.ts +0 -212
  486. package/src/implementation/primitives/pdf-string.js +0 -147
  487. package/src/implementation/structured-elements/grid/index.d.ts +0 -0
  488. package/src/implementation/structured-elements/grid/index.js +0 -1
  489. package/src/implementation/structured-elements/grid/pdf-grid-cell.d.ts +0 -248
  490. package/src/implementation/structured-elements/grid/pdf-grid-cell.js +0 -504
  491. package/src/implementation/structured-elements/grid/pdf-grid-column.d.ts +0 -108
  492. package/src/implementation/structured-elements/grid/pdf-grid-column.js +0 -127
  493. package/src/implementation/structured-elements/grid/pdf-grid-row.d.ts +0 -207
  494. package/src/implementation/structured-elements/grid/pdf-grid-row.js +0 -246
  495. package/src/implementation/structured-elements/grid/pdf-grid.d.ts +0 -678
  496. package/src/implementation/structured-elements/grid/pdf-grid.js +0 -982
  497. package/src/implementation/structured-elements/grid/styles/index.d.ts +0 -5
  498. package/src/implementation/structured-elements/grid/styles/index.js +0 -9
  499. package/src/implementation/structured-elements/grid/styles/pdf-borders.d.ts +0 -126
  500. package/src/implementation/structured-elements/grid/styles/pdf-borders.js +0 -146
  501. package/src/implementation/structured-elements/grid/styles/style.d.ts +0 -250
  502. package/src/implementation/structured-elements/grid/styles/style.js +0 -269
  503. package/src/implementation/structured-elements/index.d.ts +0 -0
  504. package/src/implementation/structured-elements/index.js +0 -1
  505. package/src/implementation/structured-elements/tables/light-tables/enum.d.ts +0 -16
  506. package/src/implementation/structured-elements/tables/light-tables/enum.js +0 -9
  507. package/src/interfaces/i-pdf-cache.d.ts +0 -23
  508. package/src/interfaces/i-pdf-cache.js +0 -4
  509. package/src/interfaces/i-pdf-changable.d.ts +0 -17
  510. package/src/interfaces/i-pdf-changable.js +0 -4
  511. package/src/interfaces/i-pdf-primitives.d.ts +0 -45
  512. package/src/interfaces/i-pdf-primitives.js +0 -4
  513. package/src/interfaces/i-pdf-wrapper.d.ts +0 -13
  514. package/src/interfaces/i-pdf-wrapper.js +0 -4
  515. package/src/interfaces/i-pdf-writer.d.ts +0 -29
  516. package/src/interfaces/i-pdf-writer.js +0 -4
  517. package/src/interfaces/index.d.ts +0 -9
  518. package/src/interfaces/index.js +0 -4
@@ -0,0 +1,1049 @@
1
+ import { _PdfStream } from './base-stream';
2
+ import { _PdfDictionary, _PdfReferenceSet, _isCommand, _PdfReference, _PdfName } from './pdf-primitives';
3
+ import { BaseException, FormatError, _escapePdfName, _bytesToString, ParserEndOfFileException, _numberToString, _stringToPdfString } from './utils';
4
+ import { _PdfParser, _PdfLexicalOperator } from './pdf-parser';
5
+ import { _PdfBaseStream } from './base-stream';
6
+ import { PdfCrossReferenceType } from './enumerator';
7
+ import { _MD5, _PdfEncryptor } from './security/encryptor';
8
+ import { CompressedStreamWriter } from '@syncfusion/ej2-compression';
9
+ var _PdfCrossReference = /** @class */ (function () {
10
+ function _PdfCrossReference(document, password) {
11
+ this._version = '';
12
+ this._newLine = '\r\n';
13
+ this._password = password;
14
+ this._document = document;
15
+ this._stream = document._stream;
16
+ this._entries = [];
17
+ this._crossReferencePosition = Object.create(null);
18
+ this._cacheMap = new Map(); // eslint-disable-line
19
+ this._pendingRefs = new _PdfReferenceSet();
20
+ }
21
+ _PdfCrossReference.prototype._setStartXRef = function (startXRef) {
22
+ this._startXRefQueue = [startXRef];
23
+ this._prevStartXref = startXRef;
24
+ };
25
+ _PdfCrossReference.prototype._parse = function (recoveryMode) {
26
+ var trailerDictionary;
27
+ if (!recoveryMode) {
28
+ trailerDictionary = this._readXRef();
29
+ }
30
+ else {
31
+ trailerDictionary = this._indexObjects();
32
+ }
33
+ trailerDictionary.assignXref(this);
34
+ this._nextReferenceNumber = trailerDictionary.get('Size');
35
+ this._trailer = trailerDictionary;
36
+ var encrypt = trailerDictionary.get('Encrypt');
37
+ if (encrypt) {
38
+ this._document._isEncrypted = true;
39
+ this._ids = trailerDictionary.get('ID');
40
+ this._permissionFlags = encrypt.get('P');
41
+ var fileId = this._ids && this._ids.length ? this._ids[0] : '';
42
+ encrypt.suppressEncryption = true;
43
+ this._encrypt = new _PdfEncryptor(encrypt, fileId, this._password);
44
+ this._document._fileStructure._crossReferenceType = PdfCrossReferenceType.stream;
45
+ this._document._isUserPassword = this._encrypt._isUserPassword;
46
+ this._document._encryptOnlyAttachment = this._encrypt._encryptOnlyAttachment;
47
+ if (this._encrypt._encryptOnlyAttachment) {
48
+ this._document._hasUserPasswordOnly = true;
49
+ this._document._encryptMetaData = false;
50
+ }
51
+ else {
52
+ this._document._hasUserPasswordOnly = this._encrypt._hasUserPasswordOnly;
53
+ this._document._encryptMetaData = encrypt.has('EncryptMetadata') ? encrypt.get('EncryptMetadata') : true;
54
+ }
55
+ }
56
+ var hasRoot = false;
57
+ try {
58
+ var root = trailerDictionary.get('Root');
59
+ if (root) {
60
+ var pagesEntry = root.get('Pages');
61
+ if (pagesEntry) {
62
+ this._root = root;
63
+ hasRoot = true;
64
+ }
65
+ }
66
+ }
67
+ catch (ex) {
68
+ throw new BaseException('Invalid cross reference', 'InvalidXRef');
69
+ }
70
+ if (!hasRoot) {
71
+ if (!recoveryMode) {
72
+ throw new BaseException('Invalid cross reference', 'XRefParseException');
73
+ }
74
+ else {
75
+ throw new BaseException('Invalid cross reference', 'InvalidXRef');
76
+ }
77
+ }
78
+ };
79
+ _PdfCrossReference.prototype._getEntry = function (i) {
80
+ var xrefEntry = this._entries[i]; // eslint-disable-line
81
+ if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
82
+ return xrefEntry;
83
+ }
84
+ return null;
85
+ };
86
+ _PdfCrossReference.prototype._fetch = function (ref, suppressEncryption) {
87
+ var entry; // eslint-disable-line
88
+ if (!(ref instanceof _PdfReference)) {
89
+ throw new Error('ref object is not a reference');
90
+ }
91
+ var objectNumber = ref.objectNumber;
92
+ var cacheEntry = this._cacheMap.get(ref); // eslint-disable-line
93
+ if (typeof cacheEntry !== 'undefined') {
94
+ if (cacheEntry instanceof _PdfDictionary && !cacheEntry.objId) {
95
+ cacheEntry.objId = objectNumber;
96
+ }
97
+ return cacheEntry;
98
+ }
99
+ var xrefEntry = this._getEntry(objectNumber);
100
+ if (xrefEntry === null) {
101
+ this._cacheMap.set(ref, xrefEntry);
102
+ return xrefEntry;
103
+ }
104
+ if (this._pendingRefs.has(ref)) {
105
+ this._pendingRefs.remove(ref);
106
+ throw new Error('circular reference');
107
+ }
108
+ this._pendingRefs.put(ref);
109
+ try {
110
+ if (xrefEntry.uncompressed) {
111
+ entry = this._fetchUncompressed(ref, xrefEntry, suppressEncryption);
112
+ }
113
+ else {
114
+ entry = this._fetchCompressed(ref, xrefEntry);
115
+ }
116
+ this._pendingRefs.remove(ref);
117
+ }
118
+ catch (ex) {
119
+ this._pendingRefs.remove(ref);
120
+ throw ex;
121
+ }
122
+ return entry;
123
+ };
124
+ _PdfCrossReference.prototype._fetchUncompressed = function (reference, xrefEntry, suppressEncryption) {
125
+ var generationNumber = reference.generationNumber;
126
+ var objectNumber = reference.objectNumber;
127
+ if (xrefEntry.gen !== generationNumber) {
128
+ throw new BaseException("Inconsistent generation in XRef: " + reference, 'XRefEntryException');
129
+ }
130
+ var stream = this._stream.makeSubStream(xrefEntry.offset + this._stream.start, undefined);
131
+ var parser = new _PdfParser(new _PdfLexicalOperator(stream), this, true);
132
+ var obj1 = parser.getObject();
133
+ var obj2 = parser.getObject();
134
+ var obj3 = parser.getObject();
135
+ if (obj1 !== objectNumber || obj2 !== generationNumber || typeof obj3 === 'undefined') {
136
+ throw new BaseException("Bad (uncompressed) XRef entry: " + reference, 'XRefEntryException');
137
+ }
138
+ var entry; // eslint-disable-line
139
+ if (this._encrypt && !suppressEncryption) {
140
+ entry = parser.getObject(this._encrypt._createCipherTransform(reference.objectNumber, reference.generationNumber));
141
+ }
142
+ else {
143
+ entry = parser.getObject();
144
+ }
145
+ if (!(entry instanceof _PdfBaseStream)) {
146
+ this._cacheMap.set(reference, entry);
147
+ }
148
+ if (entry instanceof _PdfDictionary) {
149
+ entry.objId = reference.toString();
150
+ }
151
+ else if (entry instanceof _PdfBaseStream) {
152
+ entry.dictionary.objId = reference.toString();
153
+ }
154
+ return entry;
155
+ };
156
+ _PdfCrossReference.prototype._fetchCompressed = function (ref, xrefEntry) {
157
+ var tableOffset = xrefEntry.offset;
158
+ var stream = this._fetch(_PdfReference.get(tableOffset, 0));
159
+ if (typeof stream === 'undefined') {
160
+ throw new FormatError('bad ObjStm stream');
161
+ }
162
+ var first = stream.dictionary.get('First');
163
+ var n = stream.dictionary.get('N');
164
+ var gen = ref.generationNumber;
165
+ if (!Number.isInteger(first) || !Number.isInteger(n)) {
166
+ throw new FormatError('invalid first and n parameters for ObjStm stream');
167
+ }
168
+ var parser = new _PdfParser(new _PdfLexicalOperator(stream), this, true);
169
+ var nums = new Array(n);
170
+ var offsets = new Array(n);
171
+ for (var i = 0; i < n; ++i) {
172
+ var value = parser.getObject();
173
+ if (!Number.isInteger(value)) {
174
+ throw new FormatError("invalid object number in the ObjStm stream: " + value);
175
+ }
176
+ var offset = parser.getObject();
177
+ if (!Number.isInteger(offset)) {
178
+ throw new FormatError("invalid object offset in the ObjStm stream: " + offset);
179
+ }
180
+ nums[i] = value; // eslint-disable-line
181
+ offsets[i] = offset; // eslint-disable-line
182
+ }
183
+ var start = (stream.start || 0) + first;
184
+ var entries = new Array(n); // eslint-disable-line
185
+ for (var i = 0; i < n; ++i) {
186
+ var length_1 = (i < n - 1 ? (offsets[i + 1] - offsets[i]) : undefined); // eslint-disable-line
187
+ if (length_1 < 0) {
188
+ throw new FormatError('Invalid offset in the ObjStm stream.');
189
+ }
190
+ parser = new _PdfParser(new _PdfLexicalOperator(stream.makeSubStream(start + offsets[i], length_1, stream.dictionary)), this, true); // eslint-disable-line
191
+ var obj = parser.getObject(); // eslint-disable-line
192
+ entries[i] = obj; // eslint-disable-line
193
+ if (obj instanceof _PdfBaseStream) {
194
+ continue;
195
+ }
196
+ var value = nums[i]; // eslint-disable-line
197
+ var entry = this._entries[value]; // eslint-disable-line
198
+ if (entry && entry.offset === tableOffset && entry.gen === i) {
199
+ var objId = value + " " + gen;
200
+ this._cacheMap.set(_PdfReference.get(value, gen), obj);
201
+ if (obj instanceof _PdfDictionary) {
202
+ obj.objId = objId;
203
+ }
204
+ }
205
+ }
206
+ var result = entries[xrefEntry.gen]; // eslint-disable-line
207
+ if (typeof result === 'undefined') {
208
+ throw new BaseException("Bad (compressed) XRef entry: " + ref, 'XRefEntryException');
209
+ }
210
+ return result;
211
+ };
212
+ _PdfCrossReference.prototype._readXRef = function (recoveryMode) {
213
+ if (recoveryMode === void 0) { recoveryMode = false; }
214
+ var stream = this._stream;
215
+ var startXRefParsedCache = new Set();
216
+ try {
217
+ while (this._startXRefQueue.length) {
218
+ var startXRef = this._startXRefQueue[0];
219
+ if (this._prevStartXref < startXRef) {
220
+ this._prevStartXref = startXRef;
221
+ }
222
+ if (startXRefParsedCache.has(startXRef)) {
223
+ this._startXRefQueue.shift();
224
+ continue;
225
+ }
226
+ startXRefParsedCache.add(startXRef);
227
+ stream.position = startXRef + stream.start;
228
+ var parser = new _PdfParser(new _PdfLexicalOperator(stream), this, true);
229
+ var obj = parser.getObject(); // eslint-disable-line
230
+ var dictionary = void 0;
231
+ if (_isCommand(obj, 'xref')) {
232
+ if (typeof this._document._fileStructure._crossReferenceType === 'undefined') {
233
+ this._document._fileStructure._crossReferenceType = PdfCrossReferenceType.table;
234
+ }
235
+ dictionary = this._processXRefTable(parser);
236
+ if (!this._topDictionary) {
237
+ this._topDictionary = dictionary;
238
+ }
239
+ obj = dictionary.get('XRefStm');
240
+ if (Number.isInteger(obj)) {
241
+ var position = obj; // eslint-disable-line
242
+ if (!(position in this._crossReferencePosition)) {
243
+ this._crossReferencePosition[position] = 1; // eslint-disable-line
244
+ this._startXRefQueue.push(position);
245
+ }
246
+ }
247
+ }
248
+ else if (Number.isInteger(obj)) {
249
+ if (typeof this._document._fileStructure._crossReferenceType === 'undefined') {
250
+ this._document._fileStructure._crossReferenceType = PdfCrossReferenceType.stream;
251
+ }
252
+ var gen = parser.getObject();
253
+ var command = parser.getObject();
254
+ obj = parser.getObject();
255
+ if (typeof gen === 'undefined' ||
256
+ !Number.isInteger(gen) ||
257
+ !_isCommand(command, 'obj') ||
258
+ !(obj instanceof _PdfBaseStream)) {
259
+ throw new FormatError('Invalid cross reference stream');
260
+ }
261
+ dictionary = this._processXRefStream(obj);
262
+ if (!this._topDictionary) {
263
+ this._topDictionary = dictionary;
264
+ }
265
+ if (!dictionary) {
266
+ throw new FormatError('Failed to read XRef stream');
267
+ }
268
+ }
269
+ else {
270
+ throw new FormatError('Invalid XRef stream header');
271
+ }
272
+ obj = dictionary.get('Prev');
273
+ if (Number.isInteger(obj)) {
274
+ this._startXRefQueue.push(obj);
275
+ }
276
+ else if (obj instanceof _PdfReference) {
277
+ this._startXRefQueue.push(obj.objectNumber);
278
+ }
279
+ this._startXRefQueue.shift();
280
+ }
281
+ return this._topDictionary;
282
+ }
283
+ catch (e) {
284
+ this._startXRefQueue.shift();
285
+ }
286
+ if (recoveryMode) {
287
+ return undefined;
288
+ }
289
+ throw new BaseException('Invalid cross reference', 'XRefParseException');
290
+ };
291
+ _PdfCrossReference.prototype._readToken = function (data, offset) {
292
+ var lf = 0xa;
293
+ var cr = 0xd;
294
+ var lt = 0x3c;
295
+ var token = '';
296
+ var ch = data[offset]; // eslint-disable-line
297
+ while (ch !== lf && ch !== cr && ch !== lt) {
298
+ if (++offset >= data.length) {
299
+ break;
300
+ }
301
+ token += String.fromCharCode(ch);
302
+ ch = data[offset]; // eslint-disable-line
303
+ }
304
+ return token;
305
+ };
306
+ _PdfCrossReference.prototype._skipUntil = function (data, offset, what) {
307
+ var length = what.length;
308
+ var dataLength = data.length;
309
+ var skipped = 0;
310
+ while (offset < dataLength) {
311
+ var i = 0;
312
+ while (i < length && data[offset + i] === what[i]) { // eslint-disable-line
313
+ ++i;
314
+ }
315
+ if (i >= length) {
316
+ break;
317
+ }
318
+ offset++;
319
+ skipped++;
320
+ }
321
+ return skipped;
322
+ };
323
+ _PdfCrossReference.prototype._indexObjects = function () {
324
+ var tab = 0x9;
325
+ var lf = 0xa;
326
+ var cr = 0xd;
327
+ var space = 0x20;
328
+ var percent = 0x25;
329
+ var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
330
+ var endobjRegExp = /\bendobj[\b\s]$/;
331
+ var nestedObjRegExp = /\s+(\d+\s+\d+\s+obj[\b\s<])$/;
332
+ var checkContentLength = 25;
333
+ var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
334
+ var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114, 101, 102]);
335
+ var objBytes = new Uint8Array([111, 98, 106]);
336
+ var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
337
+ this._entries.length = 0;
338
+ this._cacheMap.clear();
339
+ var stream = this._stream;
340
+ stream.position = 0;
341
+ var buffer = stream.getBytes();
342
+ var length = buffer.length;
343
+ var position = stream.start;
344
+ var trailers = [];
345
+ var crossReferencePosition = [];
346
+ while (position < length) {
347
+ var ch = buffer[position]; // eslint-disable-line
348
+ if (ch === tab || ch === lf || ch === cr || ch === space) {
349
+ ++position;
350
+ continue;
351
+ }
352
+ if (ch === percent) {
353
+ do {
354
+ ++position;
355
+ if (position >= length) {
356
+ break;
357
+ }
358
+ ch = buffer[position]; // eslint-disable-line
359
+ } while (ch !== lf && ch !== cr);
360
+ continue;
361
+ }
362
+ var token = this._readToken(buffer, position);
363
+ var m = void 0; // eslint-disable-line
364
+ if (token.startsWith('xref') && (token.length === 4 || /\s/.test(token[4]))) {
365
+ position += this._skipUntil(buffer, position, trailerBytes);
366
+ trailers.push(position);
367
+ position += this._skipUntil(buffer, position, startxrefBytes);
368
+ }
369
+ else {
370
+ m = objRegExp.exec(token);
371
+ if (m) {
372
+ var objectNumber = Number.parseInt(m[1]) | 0; // eslint-disable-line
373
+ var gen = Number.parseInt(m[2]) | 0; // eslint-disable-line
374
+ var contentLength = void 0;
375
+ var startPos = position + token.length;
376
+ var updateEntries = false;
377
+ if (!this._entries[objectNumber]) { // eslint-disable-line
378
+ updateEntries = true;
379
+ }
380
+ else if (this._entries[objectNumber].gen === gen) { // eslint-disable-line
381
+ try {
382
+ var subStream = stream.makeSubStream(startPos, stream.length - startPos);
383
+ var lexicalOperator = new _PdfLexicalOperator(subStream);
384
+ var parser = new _PdfParser(lexicalOperator, null);
385
+ parser.getObject();
386
+ updateEntries = true;
387
+ }
388
+ catch (ex) {
389
+ updateEntries = !(ex instanceof ParserEndOfFileException);
390
+ }
391
+ }
392
+ if (updateEntries) {
393
+ var info = new _PdfObjectInformation();
394
+ info.offset = position - stream.start;
395
+ info.gen = gen;
396
+ info.uncompressed = true;
397
+ this._entries[objectNumber] = info; // eslint-disable-line
398
+ }
399
+ while (startPos < buffer.length) {
400
+ var endPos = startPos + this._skipUntil(buffer, startPos, objBytes) + 4;
401
+ contentLength = endPos - position;
402
+ var checkPos = Math.max(endPos - checkContentLength, startPos);
403
+ var tokenStr = _bytesToString(buffer.subarray(checkPos, endPos));
404
+ if (endobjRegExp.test(tokenStr)) {
405
+ break;
406
+ }
407
+ else {
408
+ var objToken = nestedObjRegExp.exec(tokenStr); // eslint-disable-line
409
+ if (objToken && objToken[1]) {
410
+ contentLength -= objToken[1].length;
411
+ break;
412
+ }
413
+ }
414
+ startPos = endPos;
415
+ }
416
+ var content = buffer.subarray(position, position + contentLength);
417
+ var xrefTagOffset = this._skipUntil(content, 0, xrefBytes);
418
+ if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
419
+ crossReferencePosition.push(position - stream.start);
420
+ this._crossReferencePosition[position - stream.start] = 1;
421
+ }
422
+ position += contentLength;
423
+ }
424
+ else if (token.startsWith('trailer') && (token.length === 7 || /\s/.test(token[7]))) {
425
+ trailers.push(position);
426
+ position += this._skipUntil(buffer, position, startxrefBytes);
427
+ }
428
+ else {
429
+ position += token.length + 1;
430
+ }
431
+ }
432
+ }
433
+ for (var i = 0; i < crossReferencePosition.length; ++i) {
434
+ this._startXRefQueue.push(crossReferencePosition[i]); // eslint-disable-line
435
+ this._readXRef(true);
436
+ }
437
+ var trailerDict;
438
+ for (var i = 0; i < trailers.length; ++i) {
439
+ stream.position = trailers[i]; // eslint-disable-line
440
+ var parser = new _PdfParser(new _PdfLexicalOperator(stream), this, true, true);
441
+ var obj = parser.getObject(); // eslint-disable-line
442
+ if (!_isCommand(obj, 'trailer')) {
443
+ continue;
444
+ }
445
+ var dictionary = parser.getObject(); // eslint-disable-line
446
+ if (!(dictionary instanceof _PdfDictionary)) {
447
+ continue;
448
+ }
449
+ try {
450
+ var rootDict = dictionary.get('Root'); // eslint-disable-line
451
+ if (!(rootDict instanceof _PdfDictionary)) {
452
+ continue;
453
+ }
454
+ var pagesDict = rootDict.get('Pages'); // eslint-disable-line
455
+ if (!(pagesDict instanceof _PdfDictionary)) {
456
+ continue;
457
+ }
458
+ var pagesCount = pagesDict.get('Count');
459
+ if (typeof pagesCount === 'undefined' || !Number.isInteger(pagesCount)) {
460
+ continue;
461
+ }
462
+ }
463
+ catch (ex) {
464
+ continue;
465
+ }
466
+ if (dictionary.has('ID')) {
467
+ return dictionary;
468
+ }
469
+ trailerDict = dictionary;
470
+ }
471
+ if (trailerDict) {
472
+ return trailerDict;
473
+ }
474
+ if (this._topDictionary) {
475
+ return this._topDictionary;
476
+ }
477
+ throw new BaseException('Invalid PDF structure.', 'InvalidPDFException');
478
+ };
479
+ _PdfCrossReference.prototype._processXRefTable = function (parser) {
480
+ if (typeof this._tableState === 'undefined') {
481
+ var tableState = new _PdfCrossTableState();
482
+ tableState.entryNum = 0;
483
+ tableState.streamPos = parser.lexicalOperator.stream.position;
484
+ tableState.parserBuf1 = parser.first;
485
+ tableState.parserBuf2 = parser.second;
486
+ this._tableState = tableState;
487
+ }
488
+ var obj = this._readXRefTable(parser);
489
+ if (!_isCommand(obj, 'trailer')) {
490
+ throw new FormatError('Invalid XRef table: could not find trailer dictionary');
491
+ }
492
+ var topDictionary = parser.getObject(); // eslint-disable-line
493
+ var dictionary;
494
+ if (topDictionary) {
495
+ if (topDictionary instanceof _PdfDictionary) {
496
+ dictionary = topDictionary;
497
+ }
498
+ else if (topDictionary instanceof _PdfBaseStream && topDictionary.dictionary) {
499
+ dictionary = topDictionary.dictionary;
500
+ }
501
+ }
502
+ if (!dictionary) {
503
+ throw new FormatError('Invalid cross reference: could not parse trailer dictionary');
504
+ }
505
+ this._tableState = undefined;
506
+ return dictionary;
507
+ };
508
+ _PdfCrossReference.prototype._readXRefTable = function (parser) {
509
+ var stream = parser.lexicalOperator.stream;
510
+ stream.position = this._tableState.streamPos;
511
+ parser.first = this._tableState.parserBuf1;
512
+ parser.second = this._tableState.parserBuf2;
513
+ var obj; // eslint-disable-line
514
+ while (true) { // eslint-disable-line
515
+ if (typeof this._tableState.firstEntryNum === 'undefined' || typeof this._tableState.entryCount === 'undefined') {
516
+ obj = parser.getObject();
517
+ if (_isCommand(obj, 'trailer')) {
518
+ break;
519
+ }
520
+ this._tableState.firstEntryNum = obj;
521
+ this._tableState.entryCount = parser.getObject();
522
+ }
523
+ var first = this._tableState.firstEntryNum;
524
+ var count = this._tableState.entryCount;
525
+ if (!Number.isInteger(first) || !Number.isInteger(count)) {
526
+ throw new FormatError('Invalid cross reference: wrong types in subsection header');
527
+ }
528
+ for (var i = this._tableState.entryNum; i < count; i++) {
529
+ this._tableState.streamPos = stream.position;
530
+ this._tableState.entryNum = i;
531
+ this._tableState.parserBuf1 = parser.first;
532
+ this._tableState.parserBuf2 = parser.second;
533
+ var entry = new _PdfObjectInformation();
534
+ entry.offset = parser.getObject();
535
+ entry.gen = parser.getObject();
536
+ var type = parser.getObject();
537
+ if (type) {
538
+ switch (type.command) {
539
+ case 'f':
540
+ entry.free = true;
541
+ break;
542
+ case 'n':
543
+ entry.uncompressed = true;
544
+ break;
545
+ }
546
+ }
547
+ if (!Number.isInteger(entry.offset) || !Number.isInteger(entry.gen) || !(entry.free || entry.uncompressed)) {
548
+ throw new FormatError("Invalid entry in cross reference subsection: " + first + ", " + count);
549
+ }
550
+ if (i === 0 && entry.free && first === 1) {
551
+ first = 0;
552
+ }
553
+ if (!this._entries[i + first]) {
554
+ this._entries[i + first] = entry;
555
+ }
556
+ }
557
+ this._tableState.entryNum = 0;
558
+ this._tableState.streamPos = stream.position;
559
+ this._tableState.parserBuf1 = parser.first;
560
+ this._tableState.parserBuf2 = parser.second;
561
+ this._tableState.firstEntryNum = undefined;
562
+ this._tableState.entryCount = undefined;
563
+ }
564
+ if (this._entries[0] && !this._entries[0].free) {
565
+ throw new FormatError('Invalid XRef table: unexpected first object');
566
+ }
567
+ return obj;
568
+ };
569
+ _PdfCrossReference.prototype._processXRefStream = function (stream) {
570
+ if (typeof this._streamState === 'undefined') {
571
+ var streamParameters = stream.dictionary;
572
+ var streamState = new _PdfStreamState();
573
+ var index = streamParameters.getArray('Index');
574
+ if (!index) {
575
+ index = [0, streamParameters.get('Size')];
576
+ }
577
+ streamState.entryRanges = index;
578
+ streamState.byteWidths = streamParameters.getArray('W');
579
+ streamState.entryNum = 0;
580
+ streamState.streamPos = stream.position;
581
+ this._streamState = streamState;
582
+ }
583
+ this._readXRefStream(stream);
584
+ this._streamState = undefined;
585
+ return stream.dictionary;
586
+ };
587
+ _PdfCrossReference.prototype._readXRefStream = function (stream) {
588
+ stream.position = this._streamState.streamPos;
589
+ var typeFieldWidth = this._streamState.byteWidths[0];
590
+ var offsetFieldWidth = this._streamState.byteWidths[1];
591
+ var generationFieldWidth = this._streamState.byteWidths[2];
592
+ var entryRanges = this._streamState.entryRanges;
593
+ while (entryRanges.length > 0) {
594
+ var first = entryRanges[0];
595
+ var n = entryRanges[1];
596
+ if (!Number.isInteger(first) || !Number.isInteger(n)) {
597
+ throw new FormatError("Invalid XRef range fields: " + first + ", " + n);
598
+ }
599
+ if (!Number.isInteger(typeFieldWidth) || !Number.isInteger(offsetFieldWidth) || !Number.isInteger(generationFieldWidth)) {
600
+ throw new FormatError("Invalid XRef entry fields length: " + first + ", " + n);
601
+ }
602
+ for (var i = this._streamState.entryNum; i < n; ++i) {
603
+ this._streamState.entryNum = i;
604
+ this._streamState.streamPos = stream.position;
605
+ var type = 0;
606
+ var offset = 0;
607
+ var generation = 0;
608
+ for (var j = 0; j < typeFieldWidth; ++j) {
609
+ var typeByte = stream.getByte();
610
+ if (typeByte === -1) {
611
+ throw new FormatError('invalid cross reference byte width type.');
612
+ }
613
+ type = (type << 8) | typeByte;
614
+ }
615
+ if (typeFieldWidth === 0) {
616
+ type = 1;
617
+ }
618
+ for (var j = 0; j < offsetFieldWidth; ++j) {
619
+ var offsetByte = stream.getByte();
620
+ if (offsetByte === -1) {
621
+ throw new FormatError('invalid cross reference byte width offset.');
622
+ }
623
+ offset = (offset << 8) | offsetByte;
624
+ }
625
+ for (var j = 0; j < generationFieldWidth; ++j) {
626
+ var generationByte = stream.getByte();
627
+ if (generationByte === -1) {
628
+ throw new FormatError('invalid cross reference byte width generation.');
629
+ }
630
+ generation = (generation << 8) | generationByte;
631
+ }
632
+ var entry = new _PdfObjectInformation();
633
+ entry.offset = offset;
634
+ entry.gen = generation;
635
+ switch (type) {
636
+ case 0:
637
+ entry.free = true;
638
+ break;
639
+ case 1:
640
+ entry.uncompressed = true;
641
+ break;
642
+ case 2:
643
+ break;
644
+ default:
645
+ throw new FormatError("Invalid XRef entry type: " + type);
646
+ }
647
+ if (!this._entries[first + i]) {
648
+ this._entries[first + i] = entry;
649
+ }
650
+ }
651
+ this._streamState.entryNum = 0;
652
+ this._streamState.streamPos = stream.position;
653
+ entryRanges.splice(0, 2);
654
+ }
655
+ };
656
+ _PdfCrossReference.prototype._getCatalogObj = function () {
657
+ return this._root;
658
+ };
659
+ _PdfCrossReference.prototype._save = function () {
660
+ var _this = this;
661
+ var currentLength = this._stream.length;
662
+ var buffer = [this._newLine.charCodeAt(0), this._newLine.charCodeAt(1), 37, 80, 68, 70, 45];
663
+ this._writeString("" + this._version + this._newLine, buffer);
664
+ buffer.push(0x25, 0x83, 0x92, 0xfa, 0xfe);
665
+ this._writeString(this._newLine, buffer);
666
+ var updatedCount = 0;
667
+ var uncompressedCount = 0;
668
+ if (this._document._fileStructure._crossReferenceType === PdfCrossReferenceType.stream) {
669
+ var data = [];
670
+ var updatedStream_1 = [];
671
+ var archiveXRef_1 = '';
672
+ var indexes_1 = [];
673
+ indexes_1.push(0, 1);
674
+ var collection_1 = [];
675
+ var uncompressedOffsets_1 = [];
676
+ this._cacheMap.forEach(function (value, key) {
677
+ var dictionary;
678
+ if (value instanceof _PdfBaseStream) {
679
+ dictionary = value.dictionary;
680
+ }
681
+ if (dictionary && dictionary._updated && (!dictionary.isCatalog || _this._allowCatalog)) {
682
+ indexes_1.push(key.objectNumber, 1);
683
+ uncompressedOffsets_1.push(currentLength + buffer.length);
684
+ var cipher_1;
685
+ if (_this._encrypt) {
686
+ cipher_1 = _this._encrypt._createCipherTransform(key.objectNumber, key.generationNumber);
687
+ }
688
+ _this._writeObject(value, buffer, key, cipher_1);
689
+ uncompressedCount++;
690
+ dictionary._updated = false;
691
+ }
692
+ });
693
+ this._cacheMap.forEach(function (value, key) {
694
+ if (value instanceof _PdfDictionary) {
695
+ if (value._updated && (!value.isCatalog || _this._allowCatalog)) {
696
+ archiveXRef_1 += key.objectNumber + " " + updatedStream_1.length + _this._newLine;
697
+ collection_1.push(key.objectNumber, 1);
698
+ updatedCount++;
699
+ _this._writeObject(value, updatedStream_1);
700
+ }
701
+ }
702
+ else if (value instanceof _PdfBaseStream) {
703
+ var dictionary = value.dictionary;
704
+ if (dictionary && dictionary._updated && (!dictionary.isCatalog || _this._allowCatalog)) {
705
+ indexes_1.push(key.objectNumber, 1);
706
+ uncompressedOffsets_1.push(currentLength + buffer.length);
707
+ _this._writeObject(value, buffer, key);
708
+ uncompressedCount++;
709
+ dictionary._updated = false;
710
+ }
711
+ }
712
+ });
713
+ for (var i = 0; i < collection_1.length; i++) {
714
+ indexes_1.push(collection_1[parseInt(i.toString(), 10)]);
715
+ }
716
+ var archiveOffset = void 0;
717
+ var archiveRef = void 0;
718
+ if (updatedCount > 0) {
719
+ archiveRef = this._getNextReference();
720
+ indexes_1.push(archiveRef.objectNumber, 2);
721
+ this._writeString(archiveXRef_1, data);
722
+ this._writeBytes(updatedStream_1, data);
723
+ var newDict = new _PdfDictionary(this);
724
+ newDict.set('Type', _PdfName.get('ObjStm'));
725
+ newDict.set('N', updatedCount);
726
+ newDict.set('First', archiveXRef_1.length);
727
+ newDict.set('Length', data.length);
728
+ var archiveStream = new _PdfStream(data, newDict, 0, data.length);
729
+ archiveOffset = currentLength + buffer.length;
730
+ var cipher_2;
731
+ if (this._encrypt) {
732
+ cipher_2 = this._encrypt._createCipherTransform(archiveRef.objectNumber, archiveRef.generationNumber);
733
+ }
734
+ this._writeObject(archiveStream, buffer, archiveRef, cipher_2);
735
+ }
736
+ var newRef = this._getNextReference();
737
+ var newStartXref = currentLength + buffer.length;
738
+ var newXref = new _PdfDictionary(this);
739
+ newXref.set('Type', _PdfName.get('XRef'));
740
+ newXref.set('Index', indexes_1);
741
+ newXref.set('W', [1, 3, 1]);
742
+ this._copyTrailer(newXref);
743
+ if (this._ids && this._ids.length > 0) {
744
+ newXref.update('ID', [this._ids[0], this._computeMessageDigest(newStartXref)]);
745
+ }
746
+ var newXrefData = [];
747
+ this._writeLong(0, 1, newXrefData);
748
+ this._writeLong(1, 3, newXrefData);
749
+ this._writeLong(-1, 1, newXrefData);
750
+ if (uncompressedCount > 0) {
751
+ for (var index = 0; index < uncompressedCount; index++) {
752
+ this._writeLong(1, 1, newXrefData);
753
+ this._writeLong(uncompressedOffsets_1[index], 3, newXrefData); // eslint-disable-line
754
+ this._writeLong(0, 1, newXrefData);
755
+ }
756
+ }
757
+ if (updatedCount > 0) {
758
+ for (var index = 0; index < updatedCount; index++) {
759
+ this._writeLong(2, 1, newXrefData);
760
+ this._writeLong(archiveRef.objectNumber, 3, newXrefData);
761
+ this._writeLong(index, 1, newXrefData);
762
+ }
763
+ this._writeLong(1, 1, newXrefData);
764
+ this._writeLong(archiveOffset, 3, newXrefData);
765
+ this._writeLong(0, 1, newXrefData);
766
+ }
767
+ this._writeLong(1, 1, newXrefData);
768
+ this._writeLong(newStartXref, 3, newXrefData);
769
+ this._writeLong(0, 1, newXrefData);
770
+ newXref.set('Length', newXrefData.length);
771
+ var newXrefStream = new _PdfStream(newXrefData, newXref, 0, newXrefData.length);
772
+ var cipher = void 0;
773
+ if (this._encrypt) {
774
+ cipher = this._encrypt._createCipherTransform(newRef.objectNumber, newRef.generationNumber);
775
+ }
776
+ this._writeObject(newXrefStream, buffer, newRef, cipher, true);
777
+ this._writeString("startxref" + this._newLine + newStartXref + this._newLine + "%%EOF" + this._newLine, buffer);
778
+ }
779
+ else {
780
+ var tempBuffer_1 = '';
781
+ this._cacheMap.forEach(function (value, key) {
782
+ var dictionary;
783
+ if (value instanceof _PdfDictionary) {
784
+ dictionary = value;
785
+ }
786
+ else if (value instanceof _PdfBaseStream) {
787
+ dictionary = value.dictionary;
788
+ }
789
+ if (dictionary && dictionary._updated && (!dictionary.isCatalog || _this._allowCatalog)) {
790
+ var offsetString = (currentLength + buffer.length).toString();
791
+ while (offsetString.length < 10) {
792
+ offsetString = '0' + offsetString;
793
+ }
794
+ var genString = key.generationNumber.toString();
795
+ while (genString.length < 5) {
796
+ genString = '0' + genString;
797
+ }
798
+ tempBuffer_1 += key.objectNumber + " 1" + _this._newLine + offsetString + " " + genString + " n" + _this._newLine;
799
+ updatedCount++;
800
+ _this._writeObject(value, buffer, key);
801
+ }
802
+ });
803
+ var newStartXref = buffer.length + currentLength;
804
+ this._writeString("xref" + this._newLine + "0 1" + this._newLine + "0000000000 65535 f" + this._newLine, buffer);
805
+ if (updatedCount > 0) {
806
+ this._writeString(tempBuffer_1, buffer);
807
+ }
808
+ this._writeString("trailer" + this._newLine, buffer);
809
+ var newXref = new _PdfDictionary(this);
810
+ this._copyTrailer(newXref);
811
+ this._writeDictionary(newXref, buffer, this._newLine);
812
+ this._writeString("startxref" + this._newLine + newStartXref + this._newLine + "%%EOF" + this._newLine, buffer);
813
+ }
814
+ var array = new Uint8Array(this._stream.length + buffer.length);
815
+ array.set(this._stream.bytes);
816
+ array.set(buffer, this._stream.length);
817
+ return array;
818
+ };
819
+ _PdfCrossReference.prototype._copyTrailer = function (newXref) {
820
+ newXref.set('Size', this._nextReferenceNumber);
821
+ newXref.set('Prev', this._prevStartXref);
822
+ var root = this._trailer.getRaw('Root'); // eslint-disable-line
823
+ if (typeof root !== 'undefined' && root !== null) {
824
+ newXref.set('Root', root);
825
+ }
826
+ var info = this._trailer.getRaw('Info'); // eslint-disable-line
827
+ if (typeof info !== 'undefined' && info !== null) {
828
+ newXref.set('Info', info);
829
+ }
830
+ var encrypt = this._trailer.getRaw('Encrypt'); // eslint-disable-line
831
+ if (typeof encrypt !== 'undefined' && encrypt !== null) {
832
+ newXref.set('Encrypt', encrypt);
833
+ }
834
+ };
835
+ _PdfCrossReference.prototype._computeMessageDigest = function (size) {
836
+ var _this = this;
837
+ var time = Math.floor(Date.now() / 1000);
838
+ var buffer = [time.toString(), '', size.toString()];
839
+ var info = this._trailer.getRaw('Info');
840
+ var crossReferenceInfo = new _PdfDictionary();
841
+ if (info && info instanceof _PdfDictionary) {
842
+ info.forEach(function (key, value) {
843
+ if (value && typeof value === 'string') {
844
+ crossReferenceInfo.set(key, _stringToPdfString(value));
845
+ }
846
+ });
847
+ }
848
+ crossReferenceInfo.forEach(function (key, value) {
849
+ buffer.push(value);
850
+ });
851
+ var array = [];
852
+ buffer.forEach(function (str) {
853
+ _this._writeString(str, array);
854
+ });
855
+ return _bytesToString((new _MD5().hash(new Uint8Array(array))));
856
+ };
857
+ _PdfCrossReference.prototype._getNextReference = function () {
858
+ var reference = new _PdfReference(this._nextReferenceNumber++, 0);
859
+ reference._isNew = true;
860
+ return reference;
861
+ };
862
+ _PdfCrossReference.prototype._writeObject = function (obj, buffer, reference, transform, isCrossReference) {
863
+ if (reference && reference instanceof _PdfReference) {
864
+ this._writeString(reference.objectNumber + " " + reference.generationNumber + " obj" + this._newLine, buffer);
865
+ }
866
+ if (obj instanceof _PdfDictionary) {
867
+ this._writeDictionary(obj, buffer, this._newLine, transform, isCrossReference);
868
+ }
869
+ else if (obj instanceof _PdfBaseStream) {
870
+ this._writeStream(obj, buffer, transform, isCrossReference);
871
+ }
872
+ if (reference && reference instanceof _PdfReference) {
873
+ this._writeString("endobj" + this._newLine, buffer);
874
+ }
875
+ };
876
+ _PdfCrossReference.prototype._writeDictionary = function (dictionary, buffer, spaceChar, transform, isCrossReference) {
877
+ var _this = this;
878
+ if (dictionary._currentObj) {
879
+ dictionary._currentObj._beginSave();
880
+ }
881
+ if (dictionary._isFont) {
882
+ this._writeFontDictionary(dictionary);
883
+ }
884
+ this._writeString("<<" + spaceChar, buffer);
885
+ dictionary.forEach(function (key, value) {
886
+ _this._writeString("/" + _escapePdfName(key) + " ", buffer);
887
+ _this._writeValue(value, buffer, transform, isCrossReference);
888
+ _this._writeString(spaceChar, buffer);
889
+ });
890
+ this._writeString(">>" + this._newLine, buffer);
891
+ };
892
+ _PdfCrossReference.prototype._writeFontDictionary = function (dictionary) {
893
+ if (dictionary.has('DescendantFonts')) {
894
+ var fonts = dictionary.get('DescendantFonts'); // eslint-disable-line
895
+ var reference = this._getNextReference();
896
+ this._cacheMap.set(reference, fonts);
897
+ dictionary.update('DescendantFonts', [reference]);
898
+ }
899
+ if (dictionary.has('ToUnicode')) {
900
+ var fonts = dictionary.get('ToUnicode'); // eslint-disable-line
901
+ var reference = this._getNextReference();
902
+ this._cacheMap.set(reference, fonts);
903
+ dictionary.update('ToUnicode', reference);
904
+ }
905
+ if (dictionary.has('FontFile2')) {
906
+ var fonts = dictionary.get('FontFile2'); // eslint-disable-line
907
+ var reference = this._getNextReference();
908
+ this._cacheMap.set(reference, fonts);
909
+ dictionary.update('FontFile2', reference);
910
+ }
911
+ if (dictionary.has('FontDescriptor')) {
912
+ var fonts = dictionary.get('FontDescriptor'); // eslint-disable-line
913
+ var reference = this._getNextReference();
914
+ this._cacheMap.set(reference, fonts);
915
+ dictionary.update('FontDescriptor', reference);
916
+ }
917
+ };
918
+ _PdfCrossReference.prototype._writeStream = function (stream, buffer, transform, isCrossReference) {
919
+ var streamBuffer = [];
920
+ var value = stream.getString();
921
+ if (!isCrossReference) {
922
+ var byteArray = [];
923
+ for (var i = 0; i < value.length; i++) {
924
+ byteArray.push(value.charCodeAt(i));
925
+ }
926
+ if (stream._isCompress) {
927
+ var dataArray = new Uint8Array(byteArray);
928
+ var sw = new CompressedStreamWriter();
929
+ sw.write(dataArray, 0, dataArray.length);
930
+ sw.close();
931
+ value = sw.getCompressedString;
932
+ stream.dictionary.update('Filter', _PdfName.get('FlateDecode'));
933
+ }
934
+ if (transform) {
935
+ value = transform.encryptString(value);
936
+ }
937
+ }
938
+ this._writeString(value, streamBuffer);
939
+ stream.dictionary.update('Length', streamBuffer.length);
940
+ this._writeDictionary(stream.dictionary, buffer, this._newLine, transform, isCrossReference);
941
+ this._writeString("stream" + this._newLine, buffer);
942
+ this._writeBytes(streamBuffer, buffer);
943
+ this._writeString(this._newLine + "endstream" + this._newLine, buffer);
944
+ };
945
+ _PdfCrossReference.prototype._writeValue = function (value, buffer, transform, isCrossReference) {
946
+ if (value instanceof _PdfName) {
947
+ this._writeString("/" + _escapePdfName(value.name), buffer);
948
+ }
949
+ else if (value instanceof _PdfReference) {
950
+ this._writeString(value.toString() + " R", buffer);
951
+ }
952
+ else if (Array.isArray(value)) {
953
+ this._writeString('[', buffer);
954
+ var first = true;
955
+ for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
956
+ var val = value_1[_i];
957
+ if (!first) {
958
+ this._writeString(' ', buffer);
959
+ }
960
+ else {
961
+ first = false;
962
+ }
963
+ this._writeValue(val, buffer, transform, isCrossReference);
964
+ }
965
+ this._writeString(']', buffer);
966
+ }
967
+ else if (typeof value === 'string') {
968
+ if (!isCrossReference && transform) {
969
+ value = transform.encryptString(value);
970
+ }
971
+ this._writeString("(" + this._escapeString(value) + ")", buffer);
972
+ }
973
+ else if (typeof value === 'number') {
974
+ this._writeString(_numberToString(value), buffer);
975
+ }
976
+ else if (typeof value === 'boolean') {
977
+ this._writeString(value.toString(), buffer);
978
+ }
979
+ else if (value instanceof _PdfDictionary) {
980
+ this._writeDictionary(value, buffer, this._newLine, transform, isCrossReference);
981
+ }
982
+ else if (value instanceof _PdfBaseStream) {
983
+ this._writeStream(value, buffer, transform, isCrossReference);
984
+ }
985
+ else if (value === null) {
986
+ this._writeString('null', buffer);
987
+ }
988
+ };
989
+ _PdfCrossReference.prototype._writeString = function (value, buffer) {
990
+ for (var i = 0; i < value.length; i++) {
991
+ buffer.push(value.charCodeAt(i) & 0xff);
992
+ }
993
+ };
994
+ _PdfCrossReference.prototype._writeBytes = function (data, buffer) {
995
+ for (var i = 0; i < data.length; i++) {
996
+ buffer.push(data[i]); // eslint-disable-line
997
+ }
998
+ };
999
+ _PdfCrossReference.prototype._writeLong = function (value, count, buffer) {
1000
+ for (var i = count - 1; i >= 0; --i) {
1001
+ buffer.push(value >> (i << 3) & 0xff);
1002
+ }
1003
+ };
1004
+ _PdfCrossReference.prototype._escapeString = function (value) {
1005
+ return value.replace(/([()\\\n\r])/g, function (substring) {
1006
+ if (substring === '\n') {
1007
+ return '\\n';
1008
+ }
1009
+ else if (substring === '\r') {
1010
+ return '\\r';
1011
+ }
1012
+ return "\\" + substring;
1013
+ });
1014
+ };
1015
+ _PdfCrossReference.prototype._destroy = function () {
1016
+ this._entries = undefined;
1017
+ this._pendingRefs.clear();
1018
+ this._pendingRefs = undefined;
1019
+ this._cacheMap.clear();
1020
+ this._pendingRefs = undefined;
1021
+ this._root = undefined;
1022
+ this._startXRefQueue = [];
1023
+ this._startXRefQueue = undefined;
1024
+ this._stream = undefined;
1025
+ this._streamState = undefined;
1026
+ this._tableState = undefined;
1027
+ this._topDictionary = undefined;
1028
+ this._trailer = undefined;
1029
+ this._version = undefined;
1030
+ this._crossReferencePosition = undefined;
1031
+ };
1032
+ return _PdfCrossReference;
1033
+ }());
1034
+ export { _PdfCrossReference };
1035
+ var _PdfObjectInformation = /** @class */ (function () {
1036
+ function _PdfObjectInformation() {
1037
+ }
1038
+ return _PdfObjectInformation;
1039
+ }());
1040
+ var _PdfCrossTableState = /** @class */ (function () {
1041
+ function _PdfCrossTableState() {
1042
+ }
1043
+ return _PdfCrossTableState;
1044
+ }());
1045
+ var _PdfStreamState = /** @class */ (function () {
1046
+ function _PdfStreamState() {
1047
+ }
1048
+ return _PdfStreamState;
1049
+ }());