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

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,172 +0,0 @@
1
- import { _PdfContentStream, _PdfCrossReference, _PdfRecord, PdfDocument, PdfPage } from '@syncfusion/ej2-pdf';
2
- import { TextGlyph } from '../text-structure';
3
- import { _PdfContentParserHelper } from '../content-parser-helper';
4
- import { _TextGlyphMapper } from './text-glyph-mapper';
5
- import { _PdfRedactionProcessor } from './pdf-redaction-processor';
6
- import { PdfRedactionRegion } from './pdf-redaction-region';
7
- /**
8
- * Represents a content redactor from an existing PDF document.
9
- *
10
- * ```typescript
11
- * let document: PdfDocument = new PdfDocument(data, password);
12
- * // Create a new text extractor
13
- * let redactor: PdfRedactor = new PdfRedactor(document);
14
- * // Add redactions to the collection
15
- * let redactions: PdfRedactionRegion[] = [];
16
- * redactions.push(new PdfRedactionRegion(0, {x: 10, y: 10, width: 100, height: 50}));
17
- * redactions.push(new PdfRedactionRegion(2, {x: 10, y: 10, width: 100, height: 50}, true, [255, 0, 0]));
18
- * redactor.add(redactions);
19
- * // Apply redactions on the PDF document
20
- * redactor.redact();
21
- * // Save the document
22
- * document.save('output.pdf');
23
- * // Destroy the document
24
- * document.destroy();
25
- * ```
26
- */
27
- export declare class PdfRedactor {
28
- _document: PdfDocument;
29
- _isHex: boolean;
30
- _redactionRegion: PdfRedactionRegion[];
31
- _redaction: Map<number, PdfRedactionRegion[]>;
32
- _parser: _PdfContentParserHelper;
33
- _crossReference: _PdfCrossReference;
34
- _object: _PdfRedactionProcessor;
35
- /**
36
- * Initializes a new instance of the `PdfRedactor` class.
37
- *
38
- * @param {PdfDocument} document The PDF document to which the redactions will be applied.
39
- * @throws {Error} If the document is null, undefined, or not a loaded document instance.
40
- *
41
- * ```typescript
42
- * // Load an existing PDF document
43
- * let document: PdfDocument = new PdfDocument(data, password);
44
- * // Initialize a new instance of the `PdfRedactor` class
45
- * let redactor: PdfRedactor = new PdfRedactor(document);
46
- * // Initialize a new instance of the `PdfRedactionRegion` class.
47
- * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x:40, y: 41.809, width: 80, height: 90});
48
- * // Sets the fill color used to fill the redacted area.
49
- * redaction.fillColor = [255, 0, 0];
50
- * redactions.push(redaction);
51
- * // Add redactions with specified options.
52
- * redactor.add(redactions);
53
- * // Apply redactions on the PDF document
54
- * redactor.redact();
55
- * // Save the document
56
- * document.save('output.pdf');
57
- * // Destroy the document
58
- * document.destroy();
59
- * ```
60
- */
61
- constructor(document: PdfDocument);
62
- /**
63
- * Initializes a new instance of the `PdfRedactor` class with the specified redactions.
64
- *
65
- * @param {PdfDocument} document The PDF document to which the redactions will be applied.
66
- * @param {PdfRedactionRegion[]} redactions An array of redaction objects.
67
- * @throws {Error} If the document is null, undefined, or not a loaded document instance.
68
- *
69
- * ```typescript
70
- * // Load an existing PDF document
71
- * let document: PdfDocument = new PdfDocument(data, password);
72
- * // Add redactions to the collection
73
- * let redactions: PdfRedactionRegion[] = [];
74
- * // Initialize a new instance of the `PdfRedactionRegion` class.
75
- * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x:40, y: 41.809, width: 80, height: 90});
76
- * // Sets the fill color used to fill the redacted area.
77
- * redaction.fillColor = [255, 0, 0];
78
- * redactions.push(redaction);
79
- * // Initialize a new instance of the `PdfRedactor` class with redactions
80
- * let redactor: PdfRedactor = new PdfRedactor(document, redactions);
81
- * // Apply redactions on the PDF document
82
- * redactor.redact();
83
- * // Save the document
84
- * document.save('output.pdf');
85
- * // Destroy the document
86
- * document.destroy();
87
- * ```
88
- */
89
- constructor(document: PdfDocument, redactions: PdfRedactionRegion[]);
90
- /**
91
- * Add redactions with specified options.
92
- *
93
- * @param {PdfRedactionRegion[]} redactions An array of redaction objects to specify the page index, bounds and appearance of the redaction to be applied.
94
- * @returns {void} Nothing.
95
- *
96
- * ```typescript
97
- * // Load an existing PDF document
98
- * let document: PdfDocument = new PdfDocument(data, password);
99
- * // Add redactions to the collection
100
- * let redactions: PdfRedactionRegion[] = [];
101
- * // Initialize a new instance of the `PdfRedactor` class
102
- * let redactor: PdfRedactor = new PdfRedactor(document);
103
- * // Initialize a new instance of the `PdfRedactionRegion` class.
104
- * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x:40, y: 41.809, width: 80, height: 90});
105
- * // Sets the fill color used to fill the redacted area.
106
- * redaction.fillColor = [255, 0, 0];
107
- * redactions.push(redaction);
108
- * // Add redactions with specified options.
109
- * redactor.add(redactions);
110
- * // Apply redactions on the PDF document
111
- * redactor.redact();
112
- * // Save the document
113
- * document.save('output.pdf');
114
- * // Destroy the document
115
- * document.destroy();
116
- * ```
117
- */
118
- add(redactions: PdfRedactionRegion[]): void;
119
- /**
120
- * Redact the PDF document
121
- *
122
- * @returns {void} Nothing.
123
- *
124
- * ```typescript
125
- * // Load an existing PDF document
126
- * let document: PdfDocument = new PdfDocument(data, password);
127
- * // Add redactions to the collection
128
- * let redactions: PdfRedactionRegion[] = [];
129
- * // Initialize a new instance of the `PdfRedactor` class
130
- * let redactor: PdfRedactor = new PdfRedactor(document);
131
- * // Initialize a new instance of the `PdfRedactionRegion` class.
132
- * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x:40, y: 41.809, width: 80, height: 90});
133
- * // Sets the fill color used to fill the redacted area.
134
- * redaction.fillColor = [255, 0, 0];
135
- * redactions.push(redaction);
136
- * // Add redactions with specified options.
137
- * redactor.add(redactions);
138
- * // Apply redactions on the PDF document
139
- * redactor.redact();
140
- * // Save the document
141
- * document.save('output.pdf');
142
- * // Destroy the document
143
- * document.destroy();
144
- * ```
145
- */
146
- redact(): void;
147
- _applyRedaction(page: PdfPage): void;
148
- _combineBounds(options: PdfRedactionRegion[]): void;
149
- _optimizeContent(recordCollection: _PdfRecord[], index: number, updatedText: string, stream: _PdfContentStream): void;
150
- _getBytes(text: string): number[];
151
- _isFoundBounds(values: number[], redactionBounds: PdfRedactionRegion[]): boolean;
152
- _contains(bounds: {
153
- x: number;
154
- y: number;
155
- width: number;
156
- height: number;
157
- }, point: number[]): boolean;
158
- _intersectsWith(rect1: {
159
- x: number;
160
- y: number;
161
- width: number;
162
- height: number;
163
- }, rect2: {
164
- x: number;
165
- y: number;
166
- width: number;
167
- height: number;
168
- }): boolean;
169
- _splitHexString(hexString: string): string[];
170
- _replacedText(glyph: TextGlyph[], text: string[], originalText: string, decodeText: string[]): string;
171
- _mapString(mainTextCollection: string[], imageGlyph: TextGlyph[]): _TextGlyphMapper[];
172
- }
@@ -1,414 +0,0 @@
1
- import { _PdfContentStream, _PdfCrossReference, _PdfDictionary, _PdfRecord, PdfAnnotation, PdfDocument, PdfPage, PdfRedactionAnnotation, PdfTemplate} from '@syncfusion/ej2-pdf';
2
- import { _GraphicState } from '../graphic-state';
3
- import { TextGlyph } from '../text-structure';
4
- import { _PdfContentParserHelper } from '../content-parser-helper';
5
- import { _TextProcessingMode } from '../enum';
6
- import { _FontStructure } from '../text-extraction';
7
- import { _addFontResources, _getXObjectResources } from '../utils';
8
- import { _TextGlyphMapper } from './text-glyph-mapper';
9
- import { _PdfRedactionProcessor } from './pdf-redaction-processor';
10
- import { PdfRedactionRegion } from './pdf-redaction-region';
11
- /**
12
- * Represents a content redactor from an existing PDF document.
13
- *
14
- * ```typescript
15
- * let document: PdfDocument = new PdfDocument(data, password);
16
- * // Create a new text extractor
17
- * let redactor: PdfRedactor = new PdfRedactor(document);
18
- * // Add redactions to the collection
19
- * let redactions: PdfRedactionRegion[] = [];
20
- * redactions.push(new PdfRedactionRegion(0, {x: 10, y: 10, width: 100, height: 50}));
21
- * redactions.push(new PdfRedactionRegion(2, {x: 10, y: 10, width: 100, height: 50}, true, [255, 0, 0]));
22
- * redactor.add(redactions);
23
- * // Apply redactions on the PDF document
24
- * redactor.redact();
25
- * // Save the document
26
- * document.save('output.pdf');
27
- * // Destroy the document
28
- * document.destroy();
29
- * ```
30
- */
31
- export class PdfRedactor {
32
- _document: PdfDocument;
33
- _isHex: boolean = false;
34
- _redactionRegion: PdfRedactionRegion[] = [];
35
- _redaction: Map<number, PdfRedactionRegion[]> = new Map<number, PdfRedactionRegion[]>();
36
- _parser: _PdfContentParserHelper;
37
- _crossReference: _PdfCrossReference;
38
- _object: _PdfRedactionProcessor = new _PdfRedactionProcessor();
39
- /**
40
- * Initializes a new instance of the `PdfRedactor` class.
41
- *
42
- * @param {PdfDocument} document The PDF document to which the redactions will be applied.
43
- * @throws {Error} If the document is null, undefined, or not a loaded document instance.
44
- *
45
- * ```typescript
46
- * // Load an existing PDF document
47
- * let document: PdfDocument = new PdfDocument(data, password);
48
- * // Initialize a new instance of the `PdfRedactor` class
49
- * let redactor: PdfRedactor = new PdfRedactor(document);
50
- * // Initialize a new instance of the `PdfRedactionRegion` class.
51
- * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x:40, y: 41.809, width: 80, height: 90});
52
- * // Sets the fill color used to fill the redacted area.
53
- * redaction.fillColor = [255, 0, 0];
54
- * redactions.push(redaction);
55
- * // Add redactions with specified options.
56
- * redactor.add(redactions);
57
- * // Apply redactions on the PDF document
58
- * redactor.redact();
59
- * // Save the document
60
- * document.save('output.pdf');
61
- * // Destroy the document
62
- * document.destroy();
63
- * ```
64
- */
65
- constructor(document: PdfDocument)
66
- /**
67
- * Initializes a new instance of the `PdfRedactor` class with the specified redactions.
68
- *
69
- * @param {PdfDocument} document The PDF document to which the redactions will be applied.
70
- * @param {PdfRedactionRegion[]} redactions An array of redaction objects.
71
- * @throws {Error} If the document is null, undefined, or not a loaded document instance.
72
- *
73
- * ```typescript
74
- * // Load an existing PDF document
75
- * let document: PdfDocument = new PdfDocument(data, password);
76
- * // Add redactions to the collection
77
- * let redactions: PdfRedactionRegion[] = [];
78
- * // Initialize a new instance of the `PdfRedactionRegion` class.
79
- * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x:40, y: 41.809, width: 80, height: 90});
80
- * // Sets the fill color used to fill the redacted area.
81
- * redaction.fillColor = [255, 0, 0];
82
- * redactions.push(redaction);
83
- * // Initialize a new instance of the `PdfRedactor` class with redactions
84
- * let redactor: PdfRedactor = new PdfRedactor(document, redactions);
85
- * // Apply redactions on the PDF document
86
- * redactor.redact();
87
- * // Save the document
88
- * document.save('output.pdf');
89
- * // Destroy the document
90
- * document.destroy();
91
- * ```
92
- */
93
- constructor(document: PdfDocument, redactions: PdfRedactionRegion[])
94
- constructor(document: PdfDocument, redactions?: PdfRedactionRegion[]) {
95
- if (document) {
96
- if (document._isLoaded) {
97
- this._document = document;
98
- this._crossReference = document._crossReference;
99
- } else {
100
- throw new Error('Redaction cannot be applied to a newly created document.');
101
- }
102
- this._document.fileStructure.isIncrementalUpdate = false;
103
- this._parser = new _PdfContentParserHelper(_TextProcessingMode.redaction, this);
104
- if (redactions && redactions.length > 0) {
105
- this.add(redactions);
106
- }
107
- } else {
108
- throw new Error('PDF document instance cannot be null or undefined');
109
- }
110
- }
111
- /**
112
- * Add redactions with specified options.
113
- *
114
- * @param {PdfRedactionRegion[]} redactions An array of redaction objects to specify the page index, bounds and appearance of the redaction to be applied.
115
- * @returns {void} Nothing.
116
- *
117
- * ```typescript
118
- * // Load an existing PDF document
119
- * let document: PdfDocument = new PdfDocument(data, password);
120
- * // Add redactions to the collection
121
- * let redactions: PdfRedactionRegion[] = [];
122
- * // Initialize a new instance of the `PdfRedactor` class
123
- * let redactor: PdfRedactor = new PdfRedactor(document);
124
- * // Initialize a new instance of the `PdfRedactionRegion` class.
125
- * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x:40, y: 41.809, width: 80, height: 90});
126
- * // Sets the fill color used to fill the redacted area.
127
- * redaction.fillColor = [255, 0, 0];
128
- * redactions.push(redaction);
129
- * // Add redactions with specified options.
130
- * redactor.add(redactions);
131
- * // Apply redactions on the PDF document
132
- * redactor.redact();
133
- * // Save the document
134
- * document.save('output.pdf');
135
- * // Destroy the document
136
- * document.destroy();
137
- * ```
138
- */
139
- add(redactions: PdfRedactionRegion[]): void {
140
- const options: PdfRedactionRegion[] = redactions;
141
- for (let i: number = 0; i < options.length; i++) {
142
- const pageIndex: number = options[Number.parseInt(i.toString(), 10)].pageIndex;
143
- if (!this._redaction.has(pageIndex)) {
144
- this._redaction.set(pageIndex, []);
145
- }
146
- const redactionArray: PdfRedactionRegion[] = this._redaction.get(pageIndex);
147
- if (redactionArray) {
148
- redactionArray.push(options[Number.parseInt(i.toString(), 10)]);
149
- }
150
- }
151
- }
152
- /**
153
- * Redact the PDF document
154
- *
155
- * @returns {void} Nothing.
156
- *
157
- * ```typescript
158
- * // Load an existing PDF document
159
- * let document: PdfDocument = new PdfDocument(data, password);
160
- * // Add redactions to the collection
161
- * let redactions: PdfRedactionRegion[] = [];
162
- * // Initialize a new instance of the `PdfRedactor` class
163
- * let redactor: PdfRedactor = new PdfRedactor(document);
164
- * // Initialize a new instance of the `PdfRedactionRegion` class.
165
- * let redaction: PdfRedactionRegion = new PdfRedactionRegion(0, {x:40, y: 41.809, width: 80, height: 90});
166
- * // Sets the fill color used to fill the redacted area.
167
- * redaction.fillColor = [255, 0, 0];
168
- * redactions.push(redaction);
169
- * // Add redactions with specified options.
170
- * redactor.add(redactions);
171
- * // Apply redactions on the PDF document
172
- * redactor.redact();
173
- * // Save the document
174
- * document.save('output.pdf');
175
- * // Destroy the document
176
- * document.destroy();
177
- * ```
178
- */
179
- redact(): void {
180
- if (this._document && this._document.pageCount > 0) {
181
- for (let i: number = 0; i < this._document.pageCount; i++) {
182
- const page: PdfPage = this._document.getPage(i);
183
- if (page && page.annotations.count > 0) {
184
- this._applyRedaction(page);
185
- }
186
- }
187
- }
188
- this._redaction.forEach((value: PdfRedactionRegion[], key: number) => {
189
- this._redactionRegion = [];
190
- this._combineBounds(value);
191
- const option: PdfRedactionRegion[] = value;
192
- const page: PdfPage = this._document.getPage(key);
193
- const graphicState: _GraphicState = new _GraphicState();
194
- const recordCollection: _PdfRecord[] = this._parser._getPageRecordCollection(page);
195
- const resource: _PdfDictionary = page._pageDictionary.get('Resources');
196
- let fontCollection: Map<string, _FontStructure>;
197
- let xObjectCollection: Map<string, _FontStructure>;
198
- if (typeof(resource) !== 'undefined') {
199
- fontCollection = _addFontResources(resource, page._pageDictionary._crossReference );
200
- xObjectCollection = _getXObjectResources(resource, page._pageDictionary._crossReference);
201
- }
202
- let stream: any; // eslint-disable-line
203
- if (this._redactionRegion.length > 0) {
204
- stream = this._parser._processRecordCollection(recordCollection, page, fontCollection, xObjectCollection, graphicState);
205
- }
206
- page._needInitializeGraphics = true;
207
- this._object._updateContentStream(page, stream, option, this._document);
208
- });
209
- }
210
- _applyRedaction(page: PdfPage): void {
211
- const redactRegions: PdfRedactionRegion[] = [];
212
- for (let k: number = 0; k < page.annotations.count; k++) {
213
- const annotation: PdfAnnotation = page.annotations.at(k);
214
- if (annotation && annotation instanceof PdfRedactionAnnotation) {
215
- const redactionAnnotation: PdfRedactionAnnotation = annotation as PdfRedactionAnnotation;
216
- redactionAnnotation.flatten = true;
217
- const appearance: PdfTemplate = redactionAnnotation._createNormalAppearance();
218
- const redact: PdfRedactionRegion = new PdfRedactionRegion(page._pageIndex, redactionAnnotation.bounds);
219
- redact.appearance.normal = appearance;
220
- page.annotations.removeAt(k);
221
- redactRegions.push(redact);
222
- k--;
223
- }
224
- }
225
- if (redactRegions.length > 0) {
226
- const existingRedactions: PdfRedactionRegion[] = this._redaction.get(page._pageIndex) || [];
227
- this._redaction.set(page._pageIndex, existingRedactions.concat(redactRegions));
228
- }
229
- }
230
- _combineBounds(options: PdfRedactionRegion[]): void {
231
- for (let i: number = 0; i < options.length; i++) {
232
- this._redactionRegion.push(options[Number.parseInt(i.toString(), 10)]);
233
- }
234
- }
235
- _optimizeContent(recordCollection: _PdfRecord[], index: number, updatedText: string, stream: _PdfContentStream): void {
236
- const record: _PdfRecord = recordCollection[Number.parseInt(index.toString(), 10)];
237
- if (record) {
238
- if (typeof(record._operands) !== 'undefined' && record._operands.length >= 1) {
239
- if (record._operator === 'ID') {
240
- const builder: string[] = [];
241
- for (let k: number = 0; k < record._operands.length; k++) {
242
- if (k + 1 < record._operands.length && record._operands[k].indexOf("/") !== -1 && record._operands[k + 1].indexOf("/") !==-1) { // eslint-disable-line
243
- builder.push(record._operands[Number.parseInt(k.toString(), 10)], ' ', record._operands[k + 1], '\r\n');
244
- k = k + 1;
245
- } else if (k + 1 < record._operands.length && record._operands[k].indexOf("/") !== -1) { // eslint-disable-line
246
- builder.push(record._operands[Number.parseInt(k.toString(), 10)], ' ', record._operands[k + 1], '\r\n');
247
- k = k + 1;
248
- } else {
249
- builder.push(record._operands[Number.parseInt(k.toString(), 10)], ' ');
250
- }
251
- }
252
- let text: string = builder.join(""); // eslint-disable-line
253
- const bytes: number[] = this._getBytes(text);
254
- stream.write(bytes);
255
- } else {
256
- for (let i: number = 0; i < record._operands.length; i++) {
257
- let operand: string = record._operands[Number.parseInt(i.toString(), 10)];
258
- if (record._operator === 'Tj' || record._operator === "'" || record._operator === '\"' || record._operator === 'TJ') { // eslint-disable-line
259
- if (updatedText !== '') {
260
- operand = updatedText;
261
- if (record._operator === "'" || record._operator === '\"') { // eslint-disable-line
262
- stream.write('T*');
263
- stream.write(' ');
264
- if (record._operator === '\"') { // eslint-disable-line
265
- i += 2;
266
- }
267
- }
268
- record._operator = 'TJ';
269
- }
270
- }
271
- const bytes: number[] = this._getBytes(operand);
272
- stream.write(bytes);
273
- if (record._operator !== 'Tj' && record._operator !== "'" && record._operator !== '\"' && record._operator !== 'TJ') { // eslint-disable-line
274
- stream.write(' ');
275
- }
276
- }
277
- }
278
- } else if (typeof(record._operands) === 'undefined' && typeof(record._inlineImageBytes) !== 'undefined') {
279
- const numberArray: number[] = Array.from(record._inlineImageBytes);
280
- stream.write(numberArray);
281
- stream.write(' ');
282
- }
283
- stream.write(record._operator);
284
- }
285
- const count: number = recordCollection.length;
286
- if ((index) < count) {
287
- if (record._operator === 'ID') {
288
- stream.write('\n');
289
- } else if ((record._operator === 'W' || record._operator === 'W*') && recordCollection[index + 1]._operator === 'n') {
290
- stream.write(' ');
291
- } else if (record._operator === 'w' || record._operator === 'EI') {
292
- stream.write(' ');
293
- } else {
294
- stream.write('\r\n');
295
- }
296
- }
297
- }
298
- _getBytes(text: string): number[] {
299
- const bytes: number[] = [];
300
- for (let i: number = 0; i < text.length; i++) {
301
- const charCode: number = text.charCodeAt(i);
302
- bytes.push(charCode);
303
- }
304
- return bytes;
305
- }
306
- _isFoundBounds(values: number[], redactionBounds: PdfRedactionRegion[]): boolean {
307
- const rect: {x: number, y: number, width: number, height: number} = {x: values[0], y: values[1], width: values[2],
308
- height: values[3]};
309
- for (const bounds of redactionBounds) {
310
- if (this._contains(bounds._bounds, [rect.x, rect.y]) || this._intersectsWith(bounds._bounds, rect)) {
311
- return true;
312
- }
313
- }
314
- return false;
315
- }
316
- _contains(bounds: {x: number, y: number, width: number, height: number}, point: number[]): boolean {
317
- return (
318
- point[0] >= bounds.x &&
319
- point[0] <= bounds.x + bounds.width &&
320
- point[1] >= bounds.y &&
321
- point[1] <= bounds.y + bounds.height
322
- );
323
- }
324
- _intersectsWith(rect1: {x: number, y: number, width: number, height: number}, rect2: {x: number, y: number, width: number,
325
- height: number}): boolean {
326
- return (rect2.x < rect1.x + rect1.width) && (rect1.x < (rect2.x + rect2.width)) && (rect2.y < rect1.y + rect1.height) &&
327
- (rect1.y < rect2.y + rect2.height);
328
- }
329
- _splitHexString(hexString: string): string[] {
330
- const hexList: string[] = [];
331
- hexString = hexString.slice(1, -1);
332
- const size: number = hexString.startsWith('0') ? 4 : 2;
333
- for (let i: number = 0; i < hexString.length; i += size) {
334
- let chunk: string = hexString.substring(i, i + size);
335
- if (chunk.indexOf('\n') !== -1) {
336
- const extraChar: string = hexString.charAt(i + size);
337
- chunk += extraChar;
338
- i++;
339
- }
340
- hexList.push(chunk);
341
- }
342
- return hexList;
343
- }
344
- _replacedText(glyph: TextGlyph[], text: string[], originalText: string, decodeText: string[]): string {
345
- let isReplacedText: boolean = false;
346
- let isOtherText: boolean = false;
347
- for (let i: number = 0; i < glyph.length; i++) {
348
- if (this._isFoundBounds(glyph[Number.parseInt(i.toString(), 10)]._bounds, this._redactionRegion)) {
349
- isReplacedText = true;
350
- glyph[Number.parseInt(i.toString(), 10)]._isReplace = true;
351
- } else {
352
- isOtherText = true;
353
- glyph[Number.parseInt(i.toString(), 10)]._text = text[Number.parseInt(i.toString(), 10)];
354
- }
355
- }
356
- let updatedText: string = '';
357
- if (!isReplacedText && isOtherText) {
358
- return originalText;
359
- } else {
360
- let mainTextCollection: string[] = [];
361
- if (originalText[0] === '(') {
362
- mainTextCollection = decodeText;
363
- } else if (originalText[0] === '[') {
364
- mainTextCollection = decodeText;
365
- } else if (originalText[0] === '<') {
366
- mainTextCollection = decodeText;
367
- this._isHex = true;
368
- }
369
- const map: _TextGlyphMapper[] = this._mapString(mainTextCollection, glyph);
370
- for (let i: number = 0; i < map.length; i++) {
371
- map[Number.parseInt(i.toString(), 10)]._isHex = this._isHex;
372
- updatedText += map[Number.parseInt(i.toString(), 10)]._getText();
373
- }
374
- updatedText = '[' + updatedText + ']';
375
- this._isHex = false;
376
- }
377
- return updatedText;
378
- }
379
- _mapString(mainTextCollection: string[], imageGlyph: TextGlyph[]): _TextGlyphMapper[] {
380
- const mappedString: _TextGlyphMapper[] = [];
381
- const glyphList: TextGlyph[] = imageGlyph;
382
- let startIndex: number = 0;
383
- for (let i: number = 0; i < mainTextCollection.length; i++) {
384
- const endChar: number = mainTextCollection[Number.parseInt(i.toString(), 10)].length - 1;
385
- if (mainTextCollection[Number.parseInt(i.toString(), 10)][0] !== '(' && mainTextCollection[
386
- Number.parseInt(i.toString(), 10)][Number.parseInt(endChar.toString(), 10)] !== ')') {
387
- const mapping: _TextGlyphMapper = new _TextGlyphMapper();
388
- mapping.text = mainTextCollection[Number.parseInt(i.toString(), 10)];
389
- mappedString.push(mapping);
390
- } else {
391
- const mapping: _TextGlyphMapper = new _TextGlyphMapper();
392
- mapping.text = mainTextCollection[Number.parseInt(i.toString(), 10)];
393
- let text: string = mainTextCollection[Number.parseInt(i.toString(), 10)];
394
- const subString: boolean = text.length >= 2;
395
- const start: boolean = text.startsWith('(');
396
- const end: boolean = text.endsWith(')');
397
- if (subString && start && !end) {
398
- text = text.substring(1, text.length);
399
- } else if (subString && !start && end) {
400
- text = text.substring(0, text.length - 1);
401
- } else if (subString) {
402
- text = text.substring(1, text.length - 1);
403
- } else {
404
- continue;
405
- }
406
- const length: number = text.length;
407
- mapping.glyph = glyphList.slice(startIndex, startIndex + length);
408
- startIndex += length;
409
- mappedString.push(mapping);
410
- }
411
- }
412
- return mappedString;
413
- }
414
- }
@@ -1,45 +0,0 @@
1
- import { Point } from '@syncfusion/ej2-pdf';
2
- export declare class _PdfIntersection {
3
- _x: number;
4
- _y: number;
5
- _toSource: number;
6
- _toClip: number;
7
- constructor(s1: _PdfVertex, s2: _PdfVertex, c1: _PdfVertex, c2: _PdfVertex);
8
- _isValid(): boolean;
9
- }
10
- export declare class _PdfPolygon {
11
- _first: _PdfVertex;
12
- private _vertices;
13
- private _lastUnprocessed;
14
- private _firstIntersect;
15
- private _arrayVertices;
16
- _globalIntersections: Point[];
17
- constructor(p: Point[], arrayVertices?: boolean);
18
- _addVertex(vertex: _PdfVertex): void;
19
- _insertVertex(vertex: _PdfVertex, start: _PdfVertex, end: _PdfVertex): void;
20
- _getNext(v: _PdfVertex): _PdfVertex;
21
- _getFirstIntersect(): _PdfVertex;
22
- _hasUnprocessed(): boolean;
23
- _getPoints(): Point[];
24
- _clip(clip: _PdfPolygon, sourceForwards: boolean, clipForwards: boolean): Point[][];
25
- private _computeIntersections;
26
- private _setEntryExitFlags;
27
- private _constructClippedPolygons;
28
- private _handleEmptyResult;
29
- }
30
- export declare class _PdfVertex {
31
- _x: number;
32
- _y: number;
33
- _next: _PdfVertex;
34
- _prev: _PdfVertex;
35
- _corresponding: _PdfVertex;
36
- _distance: number;
37
- _isEntry: boolean;
38
- _isIntersection: boolean;
39
- _visited: boolean;
40
- constructor(x: number, y: number);
41
- _createIntersection(x: number, y: number, distance: number): _PdfVertex;
42
- _visit(): void;
43
- _equals(v: _PdfVertex): boolean;
44
- _isInside(poly: _PdfPolygon): boolean;
45
- }