@syncfusion/ej2-pdf-export 24.1.41 → 24.2.3

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 (164) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/ej2-pdf-export.min.js +2 -2
  3. package/dist/ej2-pdf-export.umd.min.js +2 -2
  4. package/dist/ej2-pdf-export.umd.min.js.map +1 -1
  5. package/dist/es6/ej2-pdf-export.es2015.js +157 -28
  6. package/dist/es6/ej2-pdf-export.es2015.js.map +1 -1
  7. package/dist/es6/ej2-pdf-export.es5.js +157 -28
  8. package/dist/es6/ej2-pdf-export.es5.js.map +1 -1
  9. package/dist/global/ej2-pdf-export.min.js +2 -2
  10. package/dist/global/ej2-pdf-export.min.js.map +1 -1
  11. package/dist/global/index.d.ts +1 -1
  12. package/package.json +6 -6
  13. package/src/implementation/graphics/pdf-graphics.d.ts +35 -0
  14. package/src/implementation/graphics/pdf-graphics.js +157 -29
  15. package/dist/ts/implementation/actions/action.ts +0 -76
  16. package/dist/ts/implementation/actions/uri-action.ts +0 -52
  17. package/dist/ts/implementation/annotations/action-link-annotation.ts +0 -43
  18. package/dist/ts/implementation/annotations/annotation-collection.ts +0 -159
  19. package/dist/ts/implementation/annotations/annotation.ts +0 -241
  20. package/dist/ts/implementation/annotations/document-link-annotation.ts +0 -118
  21. package/dist/ts/implementation/annotations/link-annotation.ts +0 -32
  22. package/dist/ts/implementation/annotations/pdf-text-web-link.ts +0 -265
  23. package/dist/ts/implementation/annotations/uri-annotation.ts +0 -86
  24. package/dist/ts/implementation/collections/dictionary.ts +0 -150
  25. package/dist/ts/implementation/collections/object-object-pair/dictionary.ts +0 -125
  26. package/dist/ts/implementation/collections/utils.ts +0 -38
  27. package/dist/ts/implementation/document/automatic-fields/automatic-field-info-collection.ts +0 -39
  28. package/dist/ts/implementation/document/automatic-fields/automatic-field-info.ts +0 -108
  29. package/dist/ts/implementation/document/automatic-fields/automatic-field.ts +0 -127
  30. package/dist/ts/implementation/document/automatic-fields/composite-field.ts +0 -76
  31. package/dist/ts/implementation/document/automatic-fields/multiple-value-field.ts +0 -37
  32. package/dist/ts/implementation/document/automatic-fields/page-count-field.ts +0 -75
  33. package/dist/ts/implementation/document/automatic-fields/pdf-numbers-convertor.ts +0 -157
  34. package/dist/ts/implementation/document/automatic-fields/pdf-page-number-field.ts +0 -82
  35. package/dist/ts/implementation/document/automatic-fields/pdf-template-value-pair.ts +0 -60
  36. package/dist/ts/implementation/document/automatic-fields/single-value-field.ts +0 -48
  37. package/dist/ts/implementation/document/pdf-catalog.ts +0 -65
  38. package/dist/ts/implementation/document/pdf-document-base.ts +0 -180
  39. package/dist/ts/implementation/document/pdf-document-template.ts +0 -310
  40. package/dist/ts/implementation/document/pdf-document.ts +0 -342
  41. package/dist/ts/implementation/document/pdf-viewer-preferences.ts +0 -578
  42. package/dist/ts/implementation/drawing/pdf-drawing.ts +0 -218
  43. package/dist/ts/implementation/general/enum.ts +0 -21
  44. package/dist/ts/implementation/general/functions/pdf-function.ts +0 -66
  45. package/dist/ts/implementation/general/functions/pdf-sampled-function.ts +0 -63
  46. package/dist/ts/implementation/general/pdf-cache-collection.ts +0 -97
  47. package/dist/ts/implementation/general/pdf-collection.ts +0 -41
  48. package/dist/ts/implementation/general/pdf-destination.ts +0 -170
  49. package/dist/ts/implementation/graphics/brushes/enum.ts +0 -237
  50. package/dist/ts/implementation/graphics/brushes/pdf-blend.ts +0 -294
  51. package/dist/ts/implementation/graphics/brushes/pdf-brush.ts +0 -68
  52. package/dist/ts/implementation/graphics/brushes/pdf-brushes.ts +0 -2438
  53. package/dist/ts/implementation/graphics/brushes/pdf-color-blend.ts +0 -295
  54. package/dist/ts/implementation/graphics/brushes/pdf-gradient-brush.ts +0 -311
  55. package/dist/ts/implementation/graphics/brushes/pdf-linear-gradient-brush.ts +0 -406
  56. package/dist/ts/implementation/graphics/brushes/pdf-radial-gradient-brush.ts +0 -290
  57. package/dist/ts/implementation/graphics/brushes/pdf-solid-brush.ts +0 -107
  58. package/dist/ts/implementation/graphics/brushes/pdf-tiling-brush.ts +0 -304
  59. package/dist/ts/implementation/graphics/constants.ts +0 -31
  60. package/dist/ts/implementation/graphics/enum.ts +0 -413
  61. package/dist/ts/implementation/graphics/figures/arc.ts +0 -133
  62. package/dist/ts/implementation/graphics/figures/base/draw-element.ts +0 -59
  63. package/dist/ts/implementation/graphics/figures/base/element-layouter.ts +0 -260
  64. package/dist/ts/implementation/graphics/figures/base/fill-element.ts +0 -72
  65. package/dist/ts/implementation/graphics/figures/base/graphics-element.ts +0 -34
  66. package/dist/ts/implementation/graphics/figures/base/pdf-shape-element.ts +0 -69
  67. package/dist/ts/implementation/graphics/figures/base/shape-layouter.ts +0 -276
  68. package/dist/ts/implementation/graphics/figures/base/text-layouter.ts +0 -205
  69. package/dist/ts/implementation/graphics/figures/ellipse-part.ts +0 -76
  70. package/dist/ts/implementation/graphics/figures/enum.ts +0 -80
  71. package/dist/ts/implementation/graphics/figures/layout-element.ts +0 -132
  72. package/dist/ts/implementation/graphics/figures/path.ts +0 -646
  73. package/dist/ts/implementation/graphics/figures/pdf-template.ts +0 -205
  74. package/dist/ts/implementation/graphics/figures/rectangle-area.ts +0 -108
  75. package/dist/ts/implementation/graphics/figures/text-element.ts +0 -445
  76. package/dist/ts/implementation/graphics/fonts/enum.ts +0 -385
  77. package/dist/ts/implementation/graphics/fonts/pdf-font-metrics.ts +0 -248
  78. package/dist/ts/implementation/graphics/fonts/pdf-font.ts +0 -316
  79. package/dist/ts/implementation/graphics/fonts/pdf-standard-font-metrics-factory.ts +0 -606
  80. package/dist/ts/implementation/graphics/fonts/pdf-standard-font.ts +0 -243
  81. package/dist/ts/implementation/graphics/fonts/pdf-string-format.ts +0 -474
  82. package/dist/ts/implementation/graphics/fonts/pdf-true-type-font.ts +0 -165
  83. package/dist/ts/implementation/graphics/fonts/rtl/rtl-bidirectional.ts +0 -958
  84. package/dist/ts/implementation/graphics/fonts/rtl/rtl-text-shape.ts +0 -374
  85. package/dist/ts/implementation/graphics/fonts/rtl-renderer.ts +0 -255
  86. package/dist/ts/implementation/graphics/fonts/string-layouter.ts +0 -617
  87. package/dist/ts/implementation/graphics/fonts/string-tokenizer.ts +0 -275
  88. package/dist/ts/implementation/graphics/fonts/ttf-OS2-Table.ts +0 -206
  89. package/dist/ts/implementation/graphics/fonts/ttf-apple-cmap-sub-table.ts +0 -18
  90. package/dist/ts/implementation/graphics/fonts/ttf-cmap-sub-table.ts +0 -18
  91. package/dist/ts/implementation/graphics/fonts/ttf-cmap-table.ts +0 -14
  92. package/dist/ts/implementation/graphics/fonts/ttf-glyph-header.ts +0 -26
  93. package/dist/ts/implementation/graphics/fonts/ttf-glyph-info.ts +0 -35
  94. package/dist/ts/implementation/graphics/fonts/ttf-head-table.ts +0 -94
  95. package/dist/ts/implementation/graphics/fonts/ttf-horizontal-header-table.ts +0 -56
  96. package/dist/ts/implementation/graphics/fonts/ttf-loca-table.ts +0 -10
  97. package/dist/ts/implementation/graphics/fonts/ttf-long-hor-metric.ts +0 -14
  98. package/dist/ts/implementation/graphics/fonts/ttf-metrics.ts +0 -106
  99. package/dist/ts/implementation/graphics/fonts/ttf-microsoft-cmap-sub-table.ts +0 -58
  100. package/dist/ts/implementation/graphics/fonts/ttf-name-record.ts +0 -33
  101. package/dist/ts/implementation/graphics/fonts/ttf-name-table.ts +0 -22
  102. package/dist/ts/implementation/graphics/fonts/ttf-post-table.ts +0 -42
  103. package/dist/ts/implementation/graphics/fonts/ttf-reader.ts +0 -1254
  104. package/dist/ts/implementation/graphics/fonts/ttf-table-info.ts +0 -26
  105. package/dist/ts/implementation/graphics/fonts/ttf-trimmed-cmap-sub-table.ts +0 -26
  106. package/dist/ts/implementation/graphics/fonts/unicode-true-type-font.ts +0 -577
  107. package/dist/ts/implementation/graphics/images/byte-array.ts +0 -137
  108. package/dist/ts/implementation/graphics/images/image-decoder.ts +0 -439
  109. package/dist/ts/implementation/graphics/images/pdf-bitmap.ts +0 -110
  110. package/dist/ts/implementation/graphics/images/pdf-image.ts +0 -132
  111. package/dist/ts/implementation/graphics/pdf-color.ts +0 -478
  112. package/dist/ts/implementation/graphics/pdf-graphics.ts +0 -2429
  113. package/dist/ts/implementation/graphics/pdf-margins.ts +0 -124
  114. package/dist/ts/implementation/graphics/pdf-pen.ts +0 -370
  115. package/dist/ts/implementation/graphics/pdf-resources.ts +0 -300
  116. package/dist/ts/implementation/graphics/pdf-transformation-matrix.ts +0 -246
  117. package/dist/ts/implementation/graphics/pdf-transparency.ts +0 -93
  118. package/dist/ts/implementation/graphics/unit-convertor.ts +0 -96
  119. package/dist/ts/implementation/input-output/big-endian-writer.ts +0 -121
  120. package/dist/ts/implementation/input-output/cross-table.ts +0 -21
  121. package/dist/ts/implementation/input-output/enum.ts +0 -16
  122. package/dist/ts/implementation/input-output/pdf-cross-table.ts +0 -524
  123. package/dist/ts/implementation/input-output/pdf-dictionary-properties.ts +0 -571
  124. package/dist/ts/implementation/input-output/pdf-main-object-collection.ts +0 -194
  125. package/dist/ts/implementation/input-output/pdf-operators.ts +0 -363
  126. package/dist/ts/implementation/input-output/pdf-stream-writer.ts +0 -681
  127. package/dist/ts/implementation/input-output/pdf-writer.ts +0 -88
  128. package/dist/ts/implementation/pages/enum.ts +0 -201
  129. package/dist/ts/implementation/pages/page-added-event-arguments.ts +0 -39
  130. package/dist/ts/implementation/pages/pdf-document-page-collection.ts +0 -180
  131. package/dist/ts/implementation/pages/pdf-page-base.ts +0 -181
  132. package/dist/ts/implementation/pages/pdf-page-layer-collection.ts +0 -348
  133. package/dist/ts/implementation/pages/pdf-page-layer.ts +0 -271
  134. package/dist/ts/implementation/pages/pdf-page-settings.ts +0 -192
  135. package/dist/ts/implementation/pages/pdf-page-size.ts +0 -162
  136. package/dist/ts/implementation/pages/pdf-page-template-element.ts +0 -663
  137. package/dist/ts/implementation/pages/pdf-page.ts +0 -235
  138. package/dist/ts/implementation/pages/pdf-section-collection.ts +0 -187
  139. package/dist/ts/implementation/pages/pdf-section-page-collection.ts +0 -61
  140. package/dist/ts/implementation/pages/pdf-section-templates.ts +0 -96
  141. package/dist/ts/implementation/pages/pdf-section.ts +0 -644
  142. package/dist/ts/implementation/primitives/pdf-array.ts +0 -386
  143. package/dist/ts/implementation/primitives/pdf-boolean.ts +0 -119
  144. package/dist/ts/implementation/primitives/pdf-dictionary.ts +0 -513
  145. package/dist/ts/implementation/primitives/pdf-name.ts +0 -218
  146. package/dist/ts/implementation/primitives/pdf-number.ts +0 -165
  147. package/dist/ts/implementation/primitives/pdf-reference.ts +0 -430
  148. package/dist/ts/implementation/primitives/pdf-stream.ts +0 -306
  149. package/dist/ts/implementation/primitives/pdf-string.ts +0 -397
  150. package/dist/ts/implementation/structured-elements/grid/layout/grid-layouter.ts +0 -2027
  151. package/dist/ts/implementation/structured-elements/grid/pdf-grid-cell.ts +0 -1193
  152. package/dist/ts/implementation/structured-elements/grid/pdf-grid-column.ts +0 -206
  153. package/dist/ts/implementation/structured-elements/grid/pdf-grid-row.ts +0 -470
  154. package/dist/ts/implementation/structured-elements/grid/pdf-grid.ts +0 -853
  155. package/dist/ts/implementation/structured-elements/grid/styles/pdf-borders.ts +0 -240
  156. package/dist/ts/implementation/structured-elements/grid/styles/style.ts +0 -424
  157. package/dist/ts/implementation/structured-elements/tables/light-tables/enum.ts +0 -16
  158. package/dist/ts/interfaces/i-pdf-cache.ts +0 -23
  159. package/dist/ts/interfaces/i-pdf-changable.ts +0 -17
  160. package/dist/ts/interfaces/i-pdf-clonable.ts +0 -12
  161. package/dist/ts/interfaces/i-pdf-primitives.ts +0 -45
  162. package/dist/ts/interfaces/i-pdf-true-type-font.ts +0 -48
  163. package/dist/ts/interfaces/i-pdf-wrapper.ts +0 -13
  164. package/dist/ts/interfaces/i-pdf-writer.ts +0 -29
