@syncfusion/ej2-pdf-data-extract 30.1.42 → 30.2.5
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-data-extract.umd.min.js +1 -2
- package/dist/global/ej2-pdf-data-extract.min.js +1 -2
- package/dist/global/index.d.ts +1 -2
- package/package.json +14 -46
- package/dist/ts/index.d.ts +0 -20
- package/dist/ts/index.ts +0 -20
- package/dist/ts/pdf-data-extract/core/content-parser-helper.d.ts +0 -62
- package/dist/ts/pdf-data-extract/core/content-parser-helper.ts +0 -640
- package/dist/ts/pdf-data-extract/core/enum.d.ts +0 -6
- package/dist/ts/pdf-data-extract/core/enum.ts +0 -6
- package/dist/ts/pdf-data-extract/core/graphic-state.d.ts +0 -33
- package/dist/ts/pdf-data-extract/core/graphic-state.ts +0 -106
- package/dist/ts/pdf-data-extract/core/pdf-data-extractor.d.ts +0 -210
- package/dist/ts/pdf-data-extract/core/pdf-data-extractor.ts +0 -977
- package/dist/ts/pdf-data-extract/core/pdf-text-parser.d.ts +0 -67
- package/dist/ts/pdf-data-extract/core/pdf-text-parser.ts +0 -495
- package/dist/ts/pdf-data-extract/core/redaction/index.d.ts +0 -4
- package/dist/ts/pdf-data-extract/core/redaction/index.ts +0 -4
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-processor.d.ts +0 -55
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-processor.ts +0 -592
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-region.d.ts +0 -281
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-region.ts +0 -342
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redactor.d.ts +0 -129
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redactor.ts +0 -322
- package/dist/ts/pdf-data-extract/core/redaction/text-glyph-mapper.d.ts +0 -12
- package/dist/ts/pdf-data-extract/core/redaction/text-glyph-mapper.ts +0 -153
- package/dist/ts/pdf-data-extract/core/text-extraction/binary-cmap-reader.d.ts +0 -24
- package/dist/ts/pdf-data-extract/core/text-extraction/binary-cmap-reader.ts +0 -281
- package/dist/ts/pdf-data-extract/core/text-extraction/cmap.d.ts +0 -50
- package/dist/ts/pdf-data-extract/core/text-extraction/cmap.ts +0 -565
- package/dist/ts/pdf-data-extract/core/text-extraction/compact-font-parser.d.ts +0 -191
- package/dist/ts/pdf-data-extract/core/text-extraction/compact-font-parser.ts +0 -1928
- package/dist/ts/pdf-data-extract/core/text-extraction/encoding-utils.d.ts +0 -102
- package/dist/ts/pdf-data-extract/core/text-extraction/encoding-utils.ts +0 -5780
- package/dist/ts/pdf-data-extract/core/text-extraction/font-structure.d.ts +0 -167
- package/dist/ts/pdf-data-extract/core/text-extraction/font-structure.ts +0 -1842
- package/dist/ts/pdf-data-extract/core/text-extraction/font-tables.d.ts +0 -5
- package/dist/ts/pdf-data-extract/core/text-extraction/font-tables.ts +0 -16
- package/dist/ts/pdf-data-extract/core/text-extraction/font-utils.d.ts +0 -18
- package/dist/ts/pdf-data-extract/core/text-extraction/font-utils.ts +0 -630
- package/dist/ts/pdf-data-extract/core/text-extraction/glyph.d.ts +0 -93
- package/dist/ts/pdf-data-extract/core/text-extraction/glyph.ts +0 -622
- package/dist/ts/pdf-data-extract/core/text-extraction/index.d.ts +0 -10
- package/dist/ts/pdf-data-extract/core/text-extraction/index.ts +0 -10
- package/dist/ts/pdf-data-extract/core/text-extraction/matrix-helper.d.ts +0 -38
- package/dist/ts/pdf-data-extract/core/text-extraction/matrix-helper.ts +0 -150
- package/dist/ts/pdf-data-extract/core/text-extraction/metrics.d.ts +0 -16
- package/dist/ts/pdf-data-extract/core/text-extraction/metrics.ts +0 -2938
- package/dist/ts/pdf-data-extract/core/text-structure.d.ts +0 -628
- package/dist/ts/pdf-data-extract/core/text-structure.ts +0 -668
- package/dist/ts/pdf-data-extract/core/utils.d.ts +0 -99
- package/dist/ts/pdf-data-extract/core/utils.ts +0 -626
- package/dist/ts/pdf-data-extract/index.d.ts +0 -20
- package/dist/ts/pdf-data-extract/index.ts +0 -20
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { _PdfContentStream, _PdfCrossReference, _PdfRecord, PdfDocument } 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 PdfRedaction(0, {x: 10, y: 10, width: 100, height: 50}));
|
|
17
|
-
* redactions.push(new PdfRedaction(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
|
-
_redactionBounds: {
|
|
31
|
-
x: number;
|
|
32
|
-
y: number;
|
|
33
|
-
width: number;
|
|
34
|
-
height: number;
|
|
35
|
-
}[];
|
|
36
|
-
_redaction: Map<number, PdfRedactionRegion[]>;
|
|
37
|
-
_parser: _PdfContentParserHelper;
|
|
38
|
-
_crossReference: _PdfCrossReference;
|
|
39
|
-
_object: _PdfRedactionProcessor;
|
|
40
|
-
constructor();
|
|
41
|
-
constructor(document: PdfDocument);
|
|
42
|
-
/**
|
|
43
|
-
* Add redactions with specified options.
|
|
44
|
-
*
|
|
45
|
-
* @param {PdfRedactionRegion[]} redactions An array of redaction objects to specify the page index, bounds and appearance of the redaction to be applied.
|
|
46
|
-
*
|
|
47
|
-
* @returns {void} Nothing.
|
|
48
|
-
*
|
|
49
|
-
* ```typescript
|
|
50
|
-
* // Load an existing PDF document
|
|
51
|
-
* let document: PdfDocument = new PdfDocument(data, password);
|
|
52
|
-
* // Add redactions to the collection
|
|
53
|
-
* let redactions: PdfRedactionRegion[] = [];
|
|
54
|
-
* // Initialize a new instance of the `PdfRedactor` class
|
|
55
|
-
* let redactor: PdfRedactor = new PdfRedactor(document);
|
|
56
|
-
* // Initialize a new instance of the `PdfRedaction` class.
|
|
57
|
-
* let redaction: PdfRedaction = new PdfRedaction(0, {x:40, y: 41.809, width: 80, height: 90});
|
|
58
|
-
* // Sets the fill color used to fill the redacted area.
|
|
59
|
-
* redaction.fillColor = [255, 0, 0];
|
|
60
|
-
* redactions.push(redaction);
|
|
61
|
-
* // Add redactions with specified options.
|
|
62
|
-
* redactor.add(redactions);
|
|
63
|
-
* // Apply redactions on the PDF document
|
|
64
|
-
* redactor.redact();
|
|
65
|
-
* // Save the document
|
|
66
|
-
* document.save('output.pdf');
|
|
67
|
-
* // Destroy the document
|
|
68
|
-
* document.destroy();
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
add(redactions: PdfRedactionRegion[]): void;
|
|
72
|
-
/**
|
|
73
|
-
* Redact the PDF document
|
|
74
|
-
*
|
|
75
|
-
* @returns {void} Nothing.
|
|
76
|
-
*
|
|
77
|
-
* ```typescript
|
|
78
|
-
* // Load an existing PDF document
|
|
79
|
-
* let document: PdfDocument = new PdfDocument(data, password);
|
|
80
|
-
* // Add redactions to the collection
|
|
81
|
-
* let redactions: PdfRedactionRegion[] = [];
|
|
82
|
-
* // Initialize a new instance of the `PdfRedactor` class
|
|
83
|
-
* let redactor: PdfRedactor = new PdfRedactor(document);
|
|
84
|
-
* // Initialize a new instance of the `PdfRedaction` class.
|
|
85
|
-
* let redaction: PdfRedaction = new PdfRedaction(0, {x:40, y: 41.809, width: 80, height: 90});
|
|
86
|
-
* // Sets the fill color used to fill the redacted area.
|
|
87
|
-
* redaction.fillColor = [255, 0, 0];
|
|
88
|
-
* redactions.push(redaction);
|
|
89
|
-
* // Add redactions with specified options.
|
|
90
|
-
* redactor.add(redactions);
|
|
91
|
-
* // Apply redactions on the PDF document
|
|
92
|
-
* redactor.redact();
|
|
93
|
-
* // Save the document
|
|
94
|
-
* document.save('output.pdf');
|
|
95
|
-
* // Destroy the document
|
|
96
|
-
* document.destroy();
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
redact(): void;
|
|
100
|
-
_combineBounds(options: PdfRedactionRegion[]): void;
|
|
101
|
-
_optimizeContent(recordCollection: _PdfRecord[], index: number, updatedText: string, stream: _PdfContentStream): void;
|
|
102
|
-
_getBytes(text: string): number[];
|
|
103
|
-
_isFoundBounds(values: number[], redactionBounds: {
|
|
104
|
-
x: number;
|
|
105
|
-
y: number;
|
|
106
|
-
width: number;
|
|
107
|
-
height: number;
|
|
108
|
-
}[]): boolean;
|
|
109
|
-
_contains(bounds: {
|
|
110
|
-
x: number;
|
|
111
|
-
y: number;
|
|
112
|
-
width: number;
|
|
113
|
-
height: number;
|
|
114
|
-
}, point: number[]): boolean;
|
|
115
|
-
_intersectsWith(rect1: {
|
|
116
|
-
x: number;
|
|
117
|
-
y: number;
|
|
118
|
-
width: number;
|
|
119
|
-
height: number;
|
|
120
|
-
}, rect2: {
|
|
121
|
-
x: number;
|
|
122
|
-
y: number;
|
|
123
|
-
width: number;
|
|
124
|
-
height: number;
|
|
125
|
-
}): boolean;
|
|
126
|
-
_splitHexString(hexString: string): string[];
|
|
127
|
-
_replacedText(glyph: TextGlyph[], text: string[], originalText: string, decodeText: string[]): string;
|
|
128
|
-
_mapString(mainTextCollection: string[], imageGlyph: TextGlyph[]): _TextGlyphMapper[];
|
|
129
|
-
}
|
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { _PdfContentStream, _PdfCrossReference, _PdfDictionary, _PdfRecord, PdfDocument, PdfPage} 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 PdfRedaction(0, {x: 10, y: 10, width: 100, height: 50}));
|
|
21
|
-
* redactions.push(new PdfRedaction(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
|
-
_redactionBounds: {x: number, y: number, width: number, height: number}[] = [];
|
|
35
|
-
_redaction: Map<number, PdfRedactionRegion[]> = new Map<number, PdfRedactionRegion[]>();
|
|
36
|
-
_parser: _PdfContentParserHelper;
|
|
37
|
-
_crossReference: _PdfCrossReference;
|
|
38
|
-
_object: _PdfRedactionProcessor = new _PdfRedactionProcessor();
|
|
39
|
-
constructor();
|
|
40
|
-
constructor(document: PdfDocument)
|
|
41
|
-
constructor(document?: PdfDocument) {
|
|
42
|
-
if (document instanceof PdfDocument) {
|
|
43
|
-
this._document = document;
|
|
44
|
-
this._crossReference = document._crossReference;
|
|
45
|
-
}
|
|
46
|
-
this._document.fileStructure.isIncrementalUpdate = false;
|
|
47
|
-
this._parser = new _PdfContentParserHelper(_TextProcessingMode.redaction, this);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Add redactions with specified options.
|
|
51
|
-
*
|
|
52
|
-
* @param {PdfRedactionRegion[]} redactions An array of redaction objects to specify the page index, bounds and appearance of the redaction to be applied.
|
|
53
|
-
*
|
|
54
|
-
* @returns {void} Nothing.
|
|
55
|
-
*
|
|
56
|
-
* ```typescript
|
|
57
|
-
* // Load an existing PDF document
|
|
58
|
-
* let document: PdfDocument = new PdfDocument(data, password);
|
|
59
|
-
* // Add redactions to the collection
|
|
60
|
-
* let redactions: PdfRedactionRegion[] = [];
|
|
61
|
-
* // Initialize a new instance of the `PdfRedactor` class
|
|
62
|
-
* let redactor: PdfRedactor = new PdfRedactor(document);
|
|
63
|
-
* // Initialize a new instance of the `PdfRedaction` class.
|
|
64
|
-
* let redaction: PdfRedaction = new PdfRedaction(0, {x:40, y: 41.809, width: 80, height: 90});
|
|
65
|
-
* // Sets the fill color used to fill the redacted area.
|
|
66
|
-
* redaction.fillColor = [255, 0, 0];
|
|
67
|
-
* redactions.push(redaction);
|
|
68
|
-
* // Add redactions with specified options.
|
|
69
|
-
* redactor.add(redactions);
|
|
70
|
-
* // Apply redactions on the PDF document
|
|
71
|
-
* redactor.redact();
|
|
72
|
-
* // Save the document
|
|
73
|
-
* document.save('output.pdf');
|
|
74
|
-
* // Destroy the document
|
|
75
|
-
* document.destroy();
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
add(redactions: PdfRedactionRegion[]): void {
|
|
79
|
-
const options: PdfRedactionRegion[] = redactions;
|
|
80
|
-
for (let i: number = 0; i < options.length; i++) {
|
|
81
|
-
const pageIndex: number = options[Number.parseInt(i.toString(), 10)].pageIndex;
|
|
82
|
-
if (!this._redaction.has(pageIndex)) {
|
|
83
|
-
this._redaction.set(pageIndex, []);
|
|
84
|
-
}
|
|
85
|
-
const redactionArray: PdfRedactionRegion[] = this._redaction.get(pageIndex);
|
|
86
|
-
if (redactionArray) {
|
|
87
|
-
redactionArray.push(options[Number.parseInt(i.toString(), 10)]);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Redact the PDF document
|
|
93
|
-
*
|
|
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 `PdfRedaction` class.
|
|
104
|
-
* let redaction: PdfRedaction = new PdfRedaction(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
|
-
redact(): void {
|
|
119
|
-
this._redaction.forEach((value: PdfRedactionRegion[], key: number) => {
|
|
120
|
-
this._redactionBounds = [];
|
|
121
|
-
this._combineBounds(value);
|
|
122
|
-
const option: PdfRedactionRegion[] = value;
|
|
123
|
-
const page: PdfPage = this._document.getPage(key);
|
|
124
|
-
const graphicState: _GraphicState = new _GraphicState();
|
|
125
|
-
const recordCollection: _PdfRecord[] = this._parser._getPageRecordCollection(page);
|
|
126
|
-
const resource: _PdfDictionary = page._pageDictionary.get('Resources');
|
|
127
|
-
let fontCollection: Map<string, _FontStructure>;
|
|
128
|
-
let xObjectCollection: Map<string, _FontStructure>;
|
|
129
|
-
if (typeof(resource) !== 'undefined') {
|
|
130
|
-
fontCollection = _addFontResources(resource, page._pageDictionary._crossReference );
|
|
131
|
-
xObjectCollection = _getXObjectResources(resource, page._pageDictionary._crossReference);
|
|
132
|
-
}
|
|
133
|
-
let stream: any; // eslint-disable-line
|
|
134
|
-
if (this._redactionBounds.length > 0) {
|
|
135
|
-
stream = this._parser._processRecordCollection(recordCollection, page, fontCollection, xObjectCollection, graphicState);
|
|
136
|
-
}
|
|
137
|
-
this._object._updateContentStream(page, stream, option, this._document);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
_combineBounds(options: PdfRedactionRegion[]): void {
|
|
141
|
-
for (let i: number = 0; i < options.length; i++) {
|
|
142
|
-
this._redactionBounds.push(options[Number.parseInt(i.toString(), 10)].bounds);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
_optimizeContent(recordCollection: _PdfRecord[], index: number, updatedText: string, stream: _PdfContentStream): void {
|
|
146
|
-
const record: _PdfRecord = recordCollection[Number.parseInt(index.toString(), 10)];
|
|
147
|
-
if (typeof(record._operands) !== 'undefined' && record._operands.length >= 1) {
|
|
148
|
-
if (record._operator === 'ID') {
|
|
149
|
-
const builder: string[] = [];
|
|
150
|
-
for (let k: number = 0; k < record._operands.length; k++) {
|
|
151
|
-
if (k + 1 < record._operands.length && record._operands[k].indexOf("/") !== -1 && record._operands[k + 1].indexOf("/") !==-1) { // eslint-disable-line
|
|
152
|
-
builder.push(record._operands[Number.parseInt(k.toString(), 10)], ' ', record._operands[k + 1], '\r\n');
|
|
153
|
-
k = k + 1;
|
|
154
|
-
} else if (k + 1 < record._operands.length && record._operands[k].indexOf("/") !== -1) { // eslint-disable-line
|
|
155
|
-
builder.push(record._operands[Number.parseInt(k.toString(), 10)], ' ', record._operands[k + 1], '\r\n');
|
|
156
|
-
k = k + 1;
|
|
157
|
-
} else {
|
|
158
|
-
builder.push(record._operands[Number.parseInt(k.toString(), 10)], ' ');
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
let text: string = builder.join(""); // eslint-disable-line
|
|
162
|
-
const bytes: number[] = this._getBytes(text);
|
|
163
|
-
stream.write(bytes);
|
|
164
|
-
} else {
|
|
165
|
-
for (let i: number = 0; i < record._operands.length; i++) {
|
|
166
|
-
let operand: string = record._operands[Number.parseInt(i.toString(), 10)];
|
|
167
|
-
if (record._operator === 'Tj' || record._operator === "'" || record._operator === '\"' || record._operator === 'TJ') { // eslint-disable-line
|
|
168
|
-
if (updatedText !== '') {
|
|
169
|
-
operand = updatedText;
|
|
170
|
-
if (record._operator === "'" || record._operator === '\"') { // eslint-disable-line
|
|
171
|
-
stream.write('T*');
|
|
172
|
-
stream.write(' ');
|
|
173
|
-
if (record._operator === '\"') { // eslint-disable-line
|
|
174
|
-
i += 2;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
record._operator = 'TJ';
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const bytes: number[] = this._getBytes(operand);
|
|
181
|
-
stream.write(bytes);
|
|
182
|
-
if (record._operator !== 'Tj' && record._operator !== "'" && record._operator !== '\"' && record._operator !== 'TJ') { // eslint-disable-line
|
|
183
|
-
stream.write(' ');
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
} else if (typeof(record._operands) === 'undefined' && typeof(record._inlineImageBytes) !== 'undefined') {
|
|
188
|
-
const numberArray: number[] = Array.from(record._inlineImageBytes);
|
|
189
|
-
stream.write(numberArray);
|
|
190
|
-
stream.write(' ');
|
|
191
|
-
}
|
|
192
|
-
stream.write(record._operator);
|
|
193
|
-
const count: number = recordCollection.length;
|
|
194
|
-
if ((index + 1) < count) {
|
|
195
|
-
if (record._operator === 'ID') {
|
|
196
|
-
stream.write('\n');
|
|
197
|
-
} else if ((index + 1) < count && (record._operator === 'W' || record._operator === 'W*') && recordCollection[index + 1]._operator === 'n') {
|
|
198
|
-
stream.write(' ');
|
|
199
|
-
} else if (record._operator === 'w' || record._operator === 'EI') {
|
|
200
|
-
stream.write(' ');
|
|
201
|
-
} else {
|
|
202
|
-
stream.write('\r\n');
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
_getBytes(text: string): number[] {
|
|
207
|
-
const bytes: number[] = [];
|
|
208
|
-
for (let i: number = 0; i < text.length; i++) {
|
|
209
|
-
const charCode: number = text.charCodeAt(i);
|
|
210
|
-
bytes.push(charCode);
|
|
211
|
-
}
|
|
212
|
-
return bytes;
|
|
213
|
-
}
|
|
214
|
-
_isFoundBounds(values: number[], redactionBounds: {x: number, y: number, width: number, height: number}[]): boolean {
|
|
215
|
-
const rect: {x: number, y: number, width: number, height: number} = {x: values[0], y: values[1], width: values[2],
|
|
216
|
-
height: values[3]};
|
|
217
|
-
for (const bounds of redactionBounds) {
|
|
218
|
-
if (this._contains(bounds, [rect.x, rect.y]) || this._intersectsWith(bounds, rect)) {
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
_contains(bounds: {x: number, y: number, width: number, height: number}, point: number[]): boolean {
|
|
225
|
-
return (
|
|
226
|
-
point[0] >= bounds.x &&
|
|
227
|
-
point[0] <= bounds.x + bounds.width &&
|
|
228
|
-
point[1] >= bounds.y &&
|
|
229
|
-
point[1] <= bounds.y + bounds.height
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
_intersectsWith(rect1: {x: number, y: number, width: number, height: number}, rect2: {x: number, y: number, width: number,
|
|
233
|
-
height: number}): boolean {
|
|
234
|
-
return (rect2.x < rect1.x + rect1.width) && (rect1.x < (rect2.x + rect2.width)) && (rect2.y < rect1.y + rect1.height) &&
|
|
235
|
-
(rect1.y < rect2.y + rect2.height);
|
|
236
|
-
}
|
|
237
|
-
_splitHexString(hexString: string): string[] {
|
|
238
|
-
const hexList: string[] = [];
|
|
239
|
-
hexString = hexString.slice(1, -1);
|
|
240
|
-
const size: number = hexString.startsWith('0') ? 4 : 2;
|
|
241
|
-
for (let i: number = 0; i < hexString.length; i += size) {
|
|
242
|
-
let chunk: string = hexString.substring(i, i + size);
|
|
243
|
-
if (chunk.indexOf('\n') !== -1) {
|
|
244
|
-
const extraChar: string = hexString.charAt(i + size);
|
|
245
|
-
chunk += extraChar;
|
|
246
|
-
i++;
|
|
247
|
-
}
|
|
248
|
-
hexList.push(chunk);
|
|
249
|
-
}
|
|
250
|
-
return hexList;
|
|
251
|
-
}
|
|
252
|
-
_replacedText(glyph: TextGlyph[], text: string[], originalText: string, decodeText: string[]): string {
|
|
253
|
-
let isReplacedText: boolean = false;
|
|
254
|
-
let isOtherText: boolean = false;
|
|
255
|
-
for (let i: number = 0; i < glyph.length; i++) {
|
|
256
|
-
if (this._isFoundBounds(glyph[Number.parseInt(i.toString(), 10)]._bounds, this._redactionBounds)) {
|
|
257
|
-
isReplacedText = true;
|
|
258
|
-
glyph[Number.parseInt(i.toString(), 10)]._isReplace = true;
|
|
259
|
-
} else {
|
|
260
|
-
isOtherText = true;
|
|
261
|
-
glyph[Number.parseInt(i.toString(), 10)]._text = text[Number.parseInt(i.toString(), 10)];
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
let updatedText: string = '';
|
|
265
|
-
if (!isReplacedText && isOtherText) {
|
|
266
|
-
return originalText;
|
|
267
|
-
} else {
|
|
268
|
-
let mainTextCollection: string[] = [];
|
|
269
|
-
if (originalText[0] === '(') {
|
|
270
|
-
mainTextCollection = decodeText;
|
|
271
|
-
} else if (originalText[0] === '[') {
|
|
272
|
-
mainTextCollection = decodeText;
|
|
273
|
-
} else if (originalText[0] === '<') {
|
|
274
|
-
mainTextCollection = decodeText;
|
|
275
|
-
this._isHex = true;
|
|
276
|
-
}
|
|
277
|
-
const map: _TextGlyphMapper[] = this._mapString(mainTextCollection, glyph);
|
|
278
|
-
for (let i: number = 0; i < map.length; i++) {
|
|
279
|
-
map[Number.parseInt(i.toString(), 10)]._isHex = this._isHex;
|
|
280
|
-
updatedText += map[Number.parseInt(i.toString(), 10)]._getText();
|
|
281
|
-
}
|
|
282
|
-
updatedText = '[' + updatedText + ']';
|
|
283
|
-
this._isHex = false;
|
|
284
|
-
}
|
|
285
|
-
return updatedText;
|
|
286
|
-
}
|
|
287
|
-
_mapString(mainTextCollection: string[], imageGlyph: TextGlyph[]): _TextGlyphMapper[] {
|
|
288
|
-
const mappedString: _TextGlyphMapper[] = [];
|
|
289
|
-
const glyphList: TextGlyph[] = imageGlyph;
|
|
290
|
-
let startIndex: number = 0;
|
|
291
|
-
for (let i: number = 0; i < mainTextCollection.length; i++) {
|
|
292
|
-
const endChar: number = mainTextCollection[Number.parseInt(i.toString(), 10)].length - 1;
|
|
293
|
-
if (mainTextCollection[Number.parseInt(i.toString(), 10)][0] !== '(' && mainTextCollection[
|
|
294
|
-
Number.parseInt(i.toString(), 10)][Number.parseInt(endChar.toString(), 10)] !== ')') {
|
|
295
|
-
const mapping: _TextGlyphMapper = new _TextGlyphMapper();
|
|
296
|
-
mapping.text = mainTextCollection[Number.parseInt(i.toString(), 10)];
|
|
297
|
-
mappedString.push(mapping);
|
|
298
|
-
} else {
|
|
299
|
-
const mapping: _TextGlyphMapper = new _TextGlyphMapper();
|
|
300
|
-
mapping.text = mainTextCollection[Number.parseInt(i.toString(), 10)];
|
|
301
|
-
let text: string = mainTextCollection[Number.parseInt(i.toString(), 10)];
|
|
302
|
-
const subString: boolean = text.length >= 2;
|
|
303
|
-
const start: boolean = text.startsWith('(');
|
|
304
|
-
const end: boolean = text.endsWith(')');
|
|
305
|
-
if (subString && start && !end) {
|
|
306
|
-
text = text.substring(1, text.length);
|
|
307
|
-
} else if (subString && !start && end) {
|
|
308
|
-
text = text.substring(0, text.length - 1);
|
|
309
|
-
} else if (subString) {
|
|
310
|
-
text = text.substring(1, text.length - 1);
|
|
311
|
-
} else {
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
const length: number = text.length;
|
|
315
|
-
mapping.glyph = glyphList.slice(startIndex, startIndex + length);
|
|
316
|
-
startIndex += length;
|
|
317
|
-
mappedString.push(mapping);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return mappedString;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { TextGlyph } from '../text-structure';
|
|
2
|
-
export declare class _TextGlyphMapper {
|
|
3
|
-
_text: string;
|
|
4
|
-
_glyph: TextGlyph[];
|
|
5
|
-
_isHex: boolean;
|
|
6
|
-
text: string;
|
|
7
|
-
glyph: TextGlyph[];
|
|
8
|
-
_applyEscapeSequence(text: string): string;
|
|
9
|
-
_getText(): string;
|
|
10
|
-
_replacedText(text: string, glyphs: TextGlyph[]): string;
|
|
11
|
-
_getReplacedCharacter(glyphs: TextGlyph[]): number;
|
|
12
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { TextGlyph } from '../text-structure';
|
|
2
|
-
|
|
3
|
-
export class _TextGlyphMapper {
|
|
4
|
-
_text: string;
|
|
5
|
-
_glyph: TextGlyph[];
|
|
6
|
-
_isHex: boolean = false;
|
|
7
|
-
set text(value: string) {
|
|
8
|
-
this._text = value;
|
|
9
|
-
}
|
|
10
|
-
get text(): string {
|
|
11
|
-
return this._text;
|
|
12
|
-
}
|
|
13
|
-
set glyph(value: TextGlyph[]) {
|
|
14
|
-
this._glyph = value;
|
|
15
|
-
}
|
|
16
|
-
get glyph(): TextGlyph[] {
|
|
17
|
-
return this._glyph;
|
|
18
|
-
}
|
|
19
|
-
_applyEscapeSequence(text: string): string {
|
|
20
|
-
let escapedText: string = text;
|
|
21
|
-
if (text.indexOf('(') !== -1) {
|
|
22
|
-
escapedText = escapedText.replace(/\(/g, '\\(');
|
|
23
|
-
}
|
|
24
|
-
if (text.indexOf(')') !== -1) {
|
|
25
|
-
escapedText = escapedText.replace(/\)/g, '\\)');
|
|
26
|
-
}
|
|
27
|
-
if (text.indexOf("'") !== -1) { // eslint-disable-line
|
|
28
|
-
escapedText = escapedText.replace(/'/g, "\\'"); // eslint-disable-line
|
|
29
|
-
}
|
|
30
|
-
if (text.indexOf('\\') !== -1) {
|
|
31
|
-
escapedText = escapedText.replace(/\\/g, '\\\\');
|
|
32
|
-
}
|
|
33
|
-
if (text.indexOf('\b') !== -1) {
|
|
34
|
-
escapedText = escapedText.replace(/\b/g, '\\b');
|
|
35
|
-
}
|
|
36
|
-
if (text.indexOf('\f') !== -1) {
|
|
37
|
-
escapedText = escapedText.replace(/\f/g, '\\f');
|
|
38
|
-
}
|
|
39
|
-
if (text.indexOf('\n') !== -1) {
|
|
40
|
-
escapedText = escapedText.replace(/\n/g, '\\n');
|
|
41
|
-
}
|
|
42
|
-
if (text.indexOf('\r') !== -1) {
|
|
43
|
-
escapedText = escapedText.replace(/\r/g, '\\r');
|
|
44
|
-
}
|
|
45
|
-
return escapedText;
|
|
46
|
-
}
|
|
47
|
-
_getText(): string {
|
|
48
|
-
if (typeof (this.glyph) === 'undefined') {
|
|
49
|
-
return this.text;
|
|
50
|
-
} else {
|
|
51
|
-
let finalText: string = '';
|
|
52
|
-
let currentText: string = '';
|
|
53
|
-
const subString: boolean = this.text.length >= 2;
|
|
54
|
-
const start: boolean = this.text.startsWith('(');
|
|
55
|
-
const end: boolean = this.text.endsWith(')');
|
|
56
|
-
if (subString && start && !end) {
|
|
57
|
-
currentText = this.text.substring(1, this.text.length);
|
|
58
|
-
} else if (subString && !start && end) {
|
|
59
|
-
currentText = this.text.substring(0, this.text.length - 1);
|
|
60
|
-
} else if (subString) {
|
|
61
|
-
currentText = this.text.substring(1, this.text.length - 1);
|
|
62
|
-
}
|
|
63
|
-
let replaceText: string = '';
|
|
64
|
-
let otherText: string = '';
|
|
65
|
-
let glyphs: TextGlyph[] = [];
|
|
66
|
-
const glyphDictionary: Map<string, TextGlyph[]> = new Map<string, TextGlyph[]>();
|
|
67
|
-
const dictionary: Map<string, string> = new Map<string, string> ();
|
|
68
|
-
let rTcount: number = 0;
|
|
69
|
-
let roTcount: number = 0;
|
|
70
|
-
let isHex: boolean = false;
|
|
71
|
-
for (let i: number = 0; i < this.glyph.length; i++) {
|
|
72
|
-
if (this.glyph[Number.parseInt(i.toString(), 10)]._isReplace) {
|
|
73
|
-
if (otherText !== '') {
|
|
74
|
-
dictionary.set('O-' + roTcount++, otherText);
|
|
75
|
-
otherText = '';
|
|
76
|
-
isHex = this.glyph[Number.parseInt(i.toString(), 10)]._isHex;
|
|
77
|
-
}
|
|
78
|
-
glyphs.push(this.glyph[Number.parseInt(i.toString(), 10)]);
|
|
79
|
-
replaceText += this.glyph[Number.parseInt(i.toString(), 10)].text;
|
|
80
|
-
} else {
|
|
81
|
-
if (replaceText !== '') {
|
|
82
|
-
const key: string = 'R-' + rTcount++;
|
|
83
|
-
glyphDictionary.set(key, glyphs);
|
|
84
|
-
dictionary.set(key, replaceText);
|
|
85
|
-
glyphs = [];
|
|
86
|
-
replaceText = '';
|
|
87
|
-
}
|
|
88
|
-
isHex = this.glyph[Number.parseInt(i.toString(), 10)]._isHex;
|
|
89
|
-
const text: string = this.glyph[Number.parseInt(i.toString(), 10)].text;
|
|
90
|
-
if (!isHex) {
|
|
91
|
-
otherText += this._applyEscapeSequence(text);
|
|
92
|
-
} else {
|
|
93
|
-
otherText += text;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (replaceText !== '') {
|
|
98
|
-
const key: string = 'R-' + rTcount++;
|
|
99
|
-
glyphDictionary.set(key, glyphs);
|
|
100
|
-
dictionary.set(key, replaceText);
|
|
101
|
-
glyphs = [];
|
|
102
|
-
replaceText = '';
|
|
103
|
-
}
|
|
104
|
-
if (otherText !== '') {
|
|
105
|
-
const key: string = 'O-' + roTcount++;
|
|
106
|
-
dictionary.set(key, otherText);
|
|
107
|
-
otherText = '';
|
|
108
|
-
}
|
|
109
|
-
dictionary.forEach((value: string, key: string) => {
|
|
110
|
-
if (key.indexOf('O-') !== -1) {
|
|
111
|
-
if (isHex) {
|
|
112
|
-
finalText += '<' + value + '>';
|
|
113
|
-
} else {
|
|
114
|
-
finalText += '(' + value + ')';
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
finalText += ' -' + this._getReplacedCharacter(glyphDictionary.get(key)) + ' ';
|
|
118
|
-
currentText = this._replacedText(currentText, glyphDictionary.get(key));
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
return finalText;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
_replacedText(text: string, glyphs: TextGlyph[]): string {
|
|
125
|
-
if (!text) {
|
|
126
|
-
return text;
|
|
127
|
-
}
|
|
128
|
-
let currentText: string = text;
|
|
129
|
-
let count: number = 0;
|
|
130
|
-
for (const gly of glyphs) {
|
|
131
|
-
const unicode: string = gly.text;
|
|
132
|
-
if (unicode) {
|
|
133
|
-
count += unicode.length;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
currentText = currentText.substring(count);
|
|
137
|
-
return currentText;
|
|
138
|
-
}
|
|
139
|
-
_getReplacedCharacter(glyphs: TextGlyph[]): number {
|
|
140
|
-
let totalWidth: number = 0;
|
|
141
|
-
for (let i: number = 0; i < glyphs.length; i++) {
|
|
142
|
-
const width: number = glyphs[Number.parseInt(i.toString(), 10)]._width;
|
|
143
|
-
if (glyphs[Number.parseInt(i.toString(), 10)].text !== ' ' ) {
|
|
144
|
-
totalWidth += width;
|
|
145
|
-
} else {
|
|
146
|
-
const actualFontSize: number = (0.001 * width * glyphs[Number.parseInt(i.toString(), 10)].fontSize);
|
|
147
|
-
totalWidth += (width + ((width / actualFontSize) * glyphs[Number.parseInt(i.toString(), 10)]._charSpacing) +
|
|
148
|
-
((width / actualFontSize) * glyphs[Number.parseInt(i.toString(), 10)]._wordSpacing));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return totalWidth;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare class _PdfBinaryCharacterMapReader {
|
|
2
|
-
_maximumSize: number;
|
|
3
|
-
_convertHexToInt(data: Uint8Array, size: number): number;
|
|
4
|
-
_hexArrayToString(data: any, size: number): string;
|
|
5
|
-
_addHexData(data: Uint8Array, incrementData: Uint8Array, size: number): void;
|
|
6
|
-
_performHexIncrement(data: Uint8Array, size: number): void;
|
|
7
|
-
_process(data: any, characterMap: any, enhance: any): any;
|
|
8
|
-
}
|
|
9
|
-
export declare class _PdfBinaryCMapStream {
|
|
10
|
-
_buffer: any;
|
|
11
|
-
_pos: number;
|
|
12
|
-
_end: number;
|
|
13
|
-
_tempBuffer: Uint8Array;
|
|
14
|
-
_maximumSize: number;
|
|
15
|
-
_maxEncodedNumberSize: number;
|
|
16
|
-
constructor(data: any);
|
|
17
|
-
_readByteData(): any;
|
|
18
|
-
_readNumber(): number;
|
|
19
|
-
_readSignedData(): number;
|
|
20
|
-
_readHexData(number: any, size: number): void;
|
|
21
|
-
_readHexDataNumber(number: any, size: number): void;
|
|
22
|
-
_readHexSignedData(number: any, size: number): void;
|
|
23
|
-
_readStringFromData(): string;
|
|
24
|
-
}
|