@pdftron/pdfnet-node-samples 9.1.0-2 → 9.2.0
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/package.json +18 -18
- package/samples/AddImageTest/AddImageTest.js +115 -115
- package/samples/AdvancedImagingTest/AdvancedImagingTest.js +64 -64
- package/samples/AnnotationTest/AnnotationTest.js +641 -641
- package/samples/BookmarkTest/BookmarkTest.js +219 -219
- package/samples/ContentReplacerTest/ContentReplacerTest.js +75 -75
- package/samples/ElementBuilderTest/ElementBuilderTest.js +513 -513
- package/samples/ElementEditTest/ElementEditTest.js +110 -110
- package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +305 -305
- package/samples/ElementReaderTest/ElementReaderTest.js +77 -77
- package/samples/EncTest/EncTest.js +175 -175
- package/samples/LicenseKey/LicenseKey.js +11 -11
- package/samples/LogicalStructureTest/LogicalStructureTest.js +250 -250
- package/samples/PDF2HtmlTest/PDF2HtmlTest.js +123 -117
- package/samples/PDF2OfficeTest/PDF2OfficeTest.js +158 -0
- package/samples/PDF2OfficeTest/RunTest.bat +2 -0
- package/samples/PDF2OfficeTest/RunTest.sh +2 -0
- package/samples/PDFATest/PDFATest.js +85 -85
- package/samples/PDFDrawTest/PDFDrawTest.js +305 -305
- package/samples/PDFLayersTest/PDFLayersTest.js +294 -294
- package/samples/PDFPageTest/PDFPageTest.js +189 -189
- package/samples/PDFRedactTest/PDFRedactTest.js +74 -74
- package/samples/RectTest/RectTest.js +40 -40
- package/samples/SDFTest/SDFTest.js +88 -88
- package/samples/StamperTest/StamperTest.js +255 -255
- package/samples/TestFiles/Misc-Fixed.pfa +1166 -1166
- package/samples/TestFiles/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +34 -34
- package/samples/TestFiles/form1_annots.xfdf +33 -33
- package/samples/TestFiles/form1_data.xfdf +139 -139
- package/samples/TestFiles/my_stream.txt +2310 -2310
- package/samples/TextExtractTest/TextExtractTest.js +286 -286
- package/samples/TextSearchTest/TextSearchTest.js +121 -121
- package/samples/UndoRedoTest/UndoRedoTest.js +101 -101
- package/samples/UnicodeWriteTest/UnicodeWriteTest.js +173 -173
- package/samples/runall.bat +3 -3
- package/samples/runall.sh +14 -14
- package/samples/PDF2WordTest/PDF2WordTest.js +0 -85
- package/samples/PDF2WordTest/RunTest.bat +0 -2
- package/samples/PDF2WordTest/RunTest.sh +0 -2
- package/samples/TestFiles/Output/addimage.pdf +0 -0
- package/samples/TestFiles/Output/annotation_test1.pdf +0 -0
- package/samples/TestFiles/Output/annotation_test2.pdf +0 -0
- package/samples/TestFiles/Output/bookmark.pdf +0 -0
- package/samples/TestFiles/Output/bookmark_remote.pdf +0 -0
- package/samples/TestFiles/Output/new_annot_test_api.pdf +0 -0
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
|
|
3
|
-
// Consult legal.txt regarding legal and license information.
|
|
4
|
-
//---------------------------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
const process = require('process');
|
|
8
|
-
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
9
|
-
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
10
|
-
|
|
11
|
-
((exports) => {
|
|
12
|
-
|
|
13
|
-
exports.runUnicodeWriteTest = () => {
|
|
14
|
-
|
|
15
|
-
const main = async () => {
|
|
16
|
-
try {
|
|
17
|
-
// Relative path to the folder containing test files.
|
|
18
|
-
const inputPath = '../TestFiles/';
|
|
19
|
-
const outputPath = '../TestFiles/Output/';
|
|
20
|
-
|
|
21
|
-
const doc = await PDFNet.PDFDoc.create();
|
|
22
|
-
doc.initSecurityHandler();
|
|
23
|
-
|
|
24
|
-
const eb = await PDFNet.ElementBuilder.create(); // ElementBuilder, used to build new element Objects
|
|
25
|
-
const writer = await PDFNet.ElementWriter.create(); // ElementWriter, used to write elements to the page
|
|
26
|
-
|
|
27
|
-
// Start a new page ------------------------------------
|
|
28
|
-
let page = await doc.pageCreate(new PDFNet.Rect(0, 0, 612, 794));
|
|
29
|
-
|
|
30
|
-
await writer.beginOnPage(page);
|
|
31
|
-
|
|
32
|
-
let font_program = inputPath + 'ARIALUNI.TTF';
|
|
33
|
-
|
|
34
|
-
if (!fs.existsSync(font_program)) {
|
|
35
|
-
font_program = 'C:/Windows/Fonts/ARIALUNI.TTF';
|
|
36
|
-
if (process.platform !== 'win32' || !fs.existsSync(font_program)) {
|
|
37
|
-
font_program = '';
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let fnt;
|
|
42
|
-
if (font_program.length) {
|
|
43
|
-
console.log('Note: using ' + font_program + ' for unshaped unicode text');
|
|
44
|
-
// if we can find a specific wide-coverage font file, then use that directly
|
|
45
|
-
fnt = await PDFNet.Font.createCIDTrueTypeFont(doc, font_program, true, true);
|
|
46
|
-
} else {
|
|
47
|
-
console.log('Note: using system font substitution for unshaped unicode text');
|
|
48
|
-
// if we can't find a specific file, then use system font subsitution
|
|
49
|
-
// as a fallback, using 'Helvetica' as a hint
|
|
50
|
-
fnt = await PDFNet.Font.createFromName(doc, 'Helvetica', '');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let element = await eb.createTextBeginWithFont(fnt, 1);
|
|
54
|
-
await element.setTextMatrixEntries(10, 0, 0, 10, 50, 600);
|
|
55
|
-
await (await element.getGState()).setLeading(2); // Set the spacing between lines
|
|
56
|
-
await writer.writeElement(element);
|
|
57
|
-
|
|
58
|
-
// Hello World!
|
|
59
|
-
const hello = 'Hello World!';
|
|
60
|
-
await writer.writeElement(await eb.createUnicodeTextRun(hello));
|
|
61
|
-
await writer.writeElement(await eb.createTextNewLine());
|
|
62
|
-
|
|
63
|
-
// Latin
|
|
64
|
-
const latin = 'aAbBcCdD' + String.fromCharCode(0x45, 0x0046, 0x00C0, 0x00C1, 0x00C2, 0x0143, 0x0144, 0x0145, 0x0152) + '12';
|
|
65
|
-
await writer.writeElement(await eb.createUnicodeTextRun(latin));
|
|
66
|
-
await writer.writeElement(await eb.createTextNewLine());
|
|
67
|
-
|
|
68
|
-
// Greek
|
|
69
|
-
const greek = String.fromCharCode(0x039E, 0x039F, 0x03A0, 0x03A1, 0x03A3, 0x03A6, 0x03A8, 0x03A9);
|
|
70
|
-
await writer.writeElement(await eb.createUnicodeTextRun(greek));
|
|
71
|
-
await writer.writeElement(await eb.createTextNewLine());
|
|
72
|
-
|
|
73
|
-
// Cyrillic
|
|
74
|
-
const cyrillic = String.fromCharCode(
|
|
75
|
-
0x0409, 0x040A, 0x040B, 0x040C, 0x040E, 0x040F, 0x0410, 0x0411,
|
|
76
|
-
0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419);
|
|
77
|
-
await writer.writeElement(await eb.createUnicodeTextRun(cyrillic));
|
|
78
|
-
await writer.writeElement(await eb.createTextNewLine());
|
|
79
|
-
|
|
80
|
-
// Hebrew
|
|
81
|
-
const hebrew = String.fromCharCode(
|
|
82
|
-
0x05D0, 0x05D1, 0x05D3, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, 0x05D8,
|
|
83
|
-
0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF, 0x05E0, 0x05E1);
|
|
84
|
-
await writer.writeElement(await eb.createUnicodeTextRun(hebrew));
|
|
85
|
-
await writer.writeElement(await eb.createTextNewLine());
|
|
86
|
-
|
|
87
|
-
// Arabic
|
|
88
|
-
const arabic = String.fromCharCode(
|
|
89
|
-
0x0624, 0x0625, 0x0626, 0x0627, 0x0628, 0x0629, 0x062A, 0x062B, 0x062C,
|
|
90
|
-
0x062D, 0x062E, 0x062F, 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635);
|
|
91
|
-
await writer.writeElement(await eb.createUnicodeTextRun(arabic));
|
|
92
|
-
await writer.writeElement(await eb.createTextNewLine());
|
|
93
|
-
|
|
94
|
-
// Thai
|
|
95
|
-
const thai = String.fromCharCode(
|
|
96
|
-
0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07, 0x0E08, 0x0E09,
|
|
97
|
-
0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F, 0x0E10, 0x0E11, 0x0E12);
|
|
98
|
-
await writer.writeElement(await eb.createUnicodeTextRun(thai));
|
|
99
|
-
await writer.writeElement(await eb.createTextNewLine());
|
|
100
|
-
|
|
101
|
-
// Hiragana - Japanese
|
|
102
|
-
const hiragana = String.fromCharCode(
|
|
103
|
-
0x3041, 0x3042, 0x3043, 0x3044, 0x3045, 0x3046, 0x3047, 0x3048, 0x3049,
|
|
104
|
-
0x304A, 0x304B, 0x304C, 0x304D, 0x304E, 0x304F, 0x3051, 0x3051, 0x3052);
|
|
105
|
-
await writer.writeElement(await eb.createUnicodeTextRun(hiragana));
|
|
106
|
-
await writer.writeElement(await eb.createTextNewLine());
|
|
107
|
-
|
|
108
|
-
// CJK Unified Ideographs
|
|
109
|
-
const cjk_uni = String.fromCharCode(
|
|
110
|
-
0x5841, 0x5842, 0x5843, 0x5844, 0x5845, 0x5846, 0x5847, 0x5848, 0x5849,
|
|
111
|
-
0x584A, 0x584B, 0x584C, 0x584D, 0x584E, 0x584F, 0x5850, 0x5851, 0x5852);
|
|
112
|
-
await writer.writeElement(await eb.createUnicodeTextRun(cjk_uni));
|
|
113
|
-
await writer.writeElement(await eb.createTextNewLine());
|
|
114
|
-
|
|
115
|
-
// Simplified Chinese
|
|
116
|
-
const chinese_simplified = String.fromCharCode(0x4e16, 0x754c, 0x60a8, 0x597d);
|
|
117
|
-
await writer.writeElement(await eb.createUnicodeTextRun(chinese_simplified));
|
|
118
|
-
await writer.writeElement(await eb.createTextNewLine());
|
|
119
|
-
|
|
120
|
-
// Finish the block of text
|
|
121
|
-
await writer.writeElement(await eb.createTextEnd());
|
|
122
|
-
|
|
123
|
-
console.log('Now using text shaping logic to place text');
|
|
124
|
-
|
|
125
|
-
// Create a font in indexed encoding mode
|
|
126
|
-
// normally this would mean that we are required to provide glyph indices
|
|
127
|
-
// directly to CreateUnicodeTextRun, but instead, we will use the GetShapedText
|
|
128
|
-
// method to take care of this detail for us.
|
|
129
|
-
const indexed_font = await PDFNet.Font.createCIDTrueTypeFont(doc, inputPath + 'NotoSans_with_hindi.ttf', true, true, PDFNet.Font.Encoding.e_Indices);
|
|
130
|
-
element = await eb.createTextBeginWithFont(indexed_font, 10);
|
|
131
|
-
await writer.writeElement(element);
|
|
132
|
-
|
|
133
|
-
const line_pos = 350.0;
|
|
134
|
-
const line_space = 20.0;
|
|
135
|
-
|
|
136
|
-
// Transform unicode text into an abstract collection of glyph indices and positioning info
|
|
137
|
-
let shaped_text = await indexed_font.getShapedText('Shaped Hindi Text:');
|
|
138
|
-
|
|
139
|
-
// transform the shaped text info into a PDF element and write it to the page
|
|
140
|
-
element = await eb.createShapedTextRun(shaped_text);
|
|
141
|
-
await element.setTextMatrixEntries(1.5, 0, 0, 1.5, 50, line_pos);
|
|
142
|
-
await writer.writeElement(element);
|
|
143
|
-
|
|
144
|
-
// read in unicode text lines from a file
|
|
145
|
-
const hindi_text = fs.readFileSync(inputPath + 'hindi_sample_utf16le.txt', 'utf16le').toString().split(/\n/);
|
|
146
|
-
|
|
147
|
-
console.log('Read in ' + hindi_text.length + ' lines of Unicode text from file');
|
|
148
|
-
for (let i = 0; i < hindi_text.length; ++i) {
|
|
149
|
-
shaped_text = await indexed_font.getShapedText(hindi_text[i]);
|
|
150
|
-
element = await eb.createShapedTextRun(shaped_text);
|
|
151
|
-
await element.setTextMatrixEntries(1.5, 0, 0, 1.5, 50, line_pos - line_space * (i + 1));
|
|
152
|
-
await writer.writeElement(element);
|
|
153
|
-
console.log('Wrote shaped line to page');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Finish the shaped block of text
|
|
157
|
-
await writer.writeElement(await eb.createTextEnd());
|
|
158
|
-
|
|
159
|
-
await writer.end(); // save changes to the current page
|
|
160
|
-
await doc.pagePushBack(page);
|
|
161
|
-
|
|
162
|
-
await doc.save(outputPath + 'unicodewrite.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused | PDFNet.SDFDoc.SaveOptions.e_hex_strings);
|
|
163
|
-
|
|
164
|
-
console.log('Done. Result saved in unicodewrite.pdf...');
|
|
165
|
-
} catch (err) {
|
|
166
|
-
console.log(err);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
170
|
-
};
|
|
171
|
-
exports.runUnicodeWriteTest();
|
|
172
|
-
})(exports);
|
|
173
|
-
// eslint-disable-next-line spaced-comment
|
|
1
|
+
//---------------------------------------------------------------------------------------
|
|
2
|
+
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
|
|
3
|
+
// Consult legal.txt regarding legal and license information.
|
|
4
|
+
//---------------------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
const fs = require('fs')
|
|
7
|
+
const process = require('process');
|
|
8
|
+
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
9
|
+
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
10
|
+
|
|
11
|
+
((exports) => {
|
|
12
|
+
|
|
13
|
+
exports.runUnicodeWriteTest = () => {
|
|
14
|
+
|
|
15
|
+
const main = async () => {
|
|
16
|
+
try {
|
|
17
|
+
// Relative path to the folder containing test files.
|
|
18
|
+
const inputPath = '../TestFiles/';
|
|
19
|
+
const outputPath = '../TestFiles/Output/';
|
|
20
|
+
|
|
21
|
+
const doc = await PDFNet.PDFDoc.create();
|
|
22
|
+
doc.initSecurityHandler();
|
|
23
|
+
|
|
24
|
+
const eb = await PDFNet.ElementBuilder.create(); // ElementBuilder, used to build new element Objects
|
|
25
|
+
const writer = await PDFNet.ElementWriter.create(); // ElementWriter, used to write elements to the page
|
|
26
|
+
|
|
27
|
+
// Start a new page ------------------------------------
|
|
28
|
+
let page = await doc.pageCreate(new PDFNet.Rect(0, 0, 612, 794));
|
|
29
|
+
|
|
30
|
+
await writer.beginOnPage(page);
|
|
31
|
+
|
|
32
|
+
let font_program = inputPath + 'ARIALUNI.TTF';
|
|
33
|
+
|
|
34
|
+
if (!fs.existsSync(font_program)) {
|
|
35
|
+
font_program = 'C:/Windows/Fonts/ARIALUNI.TTF';
|
|
36
|
+
if (process.platform !== 'win32' || !fs.existsSync(font_program)) {
|
|
37
|
+
font_program = '';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let fnt;
|
|
42
|
+
if (font_program.length) {
|
|
43
|
+
console.log('Note: using ' + font_program + ' for unshaped unicode text');
|
|
44
|
+
// if we can find a specific wide-coverage font file, then use that directly
|
|
45
|
+
fnt = await PDFNet.Font.createCIDTrueTypeFont(doc, font_program, true, true);
|
|
46
|
+
} else {
|
|
47
|
+
console.log('Note: using system font substitution for unshaped unicode text');
|
|
48
|
+
// if we can't find a specific file, then use system font subsitution
|
|
49
|
+
// as a fallback, using 'Helvetica' as a hint
|
|
50
|
+
fnt = await PDFNet.Font.createFromName(doc, 'Helvetica', '');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let element = await eb.createTextBeginWithFont(fnt, 1);
|
|
54
|
+
await element.setTextMatrixEntries(10, 0, 0, 10, 50, 600);
|
|
55
|
+
await (await element.getGState()).setLeading(2); // Set the spacing between lines
|
|
56
|
+
await writer.writeElement(element);
|
|
57
|
+
|
|
58
|
+
// Hello World!
|
|
59
|
+
const hello = 'Hello World!';
|
|
60
|
+
await writer.writeElement(await eb.createUnicodeTextRun(hello));
|
|
61
|
+
await writer.writeElement(await eb.createTextNewLine());
|
|
62
|
+
|
|
63
|
+
// Latin
|
|
64
|
+
const latin = 'aAbBcCdD' + String.fromCharCode(0x45, 0x0046, 0x00C0, 0x00C1, 0x00C2, 0x0143, 0x0144, 0x0145, 0x0152) + '12';
|
|
65
|
+
await writer.writeElement(await eb.createUnicodeTextRun(latin));
|
|
66
|
+
await writer.writeElement(await eb.createTextNewLine());
|
|
67
|
+
|
|
68
|
+
// Greek
|
|
69
|
+
const greek = String.fromCharCode(0x039E, 0x039F, 0x03A0, 0x03A1, 0x03A3, 0x03A6, 0x03A8, 0x03A9);
|
|
70
|
+
await writer.writeElement(await eb.createUnicodeTextRun(greek));
|
|
71
|
+
await writer.writeElement(await eb.createTextNewLine());
|
|
72
|
+
|
|
73
|
+
// Cyrillic
|
|
74
|
+
const cyrillic = String.fromCharCode(
|
|
75
|
+
0x0409, 0x040A, 0x040B, 0x040C, 0x040E, 0x040F, 0x0410, 0x0411,
|
|
76
|
+
0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419);
|
|
77
|
+
await writer.writeElement(await eb.createUnicodeTextRun(cyrillic));
|
|
78
|
+
await writer.writeElement(await eb.createTextNewLine());
|
|
79
|
+
|
|
80
|
+
// Hebrew
|
|
81
|
+
const hebrew = String.fromCharCode(
|
|
82
|
+
0x05D0, 0x05D1, 0x05D3, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, 0x05D8,
|
|
83
|
+
0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF, 0x05E0, 0x05E1);
|
|
84
|
+
await writer.writeElement(await eb.createUnicodeTextRun(hebrew));
|
|
85
|
+
await writer.writeElement(await eb.createTextNewLine());
|
|
86
|
+
|
|
87
|
+
// Arabic
|
|
88
|
+
const arabic = String.fromCharCode(
|
|
89
|
+
0x0624, 0x0625, 0x0626, 0x0627, 0x0628, 0x0629, 0x062A, 0x062B, 0x062C,
|
|
90
|
+
0x062D, 0x062E, 0x062F, 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635);
|
|
91
|
+
await writer.writeElement(await eb.createUnicodeTextRun(arabic));
|
|
92
|
+
await writer.writeElement(await eb.createTextNewLine());
|
|
93
|
+
|
|
94
|
+
// Thai
|
|
95
|
+
const thai = String.fromCharCode(
|
|
96
|
+
0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07, 0x0E08, 0x0E09,
|
|
97
|
+
0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F, 0x0E10, 0x0E11, 0x0E12);
|
|
98
|
+
await writer.writeElement(await eb.createUnicodeTextRun(thai));
|
|
99
|
+
await writer.writeElement(await eb.createTextNewLine());
|
|
100
|
+
|
|
101
|
+
// Hiragana - Japanese
|
|
102
|
+
const hiragana = String.fromCharCode(
|
|
103
|
+
0x3041, 0x3042, 0x3043, 0x3044, 0x3045, 0x3046, 0x3047, 0x3048, 0x3049,
|
|
104
|
+
0x304A, 0x304B, 0x304C, 0x304D, 0x304E, 0x304F, 0x3051, 0x3051, 0x3052);
|
|
105
|
+
await writer.writeElement(await eb.createUnicodeTextRun(hiragana));
|
|
106
|
+
await writer.writeElement(await eb.createTextNewLine());
|
|
107
|
+
|
|
108
|
+
// CJK Unified Ideographs
|
|
109
|
+
const cjk_uni = String.fromCharCode(
|
|
110
|
+
0x5841, 0x5842, 0x5843, 0x5844, 0x5845, 0x5846, 0x5847, 0x5848, 0x5849,
|
|
111
|
+
0x584A, 0x584B, 0x584C, 0x584D, 0x584E, 0x584F, 0x5850, 0x5851, 0x5852);
|
|
112
|
+
await writer.writeElement(await eb.createUnicodeTextRun(cjk_uni));
|
|
113
|
+
await writer.writeElement(await eb.createTextNewLine());
|
|
114
|
+
|
|
115
|
+
// Simplified Chinese
|
|
116
|
+
const chinese_simplified = String.fromCharCode(0x4e16, 0x754c, 0x60a8, 0x597d);
|
|
117
|
+
await writer.writeElement(await eb.createUnicodeTextRun(chinese_simplified));
|
|
118
|
+
await writer.writeElement(await eb.createTextNewLine());
|
|
119
|
+
|
|
120
|
+
// Finish the block of text
|
|
121
|
+
await writer.writeElement(await eb.createTextEnd());
|
|
122
|
+
|
|
123
|
+
console.log('Now using text shaping logic to place text');
|
|
124
|
+
|
|
125
|
+
// Create a font in indexed encoding mode
|
|
126
|
+
// normally this would mean that we are required to provide glyph indices
|
|
127
|
+
// directly to CreateUnicodeTextRun, but instead, we will use the GetShapedText
|
|
128
|
+
// method to take care of this detail for us.
|
|
129
|
+
const indexed_font = await PDFNet.Font.createCIDTrueTypeFont(doc, inputPath + 'NotoSans_with_hindi.ttf', true, true, PDFNet.Font.Encoding.e_Indices);
|
|
130
|
+
element = await eb.createTextBeginWithFont(indexed_font, 10);
|
|
131
|
+
await writer.writeElement(element);
|
|
132
|
+
|
|
133
|
+
const line_pos = 350.0;
|
|
134
|
+
const line_space = 20.0;
|
|
135
|
+
|
|
136
|
+
// Transform unicode text into an abstract collection of glyph indices and positioning info
|
|
137
|
+
let shaped_text = await indexed_font.getShapedText('Shaped Hindi Text:');
|
|
138
|
+
|
|
139
|
+
// transform the shaped text info into a PDF element and write it to the page
|
|
140
|
+
element = await eb.createShapedTextRun(shaped_text);
|
|
141
|
+
await element.setTextMatrixEntries(1.5, 0, 0, 1.5, 50, line_pos);
|
|
142
|
+
await writer.writeElement(element);
|
|
143
|
+
|
|
144
|
+
// read in unicode text lines from a file
|
|
145
|
+
const hindi_text = fs.readFileSync(inputPath + 'hindi_sample_utf16le.txt', 'utf16le').toString().split(/\n/);
|
|
146
|
+
|
|
147
|
+
console.log('Read in ' + hindi_text.length + ' lines of Unicode text from file');
|
|
148
|
+
for (let i = 0; i < hindi_text.length; ++i) {
|
|
149
|
+
shaped_text = await indexed_font.getShapedText(hindi_text[i]);
|
|
150
|
+
element = await eb.createShapedTextRun(shaped_text);
|
|
151
|
+
await element.setTextMatrixEntries(1.5, 0, 0, 1.5, 50, line_pos - line_space * (i + 1));
|
|
152
|
+
await writer.writeElement(element);
|
|
153
|
+
console.log('Wrote shaped line to page');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Finish the shaped block of text
|
|
157
|
+
await writer.writeElement(await eb.createTextEnd());
|
|
158
|
+
|
|
159
|
+
await writer.end(); // save changes to the current page
|
|
160
|
+
await doc.pagePushBack(page);
|
|
161
|
+
|
|
162
|
+
await doc.save(outputPath + 'unicodewrite.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused | PDFNet.SDFDoc.SaveOptions.e_hex_strings);
|
|
163
|
+
|
|
164
|
+
console.log('Done. Result saved in unicodewrite.pdf...');
|
|
165
|
+
} catch (err) {
|
|
166
|
+
console.log(err);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
170
|
+
};
|
|
171
|
+
exports.runUnicodeWriteTest();
|
|
172
|
+
})(exports);
|
|
173
|
+
// eslint-disable-next-line spaced-comment
|
|
174
174
|
//# sourceURL=UnicodeWriteTest.js
|
package/samples/runall.bat
CHANGED
package/samples/runall.sh
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
|
|
3
|
-
for SAMPLE in *
|
|
4
|
-
do
|
|
5
|
-
if [ -d $SAMPLE ] && [ -e $SAMPLE/RunTest.sh ]
|
|
6
|
-
then
|
|
7
|
-
cd $SAMPLE
|
|
8
|
-
echo "$SAMPLE running"
|
|
9
|
-
sh RunTest.sh
|
|
10
|
-
cd
|
|
11
|
-
echo "$SAMPLE finished. Press enter to continue..."
|
|
12
|
-
read -p "$*" a
|
|
13
|
-
fi
|
|
14
|
-
done
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
for SAMPLE in *
|
|
4
|
+
do
|
|
5
|
+
if [ -d $SAMPLE/NODEJS ] && [ -e $SAMPLE/NODEJS/RunTest.sh ]
|
|
6
|
+
then
|
|
7
|
+
cd $SAMPLE/NODEJS
|
|
8
|
+
echo "$SAMPLE running"
|
|
9
|
+
sh RunTest.sh
|
|
10
|
+
cd ../..
|
|
11
|
+
echo "$SAMPLE finished. Press enter to continue..."
|
|
12
|
+
read -p "$*" a
|
|
13
|
+
fi
|
|
14
|
+
done
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
|
|
3
|
-
// Consult legal.txt regarding legal and license information.
|
|
4
|
-
//---------------------------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
//---------------------------------------------------------------------------------------
|
|
7
|
-
// The following sample illustrates how to use the PDF::Convert utility class to convert
|
|
8
|
-
// documents and files to Word.
|
|
9
|
-
//
|
|
10
|
-
// The Word module is an optional PDFNet Add-on that can be used to convert PDF
|
|
11
|
-
// documents into Word documents.
|
|
12
|
-
//
|
|
13
|
-
// The PDFTron SDK Word module can be downloaded from http://www.pdftron.com/
|
|
14
|
-
//
|
|
15
|
-
// Please contact us if you have any questions.
|
|
16
|
-
//---------------------------------------------------------------------------------------
|
|
17
|
-
|
|
18
|
-
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
19
|
-
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
20
|
-
|
|
21
|
-
((exports) => {
|
|
22
|
-
'use strict';
|
|
23
|
-
|
|
24
|
-
exports.runPDF2WordTest = () => {
|
|
25
|
-
|
|
26
|
-
const main = async () => {
|
|
27
|
-
|
|
28
|
-
await PDFNet.addResourceSearchPath('../../lib/');
|
|
29
|
-
|
|
30
|
-
if (!await PDFNet.PDF2WordModule.isModuleAvailable())
|
|
31
|
-
{
|
|
32
|
-
console.log('\nUnable to run the sample: PDFTron SDK Word module not available.');
|
|
33
|
-
console.log('---------------------------------------------------------------');
|
|
34
|
-
console.log('The Word module is an optional add-on, available for download');
|
|
35
|
-
console.log('at http://www.pdftron.com/. If you have already downloaded this');
|
|
36
|
-
console.log('module, ensure that the SDK is able to find the required files');
|
|
37
|
-
console.log('using the PDFNet::AddResourceSearchPath() function.\n');
|
|
38
|
-
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const inputPath = '../TestFiles/';
|
|
43
|
-
const outputPath = '../TestFiles/Output/';
|
|
44
|
-
try {
|
|
45
|
-
// Convert PDF document to Word
|
|
46
|
-
console.log('Converting PDF to Word');
|
|
47
|
-
|
|
48
|
-
const outputFile = outputPath + 'paragraphs_and_tables.docx';
|
|
49
|
-
|
|
50
|
-
await PDFNet.Convert.fileToWord(inputPath + 'paragraphs_and_tables.pdf', outputFile);
|
|
51
|
-
|
|
52
|
-
console.log('Result saved in ' + outputFile);
|
|
53
|
-
} catch (err) {
|
|
54
|
-
console.log(err);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
// Convert PDF document to Word with options
|
|
59
|
-
console.log('Converting PDF to Word with options');
|
|
60
|
-
|
|
61
|
-
const outputFile = outputPath + 'paragraphs_and_tables_first_page.docx';
|
|
62
|
-
|
|
63
|
-
const wordOutputOptions = new PDFNet.Convert.WordOutputOptions();
|
|
64
|
-
|
|
65
|
-
// Convert only the first page
|
|
66
|
-
wordOutputOptions.setPages(1, 1);
|
|
67
|
-
|
|
68
|
-
await PDFNet.Convert.fileToWord(inputPath + 'paragraphs_and_tables.pdf', outputFile, wordOutputOptions);
|
|
69
|
-
|
|
70
|
-
console.log('Result saved in ' + outputFile);
|
|
71
|
-
} catch (err) {
|
|
72
|
-
console.log(err);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
console.log('Done.');
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
|
|
79
|
-
console.log('Error: ' + JSON.stringify(error));
|
|
80
|
-
}).then(function () { return PDFNet.shutdown(); });
|
|
81
|
-
};
|
|
82
|
-
exports.runPDF2WordTest();
|
|
83
|
-
})(exports);
|
|
84
|
-
// eslint-disable-next-line spaced-comment
|
|
85
|
-
//# sourceURL=PDF2WordTest.js
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|