@@ -1,524 +0,0 @@
1
- /**
2
- * PdfCrossTable.ts class for EJ2-PDF
3
- */
4
- import { PdfDocument } from './../document/pdf-document';
5
- import { PdfDocumentBase } from './../document/pdf-document-base';
6
- import { ObjectStatus } from './../input-output/enum';
7
- import { PdfWriter } from './pdf-writer';
8
- import { PdfDictionary } from './../primitives/pdf-dictionary';
9
- import { DictionaryProperties } from './pdf-dictionary-properties';
10
- import { Operators } from './pdf-operators';
11
- import { PdfMainObjectCollection, ObjectInfo } from './pdf-main-object-collection';
12
- import { Dictionary } from './../collections/dictionary';
13
- import { PdfReference, PdfReferenceHolder } from './../primitives/pdf-reference';
14
- import { ObjectType } from './cross-table';
15
- import { IPdfPrimitive } from './../../interfaces/i-pdf-primitives';
16
- import { PdfStream } from './../primitives/pdf-stream';
17
- import { PdfNumber } from './../primitives/pdf-number';
18
- import { PdfCatalog } from './../document/pdf-catalog';
19
- import { StreamWriter } from '@syncfusion/ej2-file-utils';
20
- /**
21
- * `PdfCrossTable` is responsible for intermediate level parsing
22
- * and savingof a PDF document.
23
- * @private
24
- */
25
- export class PdfCrossTable {
26
- /**
27
- * Parent `Document`.
28
- * @private
29
- */
30
- private pdfDocument : PdfDocumentBase;
31
- /**
32
- * Internal variable to store primtive objects of `main object collection`.
33
- * @private
34
- */
35
- private items : PdfMainObjectCollection;
36
- /**
37
- * The `mapped references`.
38
- * @private
39
- */
40
- private mappedReferences : Dictionary<PdfReference, PdfReference>;
41
- /**
42
- * The modified `objects` that should be saved.
43
- * @private
44
- */
45
- private objects : Dictionary<number, RegisteredObject> = new Dictionary<number, RegisteredObject>();
46
- /**
47
- * The `trailer` for a new document.
48
- * @private
49
- */
50
- private internalTrailer : IPdfPrimitive;
51
- /**
52
- * Internal variable to store if document `is being merged`.
53
- * @private
54
- */
55
- private merging : boolean;
56
- /**
57
- * `Flag` that forces an object to be 'a new'.
58
- * @private
59
- */
60
- private bForceNew : boolean;
61
- /**
62
- * Holds `maximal generation number` or offset to object.
63
- * @default 0
64
- * @private
65
- */
66
- private maxGenNumIndex : number = 0;
67
- /**
68
- * The `number of the objects`.
69
- * @default 0
70
- * @private
71
- */
72
- private objectCount : number = 0;
73
- /**
74
- * Internal variable for accessing fields from `DictionryProperties` class.
75
- * @default new PdfDictionaryProperties()
76
- * @private
77
- */
78
- private dictionaryProperties : DictionaryProperties = new DictionaryProperties();
79
- //Properties
80
- /**
81
- * Gets or sets if the document `is merged`.
82
- * @private
83
- */
84
- public get isMerging() : boolean {
85
- return this.merging;
86
- }
87
- public set isMerging(value : boolean) {
88
- this.merging = value;
89
- }
90
- /**
91
- * Gets the `trailer`.
92
- * @private
93
- */
94
- public get trailer() : PdfDictionary {
95
- if (this.internalTrailer == null) {
96
- this.internalTrailer = new PdfStream();
97
- }
98
- return <PdfDictionary>this.internalTrailer;
99
- }
100
- /**
101
- * Gets or sets the main `PdfDocument` class instance.
102
- * @private
103
- */
104
- public get document() : PdfDocumentBase {
105
- return this.pdfDocument;
106
- }
107
- public set document(value : PdfDocumentBase) {
108
- this.pdfDocument = value;
109
- this.items = this.pdfDocument.pdfObjects;
110
- }
111
- /**
112
- * Gets the catched `PDF object` main collection.
113
- * @private
114
- */
115
- public get pdfObjects() : PdfMainObjectCollection {
116
- return this.items;
117
- }
118
- /**
119
- * Gets the `object collection`.
120
- * @private
121
- */
122
- private get objectCollection() : PdfMainObjectCollection {
123
- return this.pdfDocument.pdfObjects;
124
- }
125
- /**
126
- * Gets or sets the `number of the objects` within the document.
127
- * @private
128
- */
129
- public get count() : number {
130
- return this.objectCount;
131
- }
132
- public set count(value : number) {
133
- this.objectCount = value;
134
- }
135
- /**
136
- * Returns `next available object number`.
137
- * @private
138
- */
139
- public get nextObjNumber() : number {
140
- this.count = this.count + 1;
141
- return this.count;
142
- }
143
- //Public methods
144
- /**
145
- * `Saves` the cross-reference table into the stream and return it as Blob.
146
- * @private
147
- */
148
- public save(writer : PdfWriter) : Blob
149
- /**
150
- * `Saves` the cross-reference table into the stream.
151
- * @private
152
- */
153
- public save(writer : PdfWriter, filename : string) : void
154
- public save(writer : PdfWriter, filename ?: string) : void | Blob {
155
- this.saveHead(writer);
156
- let state : boolean = false;
157
- this.mappedReferences = null;
158
- this.objects.clear();
159
- this.markTrailerReferences();
160
- this.saveObjects(writer);
161
- let saveCount : number = this.count;
162
- let xrefPos : number = writer.position;
163
- this.registerObject(0, new PdfReference(0, -1), true);
164
- let prevXRef : number = 0;
165
- writer.write(Operators.xref);
166
- writer.write(Operators.newLine);
167
- this.saveSections(writer);
168
- this.saveTrailer(writer, this.count, prevXRef);
169
- this.saveTheEndess(writer, xrefPos);
170
- this.count = saveCount;
171
- for (let i : number = 0; i < this.objectCollection.count; ++i) {
172
- let oi : ObjectInfo = this.objectCollection.items(i);
173
- oi.object.isSaving = false;
174
- }
175
- if (typeof filename === 'undefined') {
176
- return writer.stream.buffer;
177
- } else {
178
- writer.stream.save(filename);
179
- }
180
- }
181
- /**
182
- * `Saves the endess` of the file.
183
- * @private
184
- */
185
- private saveTheEndess(writer : PdfWriter, xrefPos : number) : void {
186
- writer.write(Operators.newLine + Operators.startxref + Operators.newLine);
187
- writer.write(xrefPos.toString() + Operators.newLine);
188
- writer.write(Operators.eof + Operators.newLine);
189
- }
190
- /**
191
- * `Saves the new trailer` dictionary.
192
- * @private
193
- */
194
- private saveTrailer(writer : PdfWriter, count : number, prevXRef : number) : void {
195
- writer.write(Operators.trailer + Operators.newLine);
196
- // Save the dictionary.
197
- let trailer : PdfDictionary = this.trailer;
198
- trailer.items.setValue(this.dictionaryProperties.size, new PdfNumber(this.objectCount + 1));
199
- trailer = new PdfDictionary(trailer); // Make it real dictionary.
200
- trailer.setEncrypt(false);
201
- trailer.save(writer);
202
- }
203
- /**
204
- * `Saves the xref section`.
205
- * @private
206
- */
207
- private saveSections(writer : PdfWriter) : void {
208
- let objectNum : number = 0;
209
- let count : number = 0;
210
- do {
211
- count = this.prepareSubsection(objectNum);
212
- this.saveSubsection(writer, objectNum, count);
213
- objectNum += count;
214
- } while (count !== 0);
215
- }
216
- /**
217
- * `Saves a subsection`.
218
- * @private
219
- */
220
- private saveSubsection(writer : PdfWriter, objectNum : number, count : number) : void {
221
- if (count <= 0 || objectNum >= this.count) {
222
- return;
223
- }
224
- let subsectionHead : string = '{0} {1}{2}';
225
- writer.write(objectNum + ' ' + (count + 1) + Operators.newLine);
226
- for (let i : number = objectNum; i <= objectNum + count; ++i) {
227
- let obj : RegisteredObject = this.objects.getValue(i) as RegisteredObject;
228
- let str : string = '';
229
- if ( obj.type === ObjectType.Free ) {
230
- str = this.getItem(obj.offset, 65535, true);
231
- } else {
232
- str = this.getItem(obj.offset, obj.generation, false);
233
- }
234
- writer.write(str);
235
- }
236
- }
237
- /**
238
- * Generates string for `xref table item`.
239
- * @private
240
- */
241
- public getItem(offset : number, genNumber : number, isFree : boolean) : string {
242
- let returnString : string = '';
243
- let addOffsetLength : number = 10 - offset.toString().length;
244
- if ( genNumber <= 0 ) {
245
- genNumber = 0;
246
- }
247
- let addGenNumberLength : number = (5 - genNumber.toString().length) <= 0 ? 0 : (5 - genNumber.toString().length);
248
- for (let index : number = 0; index < addOffsetLength; index++) {
249
- returnString = returnString + '0';
250
- }
251
- returnString = returnString + offset.toString() + ' ';
252
- for (let index : number = 0; index < addGenNumberLength; index++) {
253
- returnString = returnString + '0';
254
- }
255
- returnString = returnString + genNumber.toString() + ' ';
256
- returnString = returnString + ((isFree) ? Operators.f : Operators.n) + Operators.newLine;
257
- return returnString;
258
- }
259
- /**
260
- * `Prepares a subsection` of the current section within the cross-reference table.
261
- * @private
262
- */
263
- private prepareSubsection(objectNum : number) : number {
264
- let count : number = 0;
265
- let i : number;
266
- let total : number = this.count;
267
- for (let k : number = 0; k < this.document.pdfObjects.count; k++) {
268
- let reference : PdfReference = this.document.pdfObjects.items(k).reference;
269
- let refString : string = reference.toString();
270
- let refArray : string[] = refString.split(' ');
271
- }
272
- if (objectNum >= total) {
273
- return count;
274
- }
275
- // search for first changed indirect object.
276
- for (i = objectNum; i < total; ++i) {
277
- break;
278
- }
279
- objectNum = i;
280
- // look up for all indirect objects in one subsection.
281
- for (; i < total; ++i) {
282
- ++count;
283
- }
284
- return count;
285
- }
286
- /**
287
- * `Marks the trailer references` being saved.
288
- * @private
289
- */
290
- private markTrailerReferences() : void {
291
- let tempArray : IPdfPrimitive[];
292
- let keys : string[] = this.trailer.items.keys();
293
- let values : IPdfPrimitive[] = this.trailer.items.values();
294
- }
295
- /**
296
- * `Saves the head`.
297
- * @private
298
- */
299
- private saveHead(writer : PdfWriter) : void {
300
- let version : string = this.generateFileVersion(writer.document);
301
- writer.write('%PDF-' + version);
302
- writer.write(Operators.newLine);
303
- }
304
- /**
305
- * Generates the `version` of the file.
306
- * @private
307
- */
308
- private generateFileVersion(document : PdfDocumentBase) : string {
309
- let iVersion : number = 4;
310
- let version : string = '1.' + iVersion.toString();
311
- return version;
312
- }
313
- /**
314
- * Retrieves the `reference` of the object given.
315
- * @private
316
- */
317
- public getReference(obj : IPdfPrimitive) : PdfReference
318
- /**
319
- * Retrieves the `reference` of the object given.
320
- * @private
321
- */
322
- public getReference(obj : IPdfPrimitive, bNew : boolean) : PdfReference
323
- public getReference(obj : IPdfPrimitive, bNew? : boolean) : PdfReference {
324
- if (typeof bNew === 'undefined') {
325
- let wasNew : boolean = false;
326
- return this.getReference(obj, wasNew);
327
- } else {
328
- //code splitted for reducing lines of code exceeds 100.
329
- return this.getSubReference(obj, bNew);
330
- }
331
- }
332
- /**
333
- * Retrieves the `reference` of the object given.
334
- * @private
335
- */
336
- private getSubReference(obj : IPdfPrimitive, bNew : boolean) : PdfReference {
337
- let isNew : boolean = false;
338
- let wasNew : boolean;
339
- let reference : PdfReference = null;
340
- // if (obj.IsSaving) {
341
- if (this.items.count > 0 && obj.objectCollectionIndex > 0 && this.items.count > obj.objectCollectionIndex - 1) {
342
- let tempObj : {reference : PdfReference, wasNew : boolean} = this.document.pdfObjects.getReference(obj, wasNew);
343
- reference = tempObj.reference;
344
- wasNew = tempObj.wasNew;
345
- }
346
- if (reference == null) {
347
- if (obj.status === ObjectStatus.Registered) {
348
- wasNew = false;
349
- } else {
350
- wasNew = true;
351
- }
352
- } else {
353
- wasNew = false;
354
- }
355
- // need to add mapped reference code
356
- if (reference == null) {
357
- let objnumber : number = this.nextObjNumber;
358
- reference = new PdfReference(objnumber, 0);
359
- let found : boolean;
360
- if (wasNew) {
361
- this.document.pdfObjects.add(obj);
362
- this.document.pdfObjects.trySetReference(obj, reference, found);
363
- let tempIndex : number = this.document.pdfObjects.count - 1;
364
- let tempkey : number = this.document.pdfObjects.objectCollections[tempIndex].reference.objNumber;
365
- let tempvalue : ObjectInfo = this.document.pdfObjects.objectCollections[this.document.pdfObjects.count - 1];
366
- this.document.pdfObjects.mainObjectCollection.setValue(tempkey, tempvalue);
367
- obj.position = -1;
368
- } else {
369
- this.document.pdfObjects.trySetReference(obj, reference, found);
370
- }
371
- obj.objectCollectionIndex = <number>reference.objNumber;
372
- obj.status = ObjectStatus.None;
373
- isNew = true;
374
- }
375
- bNew = isNew || this.bForceNew;
376
- return reference;
377
- }
378
- /**
379
- * `Saves all objects` in the collection.
380
- * @private
381
- */
382
- private saveObjects(writer : PdfWriter) : void {
383
- let objectCollection : PdfMainObjectCollection = this.objectCollection;
384
- for (let i : number = 0; i < objectCollection.count; ++i) {
385
- let oi : ObjectInfo = objectCollection.items(i);
386
- let obj : IPdfPrimitive = oi.object;
387
- obj.isSaving = true;
388
- this.saveIndirectObject(obj, writer);
389
- }
390
- }
391
- /**
392
- * `Saves indirect object`.
393
- * @private
394
- */
395
- public saveIndirectObject(obj : IPdfPrimitive, writer : PdfWriter) : void {
396
- let reference : PdfReference = this.getReference(obj);
397
- if (obj instanceof PdfCatalog) {
398
- this.trailer.items.setValue(this.dictionaryProperties.root, reference);
399
- }
400
- // NOTE : This is needed for correct string objects encryption.
401
- this.pdfDocument.currentSavingObj = reference;
402
- let tempArchive : boolean = false;
403
- tempArchive = (<PdfDictionary>obj).getArchive();
404
- let allowedType : boolean = !((obj instanceof PdfStream) || !tempArchive || (obj instanceof PdfCatalog));
405
- let sigFlag : boolean = false;
406
- this.registerObject(writer.position, reference);
407
- this.doSaveObject(obj, reference, writer);
408
- }
409
- /**
410
- * Performs `real saving` of the save object.
411
- * @private
412
- */
413
- private doSaveObject(obj : IPdfPrimitive, reference : PdfReference, writer : PdfWriter) : void {
414
- let correctPosition : number = writer.length;
415
- writer.write(reference.objNumber.toString());
416
- writer.write(Operators.whiteSpace);
417
- writer.write(reference.genNumber.toString());
418
- writer.write(Operators.whiteSpace);
419
- writer.write(Operators.obj);
420
- writer.write(Operators.newLine);
421
- obj.save(writer);
422
- let stream : StreamWriter = writer.stream;
423
- writer.write(Operators.endObj);
424
- writer.write(Operators.newLine);
425
- }
426
- /**
427
- * `Registers` an archived object.
428
- * @private
429
- */
430
- public registerObject(offset : number, reference : PdfReference) : void
431
- /**
432
- * `Registers` the object in the cross reference table.
433
- * @private
434
- */
435
- public registerObject(offset : number, reference : PdfReference, free : boolean) : void
436
- public registerObject(offset? : number, reference? : PdfReference, free? : boolean) : void {
437
- if (typeof free === 'boolean') {
438
- // Register the object by its number.
439
- this.objects.setValue(reference.objNumber, new RegisteredObject(<number>offset, reference, free));
440
- this.maxGenNumIndex = Math.max(this.maxGenNumIndex, reference.genNumber);
441
- } else if (typeof free === 'undefined') {
442
- // Register the object by its number.
443
- this.objects.setValue(reference.objNumber, new RegisteredObject(offset, reference));
444
- this.maxGenNumIndex = Math.max(this.maxGenNumIndex, reference.genNumber);
445
- }
446
- }
447
- /**
448
- * `Dereferences` the specified primitive object.
449
- * @private
450
- */
451
- public static dereference(obj : IPdfPrimitive) : IPdfPrimitive {
452
- let rh : PdfReferenceHolder = obj as PdfReferenceHolder;
453
- if (rh != null) {
454
- obj = rh.object;
455
- }
456
- return obj;
457
- }
458
- }
459
- export class RegisteredObject {
460
- /**
461
- * The `object number` of the indirect object.
462
- * @private
463
- */
464
- private object : number;
465
- /**
466
- * The `generation number` of the indirect object.
467
- * @private
468
- */
469
- public generation : number;
470
- /**
471
- * The `offset` of the indirect object within the file.
472
- * @private
473
- */
474
- private offsetNumber : number;
475
- /**
476
- * Shows if the object `is free`.
477
- * @private
478
- */
479
- public type : ObjectType;
480
- /**
481
- * Holds the current `cross-reference` table.
482
- * @private
483
- */
484
- private xrefTable : PdfCrossTable;
485
- //Properties
486
- /**
487
- * Gets the `object number`.
488
- * @private
489
- */
490
- public get objectNumber() : number {
491
- return this.object;
492
- }
493
- /**
494
- * Gets the `offset`.
495
- * @private
496
- */
497
- public get offset() : number {
498
- let result : number;
499
- result = this.offsetNumber;
500
- return result;
501
- }
502
- /**
503
- * Initialize the `structure` with the proper values.
504
- * @private
505
- */
506
- public constructor(offset : number, reference : PdfReference)
507
- /**
508
- * Initialize the `structure` with the proper values.
509
- * @private
510
- */
511
- public constructor(offset : number, reference : PdfReference, free : boolean)
512
- public constructor(offset : number|PdfCrossTable, reference : PdfReference, free? : boolean|PdfReference) {
513
- let tempOffset : number = <number>offset;
514
- this.offsetNumber = tempOffset;
515
- let tempReference : PdfReference = <PdfReference>reference;
516
- this.generation = tempReference.genNumber;
517
- this.object = tempReference.objNumber;
518
- if (typeof free === 'undefined') {
519
- this.type = ObjectType.Normal;
520
- } else {
521
- this.type = ObjectType.Free;
522
- }
523
- }
524
- }