@syncfusion/ej2-pdf-data-extract 31.1.17 → 31.1.18

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 (60) hide show
  1. package/dist/ej2-pdf-data-extract.umd.min.js +1 -1
  2. package/dist/global/ej2-pdf-data-extract.min.js +1 -1
  3. package/dist/global/index.d.ts +1 -1
  4. package/package.json +12 -44
  5. package/dist/ts/index.d.ts +0 -23
  6. package/dist/ts/index.ts +0 -23
  7. package/dist/ts/pdf-data-extract/core/content-parser-helper.d.ts +0 -62
  8. package/dist/ts/pdf-data-extract/core/content-parser-helper.ts +0 -661
  9. package/dist/ts/pdf-data-extract/core/enum.d.ts +0 -6
  10. package/dist/ts/pdf-data-extract/core/enum.ts +0 -6
  11. package/dist/ts/pdf-data-extract/core/graphic-state.d.ts +0 -33
  12. package/dist/ts/pdf-data-extract/core/graphic-state.ts +0 -106
  13. package/dist/ts/pdf-data-extract/core/pdf-data-extractor.d.ts +0 -210
  14. package/dist/ts/pdf-data-extract/core/pdf-data-extractor.ts +0 -998
  15. package/dist/ts/pdf-data-extract/core/pdf-text-parser.d.ts +0 -63
  16. package/dist/ts/pdf-data-extract/core/pdf-text-parser.ts +0 -498
  17. package/dist/ts/pdf-data-extract/core/redaction/index.d.ts +0 -7
  18. package/dist/ts/pdf-data-extract/core/redaction/index.ts +0 -7
  19. package/dist/ts/pdf-data-extract/core/redaction/pdf-path-segment.d.ts +0 -24
  20. package/dist/ts/pdf-data-extract/core/redaction/pdf-path-segment.ts +0 -59
  21. package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-processor.d.ts +0 -55
  22. package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-processor.ts +0 -590
  23. package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-region.d.ts +0 -281
  24. package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-region.ts +0 -342
  25. package/dist/ts/pdf-data-extract/core/redaction/pdf-redactor.d.ts +0 -172
  26. package/dist/ts/pdf-data-extract/core/redaction/pdf-redactor.ts +0 -414
  27. package/dist/ts/pdf-data-extract/core/redaction/pdf-shape-redaction.d.ts +0 -45
  28. package/dist/ts/pdf-data-extract/core/redaction/pdf-shape-redaction.ts +0 -281
  29. package/dist/ts/pdf-data-extract/core/redaction/shape-parser-helper.d.ts +0 -32
  30. package/dist/ts/pdf-data-extract/core/redaction/shape-parser-helper.ts +0 -479
  31. package/dist/ts/pdf-data-extract/core/redaction/text-glyph-mapper.d.ts +0 -12
  32. package/dist/ts/pdf-data-extract/core/redaction/text-glyph-mapper.ts +0 -153
  33. package/dist/ts/pdf-data-extract/core/text-extraction/binary-cmap-reader.d.ts +0 -24
  34. package/dist/ts/pdf-data-extract/core/text-extraction/binary-cmap-reader.ts +0 -281
  35. package/dist/ts/pdf-data-extract/core/text-extraction/cmap.d.ts +0 -50
  36. package/dist/ts/pdf-data-extract/core/text-extraction/cmap.ts +0 -565
  37. package/dist/ts/pdf-data-extract/core/text-extraction/compact-font-parser.d.ts +0 -191
  38. package/dist/ts/pdf-data-extract/core/text-extraction/compact-font-parser.ts +0 -1928
  39. package/dist/ts/pdf-data-extract/core/text-extraction/encoding-utils.d.ts +0 -102
  40. package/dist/ts/pdf-data-extract/core/text-extraction/encoding-utils.ts +0 -5780
  41. package/dist/ts/pdf-data-extract/core/text-extraction/font-structure.d.ts +0 -167
  42. package/dist/ts/pdf-data-extract/core/text-extraction/font-structure.ts +0 -1842
  43. package/dist/ts/pdf-data-extract/core/text-extraction/font-tables.d.ts +0 -5
  44. package/dist/ts/pdf-data-extract/core/text-extraction/font-tables.ts +0 -16
  45. package/dist/ts/pdf-data-extract/core/text-extraction/font-utils.d.ts +0 -18
  46. package/dist/ts/pdf-data-extract/core/text-extraction/font-utils.ts +0 -630
  47. package/dist/ts/pdf-data-extract/core/text-extraction/glyph.d.ts +0 -93
  48. package/dist/ts/pdf-data-extract/core/text-extraction/glyph.ts +0 -622
  49. package/dist/ts/pdf-data-extract/core/text-extraction/index.d.ts +0 -10
  50. package/dist/ts/pdf-data-extract/core/text-extraction/index.ts +0 -10
  51. package/dist/ts/pdf-data-extract/core/text-extraction/matrix-helper.d.ts +0 -38
  52. package/dist/ts/pdf-data-extract/core/text-extraction/matrix-helper.ts +0 -150
  53. package/dist/ts/pdf-data-extract/core/text-extraction/metrics.d.ts +0 -16
  54. package/dist/ts/pdf-data-extract/core/text-extraction/metrics.ts +0 -2938
  55. package/dist/ts/pdf-data-extract/core/text-structure.d.ts +0 -628
  56. package/dist/ts/pdf-data-extract/core/text-structure.ts +0 -668
  57. package/dist/ts/pdf-data-extract/core/utils.d.ts +0 -99
  58. package/dist/ts/pdf-data-extract/core/utils.ts +0 -626
  59. package/dist/ts/pdf-data-extract/index.d.ts +0 -23
  60. package/dist/ts/pdf-data-extract/index.ts +0 -23
