@pdftron/pdfnet-node-samples 10.8.0-beta → 10.9.0-1-beta
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/{samples/AddImageTest → AddImageTest}/AddImageTest.js +115 -115
- package/{samples/AdvancedImagingTest → AdvancedImagingTest}/AdvancedImagingTest.js +78 -78
- package/{samples/AnnotationTest → AnnotationTest}/AnnotationTest.js +641 -641
- package/{samples/BookmarkTest → BookmarkTest}/BookmarkTest.js +219 -219
- package/{samples/CAD2PDFTest → CAD2PDFTest}/CAD2PDFTest.js +79 -79
- package/{samples/ContentReplacerTest → ContentReplacerTest}/ContentReplacerTest.js +75 -75
- package/{samples/ConvertPrintTest → ConvertPrintTest}/ConvertPrintTest.js +153 -153
- package/{samples/ConvertTest → ConvertTest}/ConvertTest.js +203 -203
- package/{samples/DataExtractionTest → DataExtractionTest}/DataExtractionTest.js +214 -214
- package/{samples/DigitalSignaturesTest → DigitalSignaturesTest}/DigitalSignaturesTest.js +621 -526
- package/{samples/DocumentCreationTest → DocumentCreationTest}/DocumentCreationTest.js +409 -409
- package/{samples/ElementBuilderTest → ElementBuilderTest}/ElementBuilderTest.js +513 -513
- package/{samples/ElementEditTest → ElementEditTest}/ElementEditTest.js +110 -110
- package/{samples/ElementReaderAdvTest → ElementReaderAdvTest}/ElementReaderAdvTest.js +305 -305
- package/{samples/ElementReaderTest → ElementReaderTest}/ElementReaderTest.js +77 -77
- package/{samples/EncTest → EncTest}/EncTest.js +175 -175
- package/{samples/FDFTest → FDFTest}/FDFTest.js +218 -218
- package/{samples/HTML2PDFTest → HTML2PDFTest}/HTML2PDFTest.js +164 -164
- package/{samples/HighlightsTest → HighlightsTest}/HighlightsTest.js +97 -97
- package/{samples/ImageExtractTest → ImageExtractTest}/ImageExtractTest.js +129 -129
- package/{samples/ImpositionTest → ImpositionTest}/ImpositionTest.js +86 -86
- package/{samples/InteractiveFormsTest → InteractiveFormsTest}/InteractiveFormsTest.js +381 -381
- package/{samples/JBIG2Test → JBIG2Test}/JBIG2Test.js +88 -88
- package/{samples/LicenseKey → LicenseKey}/LicenseKey.js +11 -11
- package/{samples/LogicalStructureTest → LogicalStructureTest}/LogicalStructureTest.js +250 -250
- package/{samples/OCRTest → OCRTest}/OCRTest.js +235 -235
- package/{samples/OfficeTemplateTest → OfficeTemplateTest}/OfficeTemplateTest.js +79 -79
- package/{samples/OfficeToPDFTest → OfficeToPDFTest}/OfficeToPDFTest.js +125 -125
- package/{samples/OptimizerTest → OptimizerTest}/OptimizerTest.js +191 -191
- package/{samples/PDF2HtmlTest → PDF2HtmlTest}/PDF2HtmlTest.js +123 -123
- package/{samples/PDF2OfficeTest → PDF2OfficeTest}/PDF2OfficeTest.js +158 -158
- package/{samples/PDFATest → PDFATest}/PDFATest.js +85 -85
- package/{samples/PDFDocMemoryTest → PDFDocMemoryTest}/PDFDocMemoryTest.js +84 -84
- package/{samples/PDFDrawTest → PDFDrawTest}/PDFDrawTest.js +305 -305
- package/{samples/PDFLayersTest → PDFLayersTest}/PDFLayersTest.js +294 -294
- package/{samples/PDFPackageTest → PDFPackageTest}/PDFPackageTest.js +111 -111
- package/{samples/PDFPageTest → PDFPageTest}/PDFPageTest.js +189 -189
- package/{samples/PDFRedactTest → PDFRedactTest}/PDFRedactTest.js +74 -74
- package/{samples/PageLabelsTest → PageLabelsTest}/PageLabelsTest.js +138 -138
- package/{samples/PatternTest → PatternTest}/PatternTest.js +226 -226
- package/{samples/RectTest → RectTest}/RectTest.js +40 -40
- package/{samples/SDFTest → SDFTest}/SDFTest.js +87 -87
- package/{samples/StamperTest → StamperTest}/StamperTest.js +255 -255
- package/{samples/TestFiles → TestFiles}/Misc-Fixed.pfa +1166 -1166
- package/{samples/TestFiles → TestFiles}/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +34 -34
- package/{samples/TestFiles → TestFiles}/form1_annots.xfdf +33 -33
- package/{samples/TestFiles → TestFiles}/form1_data.xfdf +139 -139
- package/{samples/TestFiles → TestFiles}/my_stream.txt +2310 -2310
- package/{samples/TestFiles → TestFiles}/tiger.svg +378 -378
- package/{samples/TextExtractTest → TextExtractTest}/TextExtractTest.js +286 -286
- package/{samples/TextSearchTest → TextSearchTest}/TextSearchTest.js +121 -121
- package/{samples/U3DTest → U3DTest}/U3DTest.js +104 -104
- package/{samples/UndoRedoTest → UndoRedoTest}/UndoRedoTest.js +101 -101
- package/{samples/UnicodeWriteTest → UnicodeWriteTest}/UnicodeWriteTest.js +173 -173
- package/{samples/WebViewerConvertTest → WebViewerConvertTest}/WebViewerConvertTest.js +135 -135
- package/legal.txt +632 -0
- package/license.pdf +0 -0
- package/package.json +20 -20
- package/readme.md +38 -13
- package/{samples/runall.bat → runall.bat} +12 -12
- package/{samples/runall.sh → runall.sh} +15 -15
- /package/{samples/TestFiles → TestFiles}/BusinessCardTemplate.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/Fishermen.docx +0 -0
- /package/{samples/TestFiles → TestFiles}/Font_licenses.txt +0 -0
- /package/{samples/TestFiles → TestFiles}/GlobalSignRootForTST.cer +0 -0
- /package/{samples/TestFiles → TestFiles}/License.txt +0 -0
- /package/{samples/TestFiles → TestFiles}/NotoSans_with_hindi.ttf +0 -0
- /package/{samples/TestFiles → TestFiles}/Output/empty +0 -0
- /package/{samples/TestFiles → TestFiles}/SYH_Letter.docx +0 -0
- /package/{samples/TestFiles → TestFiles}/TigerText.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/US061222892-a.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/butterfly.png +0 -0
- /package/{samples/TestFiles → TestFiles}/credit card numbers.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/dice.jpg +0 -0
- /package/{samples/TestFiles → TestFiles}/dice.u3d +0 -0
- /package/{samples/TestFiles → TestFiles}/doc_to_sign.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/factsheet_Arabic.docx +0 -0
- /package/{samples/TestFiles → TestFiles}/financial.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/fish.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/font.ttf +0 -0
- /package/{samples/TestFiles → TestFiles}/form1.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/form1_data.fdf +0 -0
- /package/{samples/TestFiles → TestFiles}/formfields-scanned-withfields.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/formfields-scanned.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/formfields.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/grayscale.tif +0 -0
- /package/{samples/TestFiles → TestFiles}/hindi_sample_utf16le.txt +0 -0
- /package/{samples/TestFiles → TestFiles}/imagemask.dat +0 -0
- /package/{samples/TestFiles → TestFiles}/logo_red.png +0 -0
- /package/{samples/TestFiles → TestFiles}/lorem_ipsum.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/multipage.tif +0 -0
- /package/{samples/TestFiles → TestFiles}/newsletter.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/newsletter.xod +0 -0
- /package/{samples/TestFiles → TestFiles}/numbered.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/op_blend_test.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/palm.jp2 +0 -0
- /package/{samples/TestFiles → TestFiles}/paragraphs_and_tables.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/pdfnet.gif +0 -0
- /package/{samples/TestFiles → TestFiles}/pdftron.bmp +0 -0
- /package/{samples/TestFiles → TestFiles}/pdftron.cer +0 -0
- /package/{samples/TestFiles → TestFiles}/pdftron.pfx +0 -0
- /package/{samples/TestFiles → TestFiles}/pdftron_smart_substitution.plugin +0 -0
- /package/{samples/TestFiles → TestFiles}/peppers.jpg +0 -0
- /package/{samples/TestFiles → TestFiles}/signature.jpg +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-emf.emf +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-excel_2007.xlsx +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-outlook.msg +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-powerpoint_2007.pptx +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-publisher.pub +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-rtf.rtf +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-text.txt +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-visio.vsd +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage.html +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage.mht +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/colorschememapping.xml +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/filelist.xml +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image001.gif +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image002.png +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image003.jpg +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image004.emz +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image005.gif +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image006.png +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image007.gif +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/oledata.mso +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/themedata.thmx +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-word_2007.docx +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-xps.xps +0 -0
- /package/{samples/TestFiles → TestFiles}/table.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/tagged.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/the_rime_of_the_ancient_mariner.docx +0 -0
- /package/{samples/TestFiles → TestFiles}/tiger.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/waiver.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/waiver_withApprovalField.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/waiver_withApprovalField_certified.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/waiver_withApprovalField_certified_approved.pdf +0 -0
|
@@ -1,305 +1,305 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
|
|
3
|
-
// Consult legal.txt regarding legal and license information.
|
|
4
|
-
//---------------------------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
8
|
-
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
9
|
-
|
|
10
|
-
((exports) => {
|
|
11
|
-
|
|
12
|
-
exports.runElementReaderAdvTest = () => {
|
|
13
|
-
|
|
14
|
-
const processPath = async (reader, path) => {
|
|
15
|
-
if (await path.isClippingPath()) {
|
|
16
|
-
console.log('This is a clipping path');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const d = await path.getPathData();
|
|
20
|
-
|
|
21
|
-
const opr = d.operators;
|
|
22
|
-
const opr_len = opr.byteLength;
|
|
23
|
-
const data = d.points;
|
|
24
|
-
let data_idx = 0, data_len = data.byteLength / data.BYTES_PER_ELEMENT;
|
|
25
|
-
|
|
26
|
-
let x1, y1, x2, y2, x3, y3;
|
|
27
|
-
|
|
28
|
-
// Use path.GetCTM() if you are interested in CTM (current transformation matrix).
|
|
29
|
-
|
|
30
|
-
let path_str = ' Path Data Points := "';
|
|
31
|
-
for (let opr_idx = 0; opr_idx < opr_len; ++opr_idx) {
|
|
32
|
-
switch (opr[opr_idx]) {
|
|
33
|
-
case PDFNet.Element.PathSegmentType.e_moveto:
|
|
34
|
-
x1 = data[data_idx]; ++data_idx;
|
|
35
|
-
y1 = data[data_idx]; ++data_idx;
|
|
36
|
-
path_str += 'M' + Math.round(x1) + ' ' + Math.round(y1);
|
|
37
|
-
break;
|
|
38
|
-
case PDFNet.Element.PathSegmentType.e_lineto:
|
|
39
|
-
x1 = data[data_idx]; ++data_idx;
|
|
40
|
-
y1 = data[data_idx]; ++data_idx;
|
|
41
|
-
path_str += 'L' + Math.round(x1) + ' ' + Math.round(y1);
|
|
42
|
-
break;
|
|
43
|
-
case PDFNet.Element.PathSegmentType.e_cubicto:
|
|
44
|
-
x1 = data[data_idx]; ++data_idx;
|
|
45
|
-
y1 = data[data_idx]; ++data_idx;
|
|
46
|
-
x2 = data[data_idx]; ++data_idx;
|
|
47
|
-
y2 = data[data_idx]; ++data_idx;
|
|
48
|
-
x3 = data[data_idx]; ++data_idx;
|
|
49
|
-
y3 = data[data_idx]; ++data_idx;
|
|
50
|
-
path_str += 'C' + Math.round(x1) + ' ' + Math.round(y1) + ' ' + Math.round(x2)
|
|
51
|
-
+ ' ' + Math.round(y2) + ' ' + Math.round(x3) + ' ' + Math.round(y3);
|
|
52
|
-
break;
|
|
53
|
-
case PDFNet.Element.PathSegmentType.e_rect:
|
|
54
|
-
x1 = data[data_idx]; ++data_idx;
|
|
55
|
-
y1 = data[data_idx]; ++data_idx;
|
|
56
|
-
const w = data[data_idx]; ++data_idx;
|
|
57
|
-
const h = data[data_idx]; ++data_idx;
|
|
58
|
-
x2 = x1 + w;
|
|
59
|
-
y2 = y1;
|
|
60
|
-
x3 = x2;
|
|
61
|
-
y3 = y1 + h;
|
|
62
|
-
const x4 = x1;
|
|
63
|
-
const y4 = y3;
|
|
64
|
-
path_str += 'M' + Math.round(x1) + ' ' + Math.round(y1) + ' L' + Math.round(x2) + ' ' + Math.round(y2)
|
|
65
|
-
+ ' L' + Math.round(x3) + ' ' + Math.round(y3) + ' L' + Math.round(x4) + ' ' + Math.round(y4) + ' Z';
|
|
66
|
-
break;
|
|
67
|
-
case PDFNet.Element.PathSegmentType.e_closepath:
|
|
68
|
-
path_str += ' Close Path\n';
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
throw ''
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
path_str += '" ';
|
|
77
|
-
|
|
78
|
-
const gs = await path.getGState();
|
|
79
|
-
|
|
80
|
-
// Set Path State 0 (stroke, fill, fill-rule) -----------------------------------
|
|
81
|
-
if (await path.isStroked()) {
|
|
82
|
-
console.log(path_str + 'Stroke path');
|
|
83
|
-
path_str = '';
|
|
84
|
-
|
|
85
|
-
if (await (await gs.getStrokeColorSpace()).getType() === PDFNet.ColorSpace.Type.e_pattern) {
|
|
86
|
-
console.log('Path has associated pattern');
|
|
87
|
-
} else {
|
|
88
|
-
// Get stroke color (you can use PDFNet color conversion facilities)
|
|
89
|
-
// ColorPt rgb;
|
|
90
|
-
// gs.GetStrokeColorSpace().Convert2RGB(gs.GetStrokeColor(), rgb);
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
// Do not stroke path
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (await path.isFilled()) {
|
|
97
|
-
console.log(path_str + 'Fill path');
|
|
98
|
-
path_str = '';
|
|
99
|
-
|
|
100
|
-
if (await (await gs.getFillColorSpace()).getType() === PDFNet.ColorSpace.Type.e_pattern) {
|
|
101
|
-
console.log('Path has associated pattern');
|
|
102
|
-
} else {
|
|
103
|
-
// ColorPt rgb;
|
|
104
|
-
// gs.GetFillColorSpace().Convert2RGB(gs.GetFillColor(), rgb);
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
// Do not fill path
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (path_str) {
|
|
111
|
-
console.log(path_str);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Process any changes in graphics state ---------------------------------
|
|
115
|
-
|
|
116
|
-
const gs_itr = await reader.getChangesIterator();
|
|
117
|
-
for (; await gs_itr.hasNext(); await gs_itr.next()) {
|
|
118
|
-
switch (await gs_itr.current()) {
|
|
119
|
-
case PDFNet.GState.Attribute.e_transform:
|
|
120
|
-
// Get transform matrix for this element. Unlike path.GetCTM()
|
|
121
|
-
// that return full transformation matrix gs.GetTransform() return
|
|
122
|
-
// only the transformation matrix that was installed for this element.
|
|
123
|
-
//
|
|
124
|
-
// gs.GetTransform();
|
|
125
|
-
break;
|
|
126
|
-
case PDFNet.GState.Attribute.e_line_width:
|
|
127
|
-
// gs.GetLineWidth();
|
|
128
|
-
break;
|
|
129
|
-
case PDFNet.GState.Attribute.e_line_cap:
|
|
130
|
-
// gs.GetLineCap();
|
|
131
|
-
break;
|
|
132
|
-
case PDFNet.GState.Attribute.e_line_join:
|
|
133
|
-
// gs.GetLineJoin();
|
|
134
|
-
break;
|
|
135
|
-
case PDFNet.GState.Attribute.e_flatness:
|
|
136
|
-
break;
|
|
137
|
-
case PDFNet.GState.Attribute.e_miter_limit:
|
|
138
|
-
// gs.GetMiterLimit();
|
|
139
|
-
break;
|
|
140
|
-
case PDFNet.GState.Attribute.e_dash_pattern:
|
|
141
|
-
{
|
|
142
|
-
// std::vector<double> dashes;
|
|
143
|
-
// gs.GetDashes(dashes);
|
|
144
|
-
// gs.GetPhase()
|
|
145
|
-
}
|
|
146
|
-
break;
|
|
147
|
-
case PDFNet.GState.Attribute.e_fill_color:
|
|
148
|
-
{
|
|
149
|
-
if (await (await gs.getFillColorSpace()).getType() === PDFNet.ColorSpace.Type.e_pattern &&
|
|
150
|
-
await (await gs.getFillPattern()).getType() !== PDFNet.PatternColor.Type.e_shading) {
|
|
151
|
-
//process the pattern data
|
|
152
|
-
await reader.patternBegin(true);
|
|
153
|
-
await processElements(reader);
|
|
154
|
-
await reader.end();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
await reader.clearChangeList();
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const processText = async (pageReader) => {
|
|
164
|
-
// Begin text element
|
|
165
|
-
console.log('Begin Text Block:');
|
|
166
|
-
|
|
167
|
-
let element;
|
|
168
|
-
while (element = await pageReader.next()) {
|
|
169
|
-
switch (await element.getType()) {
|
|
170
|
-
case PDFNet.Element.Type.e_text_end:
|
|
171
|
-
// Finish the text block
|
|
172
|
-
console.log('End Text Block.');
|
|
173
|
-
return;
|
|
174
|
-
|
|
175
|
-
case PDFNet.Element.Type.e_text:
|
|
176
|
-
const gs = await element.getGState();
|
|
177
|
-
|
|
178
|
-
const cs_fill = await gs.getFillColorSpace();
|
|
179
|
-
const fill = await gs.getFillColor();
|
|
180
|
-
|
|
181
|
-
const out = await cs_fill.convert2RGB(fill);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const cs_stroke = await gs.getStrokeColorSpace();
|
|
185
|
-
const stroke = await gs.getStrokeColor();
|
|
186
|
-
|
|
187
|
-
const font = await gs.getFont();
|
|
188
|
-
|
|
189
|
-
console.log('Font Name: ' + await font.getName());
|
|
190
|
-
|
|
191
|
-
let outPutStr = '';
|
|
192
|
-
if (await font.getType() == PDFNet.Font.Type.e_Type3) {
|
|
193
|
-
//type 3 font, process its data
|
|
194
|
-
for (const itr = await element.getCharIterator(); await itr.hasNext(); await itr.next()) {
|
|
195
|
-
await pageReader.type3FontBegin(await itr.current());
|
|
196
|
-
await processElements(pageReader);
|
|
197
|
-
await pageReader.end();
|
|
198
|
-
}
|
|
199
|
-
} else {
|
|
200
|
-
const text_mtx = await element.getTextMatrix();
|
|
201
|
-
|
|
202
|
-
for (const itr = await element.getCharIterator(); await itr.hasNext(); await itr.next()) {
|
|
203
|
-
outPutStr += 'Character code: ';
|
|
204
|
-
const charData = await itr.current();
|
|
205
|
-
const charCode = charData.char_code;
|
|
206
|
-
if (charCode >= 32 || charCode <= 127) {
|
|
207
|
-
// Print if in ASCII range...
|
|
208
|
-
outPutStr += String.fromCharCode(charCode);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const x = charData.x; // character positioning information
|
|
212
|
-
const y = charData.y;
|
|
213
|
-
|
|
214
|
-
// Use element.GetCTM() if you are interested in the CTM
|
|
215
|
-
// (current transformation matrix).
|
|
216
|
-
const ctm = await element.getCTM();
|
|
217
|
-
|
|
218
|
-
// To get the exact character positioning information you need to
|
|
219
|
-
// concatenate current text matrix with CTM and then multiply
|
|
220
|
-
// relative positioning coordinates with the resulting matrix.
|
|
221
|
-
await ctm.multiply(text_mtx);
|
|
222
|
-
await ctm.mult(x, y);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
console.log(outPutStr);
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const processImage = async (image) => {
|
|
232
|
-
const width = await image.getImageWidth();
|
|
233
|
-
const height = await image.getImageHeight();
|
|
234
|
-
const out_data_sz = await width * height * 3;
|
|
235
|
-
|
|
236
|
-
console.log('Image: width=\'' + width + '\' height=\'' + height + '\'');
|
|
237
|
-
|
|
238
|
-
const img_conv = await PDFNet.Filter.createImage2RGBFromElement(image); // Extract and convert image to RGB 8-bpc format
|
|
239
|
-
const reader = await PDFNet.FilterReader.create(img_conv);
|
|
240
|
-
|
|
241
|
-
const image_data_out = await reader.read(out_data_sz);
|
|
242
|
-
|
|
243
|
-
// Note that you don't need to read a whole image at a time. Alternatively
|
|
244
|
-
// you can read a chuck at a time by repeatedly calling reader.Read(buf, buf_sz)
|
|
245
|
-
// until the function returns 0.
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const processElements = async (reader) => {
|
|
249
|
-
let element;
|
|
250
|
-
while (element = await reader.next()) { // Read page contents
|
|
251
|
-
switch (await element.getType()) {
|
|
252
|
-
case PDFNet.Element.Type.e_path: // Process path data...
|
|
253
|
-
await processPath(reader, element);
|
|
254
|
-
break;
|
|
255
|
-
case PDFNet.Element.Type.e_text_begin: // Process text block...
|
|
256
|
-
await processText(reader);
|
|
257
|
-
break;
|
|
258
|
-
case PDFNet.Element.Type.e_form: // Process form XObjects
|
|
259
|
-
await reader.formBegin();
|
|
260
|
-
await processElements(reader);
|
|
261
|
-
await reader.end();
|
|
262
|
-
break;
|
|
263
|
-
case PDFNet.Element.Type.e_image: // Process Images
|
|
264
|
-
await processImage(element);
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const main = async () => {
|
|
271
|
-
// Relative path to the folder containing test files.
|
|
272
|
-
const inputPath = '../TestFiles/';
|
|
273
|
-
try {
|
|
274
|
-
console.log('-------------------------------------------------');
|
|
275
|
-
console.log('Extract page element information from all ');
|
|
276
|
-
console.log('pages in the document.');
|
|
277
|
-
|
|
278
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
|
|
279
|
-
doc.initSecurityHandler();
|
|
280
|
-
|
|
281
|
-
const pgnum = await doc.getPageCount();
|
|
282
|
-
const pageBegin = await doc.getPageIterator();
|
|
283
|
-
|
|
284
|
-
const pageReader = await PDFNet.ElementReader.create();
|
|
285
|
-
|
|
286
|
-
for (const itr = pageBegin; await itr.hasNext(); await itr.next()) // Read every page
|
|
287
|
-
{
|
|
288
|
-
const curPage = await itr.current();
|
|
289
|
-
console.log('Page ' + await curPage.getIndex() + '----------------------------------------');
|
|
290
|
-
await pageReader.beginOnPage(curPage);
|
|
291
|
-
await processElements(pageReader);
|
|
292
|
-
await pageReader.end();
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
console.log('Done.');
|
|
296
|
-
} catch (err) {
|
|
297
|
-
console.log(err);
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
301
|
-
};
|
|
302
|
-
exports.runElementReaderAdvTest();
|
|
303
|
-
})(exports);
|
|
304
|
-
// eslint-disable-next-line spaced-comment
|
|
305
|
-
//# sourceURL=ElementReaderAdvTest.js
|
|
1
|
+
//---------------------------------------------------------------------------------------
|
|
2
|
+
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
|
|
3
|
+
// Consult legal.txt regarding legal and license information.
|
|
4
|
+
//---------------------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
8
|
+
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
9
|
+
|
|
10
|
+
((exports) => {
|
|
11
|
+
|
|
12
|
+
exports.runElementReaderAdvTest = () => {
|
|
13
|
+
|
|
14
|
+
const processPath = async (reader, path) => {
|
|
15
|
+
if (await path.isClippingPath()) {
|
|
16
|
+
console.log('This is a clipping path');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const d = await path.getPathData();
|
|
20
|
+
|
|
21
|
+
const opr = d.operators;
|
|
22
|
+
const opr_len = opr.byteLength;
|
|
23
|
+
const data = d.points;
|
|
24
|
+
let data_idx = 0, data_len = data.byteLength / data.BYTES_PER_ELEMENT;
|
|
25
|
+
|
|
26
|
+
let x1, y1, x2, y2, x3, y3;
|
|
27
|
+
|
|
28
|
+
// Use path.GetCTM() if you are interested in CTM (current transformation matrix).
|
|
29
|
+
|
|
30
|
+
let path_str = ' Path Data Points := "';
|
|
31
|
+
for (let opr_idx = 0; opr_idx < opr_len; ++opr_idx) {
|
|
32
|
+
switch (opr[opr_idx]) {
|
|
33
|
+
case PDFNet.Element.PathSegmentType.e_moveto:
|
|
34
|
+
x1 = data[data_idx]; ++data_idx;
|
|
35
|
+
y1 = data[data_idx]; ++data_idx;
|
|
36
|
+
path_str += 'M' + Math.round(x1) + ' ' + Math.round(y1);
|
|
37
|
+
break;
|
|
38
|
+
case PDFNet.Element.PathSegmentType.e_lineto:
|
|
39
|
+
x1 = data[data_idx]; ++data_idx;
|
|
40
|
+
y1 = data[data_idx]; ++data_idx;
|
|
41
|
+
path_str += 'L' + Math.round(x1) + ' ' + Math.round(y1);
|
|
42
|
+
break;
|
|
43
|
+
case PDFNet.Element.PathSegmentType.e_cubicto:
|
|
44
|
+
x1 = data[data_idx]; ++data_idx;
|
|
45
|
+
y1 = data[data_idx]; ++data_idx;
|
|
46
|
+
x2 = data[data_idx]; ++data_idx;
|
|
47
|
+
y2 = data[data_idx]; ++data_idx;
|
|
48
|
+
x3 = data[data_idx]; ++data_idx;
|
|
49
|
+
y3 = data[data_idx]; ++data_idx;
|
|
50
|
+
path_str += 'C' + Math.round(x1) + ' ' + Math.round(y1) + ' ' + Math.round(x2)
|
|
51
|
+
+ ' ' + Math.round(y2) + ' ' + Math.round(x3) + ' ' + Math.round(y3);
|
|
52
|
+
break;
|
|
53
|
+
case PDFNet.Element.PathSegmentType.e_rect:
|
|
54
|
+
x1 = data[data_idx]; ++data_idx;
|
|
55
|
+
y1 = data[data_idx]; ++data_idx;
|
|
56
|
+
const w = data[data_idx]; ++data_idx;
|
|
57
|
+
const h = data[data_idx]; ++data_idx;
|
|
58
|
+
x2 = x1 + w;
|
|
59
|
+
y2 = y1;
|
|
60
|
+
x3 = x2;
|
|
61
|
+
y3 = y1 + h;
|
|
62
|
+
const x4 = x1;
|
|
63
|
+
const y4 = y3;
|
|
64
|
+
path_str += 'M' + Math.round(x1) + ' ' + Math.round(y1) + ' L' + Math.round(x2) + ' ' + Math.round(y2)
|
|
65
|
+
+ ' L' + Math.round(x3) + ' ' + Math.round(y3) + ' L' + Math.round(x4) + ' ' + Math.round(y4) + ' Z';
|
|
66
|
+
break;
|
|
67
|
+
case PDFNet.Element.PathSegmentType.e_closepath:
|
|
68
|
+
path_str += ' Close Path\n';
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
throw ''
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
path_str += '" ';
|
|
77
|
+
|
|
78
|
+
const gs = await path.getGState();
|
|
79
|
+
|
|
80
|
+
// Set Path State 0 (stroke, fill, fill-rule) -----------------------------------
|
|
81
|
+
if (await path.isStroked()) {
|
|
82
|
+
console.log(path_str + 'Stroke path');
|
|
83
|
+
path_str = '';
|
|
84
|
+
|
|
85
|
+
if (await (await gs.getStrokeColorSpace()).getType() === PDFNet.ColorSpace.Type.e_pattern) {
|
|
86
|
+
console.log('Path has associated pattern');
|
|
87
|
+
} else {
|
|
88
|
+
// Get stroke color (you can use PDFNet color conversion facilities)
|
|
89
|
+
// ColorPt rgb;
|
|
90
|
+
// gs.GetStrokeColorSpace().Convert2RGB(gs.GetStrokeColor(), rgb);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
// Do not stroke path
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (await path.isFilled()) {
|
|
97
|
+
console.log(path_str + 'Fill path');
|
|
98
|
+
path_str = '';
|
|
99
|
+
|
|
100
|
+
if (await (await gs.getFillColorSpace()).getType() === PDFNet.ColorSpace.Type.e_pattern) {
|
|
101
|
+
console.log('Path has associated pattern');
|
|
102
|
+
} else {
|
|
103
|
+
// ColorPt rgb;
|
|
104
|
+
// gs.GetFillColorSpace().Convert2RGB(gs.GetFillColor(), rgb);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
// Do not fill path
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (path_str) {
|
|
111
|
+
console.log(path_str);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Process any changes in graphics state ---------------------------------
|
|
115
|
+
|
|
116
|
+
const gs_itr = await reader.getChangesIterator();
|
|
117
|
+
for (; await gs_itr.hasNext(); await gs_itr.next()) {
|
|
118
|
+
switch (await gs_itr.current()) {
|
|
119
|
+
case PDFNet.GState.Attribute.e_transform:
|
|
120
|
+
// Get transform matrix for this element. Unlike path.GetCTM()
|
|
121
|
+
// that return full transformation matrix gs.GetTransform() return
|
|
122
|
+
// only the transformation matrix that was installed for this element.
|
|
123
|
+
//
|
|
124
|
+
// gs.GetTransform();
|
|
125
|
+
break;
|
|
126
|
+
case PDFNet.GState.Attribute.e_line_width:
|
|
127
|
+
// gs.GetLineWidth();
|
|
128
|
+
break;
|
|
129
|
+
case PDFNet.GState.Attribute.e_line_cap:
|
|
130
|
+
// gs.GetLineCap();
|
|
131
|
+
break;
|
|
132
|
+
case PDFNet.GState.Attribute.e_line_join:
|
|
133
|
+
// gs.GetLineJoin();
|
|
134
|
+
break;
|
|
135
|
+
case PDFNet.GState.Attribute.e_flatness:
|
|
136
|
+
break;
|
|
137
|
+
case PDFNet.GState.Attribute.e_miter_limit:
|
|
138
|
+
// gs.GetMiterLimit();
|
|
139
|
+
break;
|
|
140
|
+
case PDFNet.GState.Attribute.e_dash_pattern:
|
|
141
|
+
{
|
|
142
|
+
// std::vector<double> dashes;
|
|
143
|
+
// gs.GetDashes(dashes);
|
|
144
|
+
// gs.GetPhase()
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
case PDFNet.GState.Attribute.e_fill_color:
|
|
148
|
+
{
|
|
149
|
+
if (await (await gs.getFillColorSpace()).getType() === PDFNet.ColorSpace.Type.e_pattern &&
|
|
150
|
+
await (await gs.getFillPattern()).getType() !== PDFNet.PatternColor.Type.e_shading) {
|
|
151
|
+
//process the pattern data
|
|
152
|
+
await reader.patternBegin(true);
|
|
153
|
+
await processElements(reader);
|
|
154
|
+
await reader.end();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
await reader.clearChangeList();
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const processText = async (pageReader) => {
|
|
164
|
+
// Begin text element
|
|
165
|
+
console.log('Begin Text Block:');
|
|
166
|
+
|
|
167
|
+
let element;
|
|
168
|
+
while (element = await pageReader.next()) {
|
|
169
|
+
switch (await element.getType()) {
|
|
170
|
+
case PDFNet.Element.Type.e_text_end:
|
|
171
|
+
// Finish the text block
|
|
172
|
+
console.log('End Text Block.');
|
|
173
|
+
return;
|
|
174
|
+
|
|
175
|
+
case PDFNet.Element.Type.e_text:
|
|
176
|
+
const gs = await element.getGState();
|
|
177
|
+
|
|
178
|
+
const cs_fill = await gs.getFillColorSpace();
|
|
179
|
+
const fill = await gs.getFillColor();
|
|
180
|
+
|
|
181
|
+
const out = await cs_fill.convert2RGB(fill);
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
const cs_stroke = await gs.getStrokeColorSpace();
|
|
185
|
+
const stroke = await gs.getStrokeColor();
|
|
186
|
+
|
|
187
|
+
const font = await gs.getFont();
|
|
188
|
+
|
|
189
|
+
console.log('Font Name: ' + await font.getName());
|
|
190
|
+
|
|
191
|
+
let outPutStr = '';
|
|
192
|
+
if (await font.getType() == PDFNet.Font.Type.e_Type3) {
|
|
193
|
+
//type 3 font, process its data
|
|
194
|
+
for (const itr = await element.getCharIterator(); await itr.hasNext(); await itr.next()) {
|
|
195
|
+
await pageReader.type3FontBegin(await itr.current());
|
|
196
|
+
await processElements(pageReader);
|
|
197
|
+
await pageReader.end();
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
const text_mtx = await element.getTextMatrix();
|
|
201
|
+
|
|
202
|
+
for (const itr = await element.getCharIterator(); await itr.hasNext(); await itr.next()) {
|
|
203
|
+
outPutStr += 'Character code: ';
|
|
204
|
+
const charData = await itr.current();
|
|
205
|
+
const charCode = charData.char_code;
|
|
206
|
+
if (charCode >= 32 || charCode <= 127) {
|
|
207
|
+
// Print if in ASCII range...
|
|
208
|
+
outPutStr += String.fromCharCode(charCode);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const x = charData.x; // character positioning information
|
|
212
|
+
const y = charData.y;
|
|
213
|
+
|
|
214
|
+
// Use element.GetCTM() if you are interested in the CTM
|
|
215
|
+
// (current transformation matrix).
|
|
216
|
+
const ctm = await element.getCTM();
|
|
217
|
+
|
|
218
|
+
// To get the exact character positioning information you need to
|
|
219
|
+
// concatenate current text matrix with CTM and then multiply
|
|
220
|
+
// relative positioning coordinates with the resulting matrix.
|
|
221
|
+
await ctm.multiply(text_mtx);
|
|
222
|
+
await ctm.mult(x, y);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
console.log(outPutStr);
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const processImage = async (image) => {
|
|
232
|
+
const width = await image.getImageWidth();
|
|
233
|
+
const height = await image.getImageHeight();
|
|
234
|
+
const out_data_sz = await width * height * 3;
|
|
235
|
+
|
|
236
|
+
console.log('Image: width=\'' + width + '\' height=\'' + height + '\'');
|
|
237
|
+
|
|
238
|
+
const img_conv = await PDFNet.Filter.createImage2RGBFromElement(image); // Extract and convert image to RGB 8-bpc format
|
|
239
|
+
const reader = await PDFNet.FilterReader.create(img_conv);
|
|
240
|
+
|
|
241
|
+
const image_data_out = await reader.read(out_data_sz);
|
|
242
|
+
|
|
243
|
+
// Note that you don't need to read a whole image at a time. Alternatively
|
|
244
|
+
// you can read a chuck at a time by repeatedly calling reader.Read(buf, buf_sz)
|
|
245
|
+
// until the function returns 0.
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const processElements = async (reader) => {
|
|
249
|
+
let element;
|
|
250
|
+
while (element = await reader.next()) { // Read page contents
|
|
251
|
+
switch (await element.getType()) {
|
|
252
|
+
case PDFNet.Element.Type.e_path: // Process path data...
|
|
253
|
+
await processPath(reader, element);
|
|
254
|
+
break;
|
|
255
|
+
case PDFNet.Element.Type.e_text_begin: // Process text block...
|
|
256
|
+
await processText(reader);
|
|
257
|
+
break;
|
|
258
|
+
case PDFNet.Element.Type.e_form: // Process form XObjects
|
|
259
|
+
await reader.formBegin();
|
|
260
|
+
await processElements(reader);
|
|
261
|
+
await reader.end();
|
|
262
|
+
break;
|
|
263
|
+
case PDFNet.Element.Type.e_image: // Process Images
|
|
264
|
+
await processImage(element);
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const main = async () => {
|
|
271
|
+
// Relative path to the folder containing test files.
|
|
272
|
+
const inputPath = '../TestFiles/';
|
|
273
|
+
try {
|
|
274
|
+
console.log('-------------------------------------------------');
|
|
275
|
+
console.log('Extract page element information from all ');
|
|
276
|
+
console.log('pages in the document.');
|
|
277
|
+
|
|
278
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
|
|
279
|
+
doc.initSecurityHandler();
|
|
280
|
+
|
|
281
|
+
const pgnum = await doc.getPageCount();
|
|
282
|
+
const pageBegin = await doc.getPageIterator();
|
|
283
|
+
|
|
284
|
+
const pageReader = await PDFNet.ElementReader.create();
|
|
285
|
+
|
|
286
|
+
for (const itr = pageBegin; await itr.hasNext(); await itr.next()) // Read every page
|
|
287
|
+
{
|
|
288
|
+
const curPage = await itr.current();
|
|
289
|
+
console.log('Page ' + await curPage.getIndex() + '----------------------------------------');
|
|
290
|
+
await pageReader.beginOnPage(curPage);
|
|
291
|
+
await processElements(pageReader);
|
|
292
|
+
await pageReader.end();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
console.log('Done.');
|
|
296
|
+
} catch (err) {
|
|
297
|
+
console.log(err);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
301
|
+
};
|
|
302
|
+
exports.runElementReaderAdvTest();
|
|
303
|
+
})(exports);
|
|
304
|
+
// eslint-disable-next-line spaced-comment
|
|
305
|
+
//# sourceURL=ElementReaderAdvTest.js
|