@syncfusion/ej2-pdf-export 20.2.45 → 20.3.47
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.
- package/dist/ej2-pdf-export.min.js +10 -0
- package/dist/ej2-pdf-export.umd.min.js +1 -1
- package/dist/global/ej2-pdf-export.min.js +1 -1
- package/dist/global/index.d.ts +1 -1
- package/dist/ts/implementation/actions/action.ts +76 -0
- package/dist/ts/implementation/actions/uri-action.ts +52 -0
- package/dist/ts/implementation/annotations/action-link-annotation.ts +43 -0
- package/dist/ts/implementation/annotations/annotation-collection.ts +159 -0
- package/dist/ts/implementation/annotations/annotation.ts +241 -0
- package/dist/ts/implementation/annotations/document-link-annotation.ts +118 -0
- package/dist/ts/implementation/annotations/link-annotation.ts +32 -0
- package/dist/ts/implementation/annotations/pdf-text-web-link.ts +265 -0
- package/dist/ts/implementation/annotations/uri-annotation.ts +86 -0
- package/dist/ts/implementation/collections/dictionary.ts +150 -0
- package/dist/ts/implementation/collections/object-object-pair/dictionary.ts +125 -0
- package/dist/ts/implementation/collections/utils.ts +38 -0
- package/dist/ts/implementation/document/automatic-fields/automatic-field-info-collection.ts +39 -0
- package/dist/ts/implementation/document/automatic-fields/automatic-field-info.ts +108 -0
- package/dist/ts/implementation/document/automatic-fields/automatic-field.ts +127 -0
- package/dist/ts/implementation/document/automatic-fields/composite-field.ts +76 -0
- package/dist/ts/implementation/document/automatic-fields/multiple-value-field.ts +37 -0
- package/dist/ts/implementation/document/automatic-fields/page-count-field.ts +75 -0
- package/dist/ts/implementation/document/automatic-fields/pdf-numbers-convertor.ts +157 -0
- package/dist/ts/implementation/document/automatic-fields/pdf-page-number-field.ts +82 -0
- package/dist/ts/implementation/document/automatic-fields/pdf-template-value-pair.ts +60 -0
- package/dist/ts/implementation/document/automatic-fields/single-value-field.ts +48 -0
- package/dist/ts/implementation/document/pdf-catalog.ts +52 -0
- package/dist/ts/implementation/document/pdf-document-base.ts +166 -0
- package/dist/ts/implementation/document/pdf-document-template.ts +310 -0
- package/dist/ts/implementation/document/pdf-document.ts +342 -0
- package/dist/ts/implementation/drawing/pdf-drawing.ts +218 -0
- package/dist/ts/implementation/general/enum.ts +21 -0
- package/dist/ts/implementation/general/functions/pdf-function.ts +66 -0
- package/dist/ts/implementation/general/functions/pdf-sampled-function.ts +62 -0
- package/dist/ts/implementation/general/pdf-cache-collection.ts +97 -0
- package/dist/ts/implementation/general/pdf-collection.ts +41 -0
- package/dist/ts/implementation/general/pdf-destination.ts +170 -0
- package/dist/ts/implementation/graphics/brushes/enum.ts +237 -0
- package/dist/ts/implementation/graphics/brushes/pdf-blend.ts +294 -0
- package/dist/ts/implementation/graphics/brushes/pdf-brush.ts +68 -0
- package/dist/ts/implementation/graphics/brushes/pdf-brushes.ts +2438 -0
- package/dist/ts/implementation/graphics/brushes/pdf-color-blend.ts +295 -0
- package/dist/ts/implementation/graphics/brushes/pdf-gradient-brush.ts +311 -0
- package/dist/ts/implementation/graphics/brushes/pdf-linear-gradient-brush.ts +406 -0
- package/dist/ts/implementation/graphics/brushes/pdf-radial-gradient-brush.ts +290 -0
- package/dist/ts/implementation/graphics/brushes/pdf-solid-brush.ts +107 -0
- package/dist/ts/implementation/graphics/brushes/pdf-tiling-brush.ts +304 -0
- package/dist/ts/implementation/graphics/constants.ts +31 -0
- package/dist/ts/implementation/graphics/enum.ts +413 -0
- package/dist/ts/implementation/graphics/figures/arc.ts +133 -0
- package/dist/ts/implementation/graphics/figures/base/draw-element.ts +59 -0
- package/dist/ts/implementation/graphics/figures/base/element-layouter.ts +260 -0
- package/dist/ts/implementation/graphics/figures/base/fill-element.ts +72 -0
- package/dist/ts/implementation/graphics/figures/base/graphics-element.ts +34 -0
- package/dist/ts/implementation/graphics/figures/base/pdf-shape-element.ts +69 -0
- package/dist/ts/implementation/graphics/figures/base/shape-layouter.ts +276 -0
- package/dist/ts/implementation/graphics/figures/base/text-layouter.ts +205 -0
- package/dist/ts/implementation/graphics/figures/ellipse-part.ts +76 -0
- package/dist/ts/implementation/graphics/figures/enum.ts +80 -0
- package/dist/ts/implementation/graphics/figures/layout-element.ts +132 -0
- package/dist/ts/implementation/graphics/figures/path.ts +646 -0
- package/dist/ts/implementation/graphics/figures/pdf-template.ts +205 -0
- package/dist/ts/implementation/graphics/figures/rectangle-area.ts +108 -0
- package/dist/ts/implementation/graphics/figures/text-element.ts +445 -0
- package/dist/ts/implementation/graphics/fonts/enum.ts +385 -0
- package/dist/ts/implementation/graphics/fonts/pdf-font-metrics.ts +248 -0
- package/dist/ts/implementation/graphics/fonts/pdf-font.ts +316 -0
- package/dist/ts/implementation/graphics/fonts/pdf-standard-font-metrics-factory.ts +606 -0
- package/dist/ts/implementation/graphics/fonts/pdf-standard-font.ts +243 -0
- package/dist/ts/implementation/graphics/fonts/pdf-string-format.ts +474 -0
- package/dist/ts/implementation/graphics/fonts/pdf-true-type-font.ts +165 -0
- package/dist/ts/implementation/graphics/fonts/rtl/rtl-bidirectional.ts +958 -0
- package/dist/ts/implementation/graphics/fonts/rtl/rtl-text-shape.ts +374 -0
- package/dist/ts/implementation/graphics/fonts/rtl-renderer.ts +255 -0
- package/dist/ts/implementation/graphics/fonts/string-layouter.ts +617 -0
- package/dist/ts/implementation/graphics/fonts/string-tokenizer.ts +275 -0
- package/dist/ts/implementation/graphics/fonts/ttf-OS2-Table.ts +206 -0
- package/dist/ts/implementation/graphics/fonts/ttf-apple-cmap-sub-table.ts +18 -0
- package/dist/ts/implementation/graphics/fonts/ttf-cmap-sub-table.ts +18 -0
- package/dist/ts/implementation/graphics/fonts/ttf-cmap-table.ts +14 -0
- package/dist/ts/implementation/graphics/fonts/ttf-glyph-header.ts +26 -0
- package/dist/ts/implementation/graphics/fonts/ttf-glyph-info.ts +35 -0
- package/dist/ts/implementation/graphics/fonts/ttf-head-table.ts +94 -0
- package/dist/ts/implementation/graphics/fonts/ttf-horizontal-header-table.ts +56 -0
- package/dist/ts/implementation/graphics/fonts/ttf-loca-table.ts +10 -0
- package/dist/ts/implementation/graphics/fonts/ttf-long-hor-metric.ts +14 -0
- package/dist/ts/implementation/graphics/fonts/ttf-metrics.ts +106 -0
- package/dist/ts/implementation/graphics/fonts/ttf-microsoft-cmap-sub-table.ts +58 -0
- package/dist/ts/implementation/graphics/fonts/ttf-name-record.ts +33 -0
- package/dist/ts/implementation/graphics/fonts/ttf-name-table.ts +22 -0
- package/dist/ts/implementation/graphics/fonts/ttf-post-table.ts +42 -0
- package/dist/ts/implementation/graphics/fonts/ttf-reader.ts +1254 -0
- package/dist/ts/implementation/graphics/fonts/ttf-table-info.ts +26 -0
- package/dist/ts/implementation/graphics/fonts/ttf-trimmed-cmap-sub-table.ts +26 -0
- package/dist/ts/implementation/graphics/fonts/unicode-true-type-font.ts +577 -0
- package/dist/ts/implementation/graphics/images/byte-array.ts +137 -0
- package/dist/ts/implementation/graphics/images/image-decoder.ts +437 -0
- package/dist/ts/implementation/graphics/images/pdf-bitmap.ts +110 -0
- package/dist/ts/implementation/graphics/images/pdf-image.ts +132 -0
- package/dist/ts/implementation/graphics/pdf-color.ts +478 -0
- package/dist/ts/implementation/graphics/pdf-graphics.ts +2424 -0
- package/dist/ts/implementation/graphics/pdf-margins.ts +124 -0
- package/dist/ts/implementation/graphics/pdf-pen.ts +370 -0
- package/dist/ts/implementation/graphics/pdf-resources.ts +300 -0
- package/dist/ts/implementation/graphics/pdf-transformation-matrix.ts +246 -0
- package/dist/ts/implementation/graphics/pdf-transparency.ts +93 -0
- package/dist/ts/implementation/graphics/unit-convertor.ts +96 -0
- package/dist/ts/implementation/input-output/big-endian-writer.ts +121 -0
- package/dist/ts/implementation/input-output/cross-table.ts +21 -0
- package/dist/ts/implementation/input-output/enum.ts +16 -0
- package/dist/ts/implementation/input-output/pdf-cross-table.ts +524 -0
- package/dist/ts/implementation/input-output/pdf-dictionary-properties.ts +515 -0
- package/dist/ts/implementation/input-output/pdf-main-object-collection.ts +194 -0
- package/dist/ts/implementation/input-output/pdf-operators.ts +363 -0
- package/dist/ts/implementation/input-output/pdf-stream-writer.ts +681 -0
- package/dist/ts/implementation/input-output/pdf-writer.ts +88 -0
- package/dist/ts/implementation/pages/enum.ts +201 -0
- package/dist/ts/implementation/pages/page-added-event-arguments.ts +39 -0
- package/dist/ts/implementation/pages/pdf-document-page-collection.ts +180 -0
- package/dist/ts/implementation/pages/pdf-page-base.ts +181 -0
- package/dist/ts/implementation/pages/pdf-page-layer-collection.ts +348 -0
- package/dist/ts/implementation/pages/pdf-page-layer.ts +271 -0
- package/dist/ts/implementation/pages/pdf-page-settings.ts +192 -0
- package/dist/ts/implementation/pages/pdf-page-size.ts +162 -0
- package/dist/ts/implementation/pages/pdf-page-template-element.ts +659 -0
- package/dist/ts/implementation/pages/pdf-page.ts +235 -0
- package/dist/ts/implementation/pages/pdf-section-collection.ts +187 -0
- package/dist/ts/implementation/pages/pdf-section-page-collection.ts +61 -0
- package/dist/ts/implementation/pages/pdf-section-templates.ts +96 -0
- package/dist/ts/implementation/pages/pdf-section.ts +644 -0
- package/dist/ts/implementation/primitives/pdf-array.ts +386 -0
- package/dist/ts/implementation/primitives/pdf-boolean.ts +119 -0
- package/dist/ts/implementation/primitives/pdf-dictionary.ts +513 -0
- package/dist/ts/implementation/primitives/pdf-name.ts +218 -0
- package/dist/ts/implementation/primitives/pdf-number.ts +165 -0
- package/dist/ts/implementation/primitives/pdf-reference.ts +430 -0
- package/dist/ts/implementation/primitives/pdf-stream.ts +336 -0
- package/dist/ts/implementation/primitives/pdf-string.ts +397 -0
- package/dist/ts/implementation/structured-elements/grid/layout/grid-layouter.ts +2027 -0
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-cell.ts +1189 -0
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-column.ts +206 -0
- package/dist/ts/implementation/structured-elements/grid/pdf-grid-row.ts +470 -0
- package/dist/ts/implementation/structured-elements/grid/pdf-grid.ts +853 -0
- package/dist/ts/implementation/structured-elements/grid/styles/pdf-borders.ts +240 -0
- package/dist/ts/implementation/structured-elements/grid/styles/style.ts +424 -0
- package/dist/ts/implementation/structured-elements/tables/light-tables/enum.ts +16 -0
- package/dist/ts/interfaces/i-pdf-cache.ts +23 -0
- package/dist/ts/interfaces/i-pdf-changable.ts +17 -0
- package/dist/ts/interfaces/i-pdf-clonable.ts +12 -0
- package/dist/ts/interfaces/i-pdf-primitives.ts +45 -0
- package/dist/ts/interfaces/i-pdf-true-type-font.ts +48 -0
- package/dist/ts/interfaces/i-pdf-wrapper.ts +13 -0
- package/dist/ts/interfaces/i-pdf-writer.ts +29 -0
- package/package.json +8 -7
|
@@ -0,0 +1,524 @@
|
|
|
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
|
+
}
|