@@ -1,55 +0,0 @@
1
- import { _PdfAnnotationType, _PdfContentStream, _PdfDictionary, PdfDocument, PdfPage } from '@syncfusion/ej2-pdf';
2
- import { PdfRedactionRegion } from './pdf-redaction-region';
3
- export declare class _PdfRedactionProcessor {
4
- _updateContentStream(page: PdfPage, stream: _PdfContentStream, options: PdfRedactionRegion[], document: PdfDocument): void;
5
- _processFormFields(page: PdfPage, options: PdfRedactionRegion[], document: PdfDocument): void;
6
- _isFound(values: number[], redactionBounds: {
7
- x: number;
8
- y: number;
9
- width: number;
10
- height: number;
11
- }): boolean;
12
- _intersectsWith(rect1: {
13
- x: number;
14
- y: number;
15
- width: number;
16
- height: number;
17
- }, rect2: {
18
- x: number;
19
- y: number;
20
- width: number;
21
- height: number;
22
- }): boolean;
23
- _isEmptyRectangle(width: number, height: number): boolean;
24
- _toRectangle(x: number, y: number, width: number, height: number): number[];
25
- _isKidInSamePage(kid: _PdfDictionary, page: PdfPage): boolean;
26
- _processAnnotation(page: PdfPage, options: PdfRedactionRegion[]): void;
27
- _getBoundsFromPoints(points: number[], loadedPage: PdfPage): {
28
- bounds: {
29
- x: number;
30
- y: number;
31
- width: number;
32
- height: number;
33
- };
34
- isValidAnnotation: boolean;
35
- };
36
- _isLineIntersectRectangle(redactBounds: {
37
- x: number;
38
- y: number;
39
- width: number;
40
- height: number;
41
- }, p1X: number, p1Y: number, p2X: number, p2Y: number): boolean;
42
- _isBoundsEqual(bounds1: {
43
- x: number;
44
- y: number;
45
- width: number;
46
- height: number;
47
- }, bounds2: {
48
- x: number;
49
- y: number;
50
- width: number;
51
- height: number;
52
- }): boolean;
53
- _getAnnotationType(dictionary: _PdfDictionary): _PdfAnnotationType;
54
- _findAnnotation(array: any[]): boolean;
55
- }
@@ -1,590 +0,0 @@
1
- import { _FieldFlag, _getInheritableProperty, _PdfAnnotationType, _PdfBaseStream, _PdfContentStream, _PdfDictionary, _PdfName, _PdfReference, PdfAnnotation, PdfBrush, PdfButtonField, PdfCheckBoxField, PdfComboBoxField, PdfDocument, PdfField, PdfForm, PdfInkAnnotation, PdfLineAnnotation, PdfListBoxField, PdfPage, PdfPolygonAnnotation, PdfPolyLineAnnotation, PdfRadioButtonListField, PdfSignatureField, PdfTextBoxField, PdfTextMarkupAnnotation } from '@syncfusion/ej2-pdf';
2
- import { PdfRedactionRegion } from './pdf-redaction-region';
3
- export class _PdfRedactionProcessor {
4
- _updateContentStream(page: PdfPage, stream: _PdfContentStream, options: PdfRedactionRegion[], document: PdfDocument): void {
5
- if (typeof(stream) !== 'undefined' && page._pageDictionary.has('Contents')) {
6
- let contents: any = page._pageDictionary.getRaw('Contents'); // eslint-disable-line
7
- let content: Array<_PdfReference>;
8
- let ref: _PdfReference;
9
- if (contents !== null && typeof contents !== 'undefined' && contents instanceof _PdfReference) {
10
- ref = contents;
11
- contents = page._crossReference._fetch(ref);
12
- }
13
- if (contents && contents instanceof _PdfBaseStream) {
14
- content = [ref];
15
- } else if (contents && Array.isArray(contents)) {
16
- content = contents;
17
- } else {
18
- content = [];
19
- }
20
- for (let i: number = 0; i < content.length; i++) {
21
- const reference: any = content[Number.parseInt(i.toString(), 10)]; // eslint-disable-line
22
- page._crossReference._cacheMap.delete(reference);
23
- }
24
- const restoreReference: _PdfReference = page._crossReference._getNextReference();
25
- page._crossReference._cacheMap.set(restoreReference, stream);
26
- const pageContent: Array<_PdfReference> = [];
27
- pageContent.push(restoreReference);
28
- page._pageDictionary.set('Contents', pageContent);
29
- page._pageDictionary._updated = true;
30
- }
31
- this._processAnnotation(page, options);
32
- this._processFormFields(page, options, document);
33
- for (let i: number = 0; i < options.length; i++) {
34
- const bounds: {x: number, y: number, width: number, height: number} = options[Number.parseInt(i.toString(), 10)].bounds;
35
- if (options[Number.parseInt(i.toString(), 10)]._appearanceEnabled) {
36
- options[Number.parseInt(i.toString(), 10)].appearance.normal._isNew = true;
37
- page.graphics.drawTemplate(options[Number.parseInt(i.toString(), 10)].appearance.normal,
38
- bounds);
39
- } else if (options[Number.parseInt(i.toString(), 10)].fillColor) {
40
- page.graphics.drawRectangle(bounds.x, bounds.y, bounds.width, bounds.height,
41
- new PdfBrush(options[Number.parseInt(i.toString(), 10)].fillColor));
42
- }
43
- }
44
- }
45
- _processFormFields(page: PdfPage, options: PdfRedactionRegion[], document: PdfDocument): void {
46
- const form: PdfForm = document.form;
47
- let isValidField: boolean = true;
48
- if (form) {
49
- for (let i: number = 0; i < form.count; i++) {
50
- const field: PdfField = form. fieldAt(i);
51
- if (field && field.page !== page) {
52
- continue;
53
- }
54
- const key: _PdfName = _getInheritableProperty(field._dictionary, 'FT', false, true, 'Parent');
55
- let fieldFlags: number = 0;
56
- let bounds: any; // eslint-disable-line
57
- const flag: number = _getInheritableProperty(field._dictionary, 'Ff', false, true, 'Parent');
58
- if (typeof flag !== 'undefined') {
59
- fieldFlags = flag;
60
- }
61
- let kids: any[]; // eslint-disable-line
62
- switch (key.name.toLowerCase()) {
63
- case 'tx':
64
- kids = field._dictionary.getRaw('Kids');
65
- if (kids && kids.length > 1) {
66
- for (let i: number = 0; i < kids.length; i++) {
67
- const kidsDictionary: _PdfDictionary = document._crossReference._fetch(kids[Number.parseInt(i.toString(), 10)]);
68
- if (kidsDictionary.has('Rect')) {
69
- const rectangle: any = kidsDictionary.getArray('Rect'); // eslint-disable-line
70
- if (rectangle) {
71
- bounds = this._toRectangle(rectangle[0], rectangle[1], rectangle[2], rectangle[3]);
72
- bounds[1] = (page.graphics._size[1] - (bounds[1] + bounds[3]));
73
- }
74
- const emptyRectangle: boolean = this._isEmptyRectangle(bounds[2], bounds[3]);
75
- if (!emptyRectangle) {
76
- for (let j: number = 0; j < options.length; j++) {
77
- if (this._isFound(bounds, options[Number.parseInt(j.toString(), 10)].bounds) &&
78
- this._isKidInSamePage(kidsDictionary, page)) {
79
- if (page._pageDictionary.has('Annots')) {
80
- let annots: any = page._pageDictionary.getRaw('Annots'); // eslint-disable-line
81
- if (annots instanceof _PdfReference) {
82
- const values: any = document._crossReference._fetch(annots); // eslint-disable-line
83
- annots = values;
84
- }
85
- const index: number = annots.indexOf(kids[Number.parseInt(i.toString(), 10)]);
86
- annots.splice(index, 1);
87
- page._pageDictionary._updated = true;
88
- }
89
- isValidField = false;
90
- }
91
- }
92
- }
93
- }
94
- }
95
- } else {
96
- bounds = (field as PdfTextBoxField).bounds;
97
- }
98
- break;
99
- case 'btn':
100
- if ((fieldFlags & _FieldFlag.pushButton) !== 0) {
101
- bounds = (field as PdfButtonField).bounds;
102
- } else if ((fieldFlags & _FieldFlag.radio) !== 0) {
103
- kids = field._dictionary.getRaw('Kids');
104
- if (kids && kids.length > 0) {
105
- for (let i: number = 0; i < kids.length; i++) {
106
- const kidsDictionary: _PdfDictionary = document._crossReference._fetch(
107
- kids[Number.parseInt(i.toString(), 10)]);
108
- if (kidsDictionary.has('Rect')) {
109
- const rectangle: any = kidsDictionary.getArray('Rect'); // eslint-disable-line
110
- if (rectangle) {
111
- bounds = this._toRectangle(rectangle[0], rectangle[1], rectangle[2], rectangle[3]);
112
- bounds[1] = (page.graphics._size[1] - (bounds[1] + bounds[3]));
113
- }
114
- const emptyRectangle: boolean = this._isEmptyRectangle(bounds[2], bounds[3]);
115
- if (!emptyRectangle) {
116
- for (let j: number = 0; j < options.length; j++) {
117
- if (this._isFound(bounds, options[Number.parseInt(j.toString(), 10)].bounds)) {
118
- if (page._pageDictionary.has('Annots')) {
119
- let annots: any[] = page._pageDictionary.getRaw('Annots'); // eslint-disable-line
120
- if (annots instanceof _PdfReference) {
121
- const values: any = document._crossReference._fetch(annots); // eslint-disable-line
122
- annots = values;
123
- }
124
- const index: number = annots.indexOf(kids[Number.parseInt(i.toString(), 10)]);
125
- annots.splice(index, 1);
126
- page._pageDictionary._updated = true;
127
- }
128
- }
129
- }
130
- }
131
- }
132
- }
133
- } else {
134
- bounds = (field as PdfRadioButtonListField).bounds;
135
- }
136
- } else {
137
- bounds = (field as PdfCheckBoxField).bounds;
138
- }
139
- break;
140
- case 'ch':
141
- if ((fieldFlags & _FieldFlag.combo) !== 0) {
142
- bounds = (field as PdfComboBoxField).bounds;
143
- } else {
144
- bounds = (field as PdfListBoxField).bounds;
145
- }
146
- break;
147
- case 'sig':
148
- bounds = (field as PdfSignatureField).bounds;
149
- break;
150
- }
151
- if (!Array.isArray(bounds)) {
152
- bounds = [bounds.x, bounds.y, bounds.width, bounds.height];
153
- }
154
- const emptyBounds: boolean = this._isEmptyRectangle(bounds.width, bounds.height);
155
- if (isValidField && !emptyBounds) {
156
- for (let j: number = 0; j < options.length; j++) {
157
- if (this._isFound(bounds, options[Number.parseInt(j.toString(), 10)].bounds)) {
158
- form.removeFieldAt(i);
159
- i--;
160
- break;
161
- }
162
- }
163
- }
164
- isValidField = true;
165
- }
166
- }
167
- }
168
- _isFound(values: number[], redactionBounds: {x: number, y: number, width: number, height: number}): boolean {
169
- const rectangle: {x: number, y: number, width: number, height: number} = {x: values[0], y: values[1], width: values[2],
170
- height: values[3]};
171
- if (this._intersectsWith(redactionBounds, rectangle)) {
172
- return true;
173
- }
174
- return false;
175
- }
176
- _intersectsWith(rect1: {x: number, y: number, width: number, height: number}, rect2: {x: number, y: number, width: number,
177
- height: number}): boolean {
178
- return (rect2.x < rect1.x + rect1.width) && (rect1.x < (rect2.x + rect2.width)) && (rect2.y < rect1.y + rect1.height) &&
179
- (rect1.y < rect2.y + rect2.height);
180
- }
181
- _isEmptyRectangle(width: number, height: number): boolean {
182
- return (width <= 0 || height <= 0);
183
- }
184
- _toRectangle(x: number, y: number, width: number, height: number): number[] {
185
- const x1: number = Math.min(x, width);
186
- const y1: number = Math.min(y, height);
187
- const x2: number = Math.abs(x - width);
188
- const y2: number = Math.abs(y - height);
189
- const bounds: number[] = [x1, y1, x2, y2];
190
- return bounds;
191
- }
192
- _isKidInSamePage(kid: _PdfDictionary, page: PdfPage): boolean {
193
- const pageReference: _PdfReference = page._ref;
194
- const reference: _PdfReference = kid.getRaw('P');
195
- if (pageReference === reference) {
196
- return true;
197
- } else {
198
- return false;
199
- }
200
- }
201
- _processAnnotation(page: PdfPage, options: PdfRedactionRegion[]): void {
202
- let markupAnnotation: PdfTextMarkupAnnotation;
203
- const annotbounds: Array<number[]> = [];
204
- for (let i: number = 0; i <= page.annotations.count - 1; i++) {
205
- const annotation: PdfAnnotation = page.annotations.at(i) as PdfAnnotation;
206
- let type: _PdfAnnotationType;
207
- let rect: any; // eslint-disable-line
208
- let bounds: number[];
209
- if (typeof(annotation) !== 'undefined') {
210
- type = this._getAnnotationType(annotation._dictionary);
211
- rect = annotation.bounds;
212
- bounds = [rect.x, rect.y, rect.width, rect.height];
213
- } else {
214
- type = _PdfAnnotationType.widgetAnnotation;
215
- }
216
- let isValidAnnotation: boolean = true;
217
- const newPoints: number[] = [];
218
- let inkBounds: {bounds: {x: number; y: number; width: number; height: number}, isValidAnnotation: boolean };
219
- switch (type) {
220
- case _PdfAnnotationType.textWebLinkAnnotation:
221
- case _PdfAnnotationType.documentLinkAnnotation:
222
- case _PdfAnnotationType.fileLinkAnnotation:
223
- case _PdfAnnotationType.watermarkAnnotation:
224
- case _PdfAnnotationType.fileAttachmentAnnotation:
225
- case _PdfAnnotationType.freeTextAnnotation:
226
- case _PdfAnnotationType.circleAnnotation:
227
- case _PdfAnnotationType.ellipseAnnotation:
228
- case _PdfAnnotationType.richMediaAnnotation:
229
- case _PdfAnnotationType.squareAnnotation:
230
- case _PdfAnnotationType.rectangleAnnotation:
231
- case _PdfAnnotationType.popupAnnotation:
232
- case _PdfAnnotationType.rubberStampAnnotation:
233
- case _PdfAnnotationType.soundAnnotation:
234
- case _PdfAnnotationType.linkAnnotation:
235
- break;
236
- case _PdfAnnotationType.caretAnnotation:
237
- case _PdfAnnotationType.movieAnnotation:
238
- case _PdfAnnotationType.printerMarkAnnotation:
239
- case _PdfAnnotationType.textAnnotation:
240
- case _PdfAnnotationType.textMarkupAnnotation:
241
- case _PdfAnnotationType.trapNetworkAnnotation:
242
- markupAnnotation = annotation as PdfTextMarkupAnnotation;
243
- if (markupAnnotation && markupAnnotation.boundsCollection && markupAnnotation.boundsCollection.length > 0) {
244
- let isIntersect: boolean = false;
245
- for (const innerBounds of markupAnnotation.boundsCollection) {
246
- for (let j: number = 0; j < options.length; j++) {
247
- if (this._isFound(innerBounds, options[Number.parseInt(j.toString(), 10)].bounds)) {
248
- isIntersect = true;
249
- break;
250
- }
251
- }
252
- }
253
- if (isIntersect) {
254
- page.annotations.removeAt(i);
255
- i--;
256
- continue;
257
- }
258
- }
259
- break;
260
- case _PdfAnnotationType.lineAnnotation:
261
- {
262
- const lineAnnotation: PdfLineAnnotation = annotation as PdfLineAnnotation;
263
- let points: number[];
264
- if (lineAnnotation) {
265
- points = lineAnnotation.linePoints;
266
- }
267
- let isFound: boolean = false;
268
- const height: number = page.graphics._size[1];
269
- for (let j: number = 0; j < options.length; j++) {
270
- if (this._isLineIntersectRectangle(options[Number.parseInt(j.toString(), 10)].bounds, points[0],
271
- height - points[1], points[2], height - points[3])) {
272
- isFound = true;
273
- }
274
- }
275
- if (isFound) {
276
- page.annotations.removeAt(i);
277
- i--;
278
- continue;
279
- }
280
- }
281
- break;
282
- case _PdfAnnotationType.polygonAnnotation:
283
- {
284
- const polygon: PdfPolygonAnnotation = (annotation as PdfPolygonAnnotation);
285
- const polygonPoints: Array<number[]> = polygon._getLinePoints();
286
- polygonPoints.forEach((element: number[]) => {
287
- newPoints.push(element[0], -element[1]);
288
- });
289
- inkBounds = this._getBoundsFromPoints(newPoints, page);
290
- bounds = [inkBounds.bounds.x, inkBounds.bounds.y, inkBounds.bounds.width, inkBounds.bounds.height];
291
- isValidAnnotation = inkBounds.isValidAnnotation;
292
- }
293
- break;
294
- case _PdfAnnotationType.polyLineAnnotation:
295
- {
296
- const polyLine: PdfPolyLineAnnotation = (annotation as PdfPolyLineAnnotation);
297
- const polyLinePoints: Array<number[]> = polyLine._getLinePoints();
298
- polyLinePoints.forEach((element: number[]) => {
299
- newPoints.push(element[0], -element[1]);
300
- });
301
- inkBounds = this._getBoundsFromPoints(newPoints, page);
302
- bounds = [inkBounds.bounds.x, inkBounds.bounds.y, inkBounds.bounds.width, inkBounds.bounds.height];
303
- isValidAnnotation = inkBounds.isValidAnnotation;
304
- }
305
- break;
306
- case _PdfAnnotationType.inkAnnotation:
307
- {
308
- const inkAnnotation: PdfInkAnnotation = (annotation as PdfInkAnnotation);
309
- const inkList: Array<number[]> = inkAnnotation.inkPointsCollection;
310
- inkBounds = this._getBoundsFromPoints(inkList[0], page);
311
- bounds = [inkBounds.bounds.x, inkBounds.bounds.y, inkBounds.bounds.width, inkBounds.bounds.height];
312
- isValidAnnotation = inkBounds.isValidAnnotation;
313
- }
314
- break;
315
- case _PdfAnnotationType.highlight:
316
- case _PdfAnnotationType.squiggly:
317
- case _PdfAnnotationType.strikeOut:
318
- case _PdfAnnotationType.underline:
319
- case _PdfAnnotationType.screenAnnotation:
320
- markupAnnotation = annotation as PdfTextMarkupAnnotation;
321
- if (markupAnnotation && markupAnnotation.boundsCollection && markupAnnotation.boundsCollection.length > 0) {
322
- let isIntersect: boolean = false;
323
- for (const innerBounds of markupAnnotation.boundsCollection) {
324
- for (let j: number = 0; j < options.length; j++) {
325
- if (this._isFound(innerBounds, options[Number.parseInt(j.toString(), 10)].bounds)) {
326
- isIntersect = true;
327
- break;
328
- }
329
- }
330
- }
331
- if (isIntersect) {
332
- page.annotations.removeAt(i);
333
- i--;
334
- continue;
335
- }
336
- }
337
- break;
338
- default:
339
- isValidAnnotation = false;
340
- }
341
- annotbounds.push(bounds);
342
- if (bounds && isValidAnnotation) {
343
- for (let j: number = 0; j < options.length; j++) {
344
- if (this._isFound(bounds, options[Number.parseInt(j.toString(), 10)].bounds)) {
345
- page.annotations.removeAt(i);
346
- i--;
347
- page._pageDictionary._updated = true;
348
- break;
349
- }
350
- }
351
- }
352
- }
353
- }
354
- _getBoundsFromPoints(points: number[], loadedPage: PdfPage): { bounds: { x: number; y: number; width: number; height: number };
355
- isValidAnnotation: boolean } {
356
- let isValidAnnotation: boolean = false;
357
- if (points.length > 0) {
358
- let minX: number = points[0];
359
- let maxX: number = points[0];
360
- let minY: number = loadedPage.graphics._size[1] - points[1];
361
- let maxY: number = loadedPage.graphics._size[1] - points[1];
362
- for (let index: number = 0; index < points.length; index++) {
363
- const point: number = points[Number.parseInt(index.toString(), 10)];
364
- if (index % 2 === 0) {
365
- minX = Math.min(minX, point);
366
- maxX = Math.max(maxX, point);
367
- } else {
368
- const adjustedY: number = loadedPage.graphics._size[1] - point;
369
- minY = Math.min(minY, adjustedY);
370
- maxY = Math.max(maxY, adjustedY);
371
- }
372
- }
373
- isValidAnnotation = true;
374
- return { bounds: { x: minX, y: minY, width: maxX - minX, height: maxY - minY }, isValidAnnotation };
375
- }
376
- return { bounds: { x: 0, y: 0, width: 0, height: 0 }, isValidAnnotation };
377
- }
378
- _isLineIntersectRectangle(
379
- redactBounds: { x: number; y: number; width: number; height: number },
380
- p1X: number,
381
- p1Y: number,
382
- p2X: number,
383
- p2Y: number
384
- ): boolean {
385
- let minX: number = p1X;
386
- let maxX: number = p2X;
387
- if (p1X > p2X) {
388
- minX = p2X;
389
- maxX = p1X;
390
- }
391
- if (maxX > redactBounds.x + redactBounds.width) {
392
- maxX = redactBounds.x + redactBounds.width;
393
- }
394
- if (minX < redactBounds.x) {
395
- minX = redactBounds.x;
396
- }
397
- if (minX > maxX) {
398
- return false;
399
- }
400
- let minY: number = p1Y;
401
- let maxY: number = p2Y;
402
- const dx: number = p2X - p1X;
403
- if (dx > 0.0000001) {
404
- const a: number = (p2Y - p1Y) / dx;
405
- const b: number = p1Y - a * p1X;
406
- minY = a * minX + b;
407
- maxY = a * maxX + b;
408
- }
409
- if (minY > maxY) {
410
- const temp: number = maxY;
411
- maxY = minY;
412
- minY = temp;
413
- }
414
- if (maxY > redactBounds.y + redactBounds.height) {
415
- maxY = redactBounds.y + redactBounds.height;
416
- }
417
- if (minY < redactBounds.y) {
418
- minY = redactBounds.y;
419
- }
420
- if (minY > maxY) {
421
- return false;
422
- }
423
- return true;
424
- }
425
- _isBoundsEqual(bounds1: {x: number, y: number, width: number, height: number}, bounds2: {x: number, y: number, width: number,
426
- height: number}): boolean {
427
- return bounds1.x === bounds2.x &&
428
- bounds1.y === bounds2.y &&
429
- bounds1.width === bounds2.width &&
430
- bounds1.height === bounds2.height;
431
- }
432
- _getAnnotationType(dictionary: _PdfDictionary): _PdfAnnotationType {
433
- let name: string = '';
434
- if (dictionary && dictionary.has('Subtype')) {
435
- const subtype: _PdfName = dictionary.get('Subtype');
436
- if (subtype) {
437
- name = subtype.name;
438
- }
439
- }
440
- let type: _PdfAnnotationType;
441
- switch (name.toLowerCase()) {
442
- case 'sound':
443
- type = _PdfAnnotationType.soundAnnotation;
444
- break;
445
- case 'text':
446
- case 'popup':
447
- type = _PdfAnnotationType.popupAnnotation;
448
- break;
449
- case 'link':
450
- {
451
- let linkDic: _PdfDictionary = null;
452
- if (dictionary.has('A')) {
453
- linkDic = dictionary.get('A');
454
- }
455
- if (linkDic !== null && linkDic.has('S')) {
456
- name = linkDic.get('S').name;
457
- if (name != null) {
458
- let border: number[] = [];
459
- if (dictionary.has('Border')) {
460
- border = dictionary.getArray('Border');
461
- }
462
- const mType: boolean = this._findAnnotation(border);
463
- if (name === 'URI') {
464
- if (!mType) {
465
- type = _PdfAnnotationType.linkAnnotation;
466
- } else {
467
- type = _PdfAnnotationType.textWebLinkAnnotation;
468
- }
469
- }
470
- else if (name === 'Launch') {
471
- type = _PdfAnnotationType.fileLinkAnnotation;
472
- }
473
- else if (name === 'GoToR') {
474
- type = _PdfAnnotationType.linkAnnotation;
475
- } else if (name === 'GoTo') {
476
- type = _PdfAnnotationType.documentLinkAnnotation;
477
- }
478
- }
479
- } else if (typeof(dictionary) !== 'undefined' && dictionary.has('Subtype')) {
480
- const strText: _PdfName = dictionary.get('Subtype');
481
- if (typeof(strText) !== 'undefined' && strText !== null) {
482
- switch (strText.name) {
483
- case 'Link':
484
- type = _PdfAnnotationType.documentLinkAnnotation;
485
- break;
486
- }
487
- }
488
- }
489
- }
490
- break;
491
- case 'fileattachment':
492
- type = _PdfAnnotationType.fileAttachmentAnnotation;
493
- break;
494
- case 'line':
495
- type = _PdfAnnotationType.lineAnnotation;
496
- break;
497
- case 'circle':
498
- {
499
- const circleRectArray: number[] = dictionary.getArray('Rect');
500
- if (circleRectArray != null) {
501
- const circleRect: number[] = circleRectArray;
502
- type = (circleRect[2] === (circleRect[3])) ? _PdfAnnotationType.circleAnnotation :
503
- _PdfAnnotationType.ellipseAnnotation;
504
- }
505
- }
506
- break;
507
- case 'square':
508
- {
509
- const squarerectArray: number[] = dictionary.getArray('Rect');
510
- if (squarerectArray != null) {
511
- const squareRect: number[] = squarerectArray;
512
- type = (squareRect[2] === (squareRect[3])) ? _PdfAnnotationType.squareAnnotation :
513
- _PdfAnnotationType.rectangleAnnotation;
514
- }
515
- }
516
- break;
517
- case 'polygon':
518
- type = _PdfAnnotationType.polygonAnnotation;
519
- break;
520
- case 'redact':
521
- type = _PdfAnnotationType.redactionAnnotation;
522
- break;
523
- case 'polyline':
524
- type = _PdfAnnotationType.polyLineAnnotation;
525
- break;
526
- case 'widget':
527
- type = _PdfAnnotationType.widgetAnnotation;
528
- break;
529
- case 'highlight':
530
- type = _PdfAnnotationType.highlight;
531
- break;
532
- case 'underline':
533
- type = _PdfAnnotationType.underline;
534
- break;
535
- case 'strikeout':
536
- type = _PdfAnnotationType.strikeOut;
537
- break;
538
- case 'squiggly':
539
- type = _PdfAnnotationType.squiggly;
540
- break;
541
- case 'stamp':
542
- type = _PdfAnnotationType.rubberStampAnnotation;
543
- break;
544
- case 'ink':
545
- type = _PdfAnnotationType.inkAnnotation;
546
- break;
547
- case 'freetext':
548
- type = _PdfAnnotationType.freeTextAnnotation;
549
- break;
550
- case 'caret':
551
- type = _PdfAnnotationType.caretAnnotation;
552
- break;
553
- case 'watermark':
554
- type = _PdfAnnotationType.watermarkAnnotation;
555
- break;
556
- case 'screen':
557
- type = _PdfAnnotationType.screenAnnotation;
558
- break;
559
- case '3d':
560
- type = _PdfAnnotationType.movieAnnotation;
561
- break;
562
- case 'richmedia':
563
- type = _PdfAnnotationType.richMediaAnnotation;
564
- break;
565
- }
566
- return type;
567
- }
568
- _findAnnotation(array: any[]): boolean { // eslint-disable-line
569
- if (typeof(array) === 'undefined') {
570
- return false;
571
- }
572
- for (let i: number = 0; i < array.length; i++) {
573
- if (array[Number.parseInt(i.toString(), 10)] instanceof Array) {
574
- const temp: any[] = array[Number.parseInt(i.toString(), 10)]; // eslint-disable-line
575
- for (let j: number = 0; j < temp.length; j++) {
576
- const value: number = temp[Number.parseInt(i.toString(), 10)] as number;
577
- if (value > 0) {
578
- return false;
579
- }
580
- }
581
- } else {
582
- const digit: number = array[Number.parseInt(i.toString(), 10)] as number;
583
- if (typeof(digit) !== 'undefined' && digit > 0) {
584
- return false;
585
- }
586
- }
587
- }
588
- return true;
589
- }
590
- }