@syncfusion/ej2-pdf-data-extract 30.1.42 → 30.2.4

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