@pdftron/pdfnet-node-samples 9.2.0-1 → 9.3.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 +2 -2
- package/samples/AddImageTest/AddImageTest.js +115 -115
- package/samples/AdvancedImagingTest/AdvancedImagingTest.js +78 -64
- package/samples/AnnotationTest/AnnotationTest.js +641 -641
- package/samples/BookmarkTest/BookmarkTest.js +219 -219
- package/samples/CAD2PDFTest/CAD2PDFTest.js +4 -4
- package/samples/ContentReplacerTest/ContentReplacerTest.js +75 -75
- package/samples/ConvertTest/ConvertTest.js +5 -5
- package/samples/DigitalSignaturesTest/DigitalSignaturesTest.js +1 -1
- 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/FDFTest/FDFTest.js +1 -1
- package/samples/HTML2PDFTest/HTML2PDFTest.js +53 -43
- package/samples/HighlightsTest/HighlightsTest.js +97 -0
- package/samples/ImageExtractTest/ImageExtractTest.js +1 -1
- package/samples/ImpositionTest/ImpositionTest.js +1 -1
- package/samples/InteractiveFormsTest/InteractiveFormsTest.js +1 -1
- package/samples/JBIG2Test/JBIG2Test.js +1 -1
- package/samples/LicenseKey/LicenseKey.js +11 -11
- package/samples/LogicalStructureTest/LogicalStructureTest.js +250 -250
- package/samples/OCRTest/OCRTest.js +19 -34
- package/samples/OfficeTemplateTest/OfficeTemplateTest.js +77 -0
- package/samples/OfficeToPDFTest/OfficeToPDFTest.js +1 -1
- package/samples/OptimizerTest/OptimizerTest.js +1 -1
- package/samples/PDF2HtmlTest/PDF2HtmlTest.js +123 -123
- package/samples/PDF2OfficeTest/PDF2OfficeTest.js +158 -158
- package/samples/PDFATest/PDFATest.js +85 -85
- package/samples/PDFDocMemoryTest/PDFDocMemoryTest.js +1 -1
- package/samples/PDFDrawTest/PDFDrawTest.js +305 -305
- package/samples/PDFLayersTest/PDFLayersTest.js +294 -294
- package/samples/PDFPackageTest/PDFPackageTest.js +1 -1
- package/samples/PDFPageTest/PDFPageTest.js +189 -189
- package/samples/PDFRedactTest/PDFRedactTest.js +74 -74
- package/samples/PageLabelsTest/PageLabelsTest.js +1 -1
- package/samples/PatternTest/PatternTest.js +1 -1
- 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/U3DTest/U3DTest.js +1 -1
- package/samples/UndoRedoTest/UndoRedoTest.js +101 -101
- package/samples/UnicodeWriteTest/UnicodeWriteTest.js +173 -173
- package/samples/WebViewerConvertTest/WebViewerConvertTest.js +1 -1
- package/samples/runall.bat +3 -4
- package/samples/runall.sh +4 -3
- package/samples/AddImageTest/RunTest.bat +0 -2
- package/samples/AddImageTest/RunTest.sh +0 -2
- package/samples/AdvancedImagingTest/RunTest.bat +0 -2
- package/samples/AdvancedImagingTest/RunTest.sh +0 -2
- package/samples/AnnotationTest/RunTest.bat +0 -2
- package/samples/AnnotationTest/RunTest.sh +0 -2
- package/samples/BookmarkTest/RunTest.bat +0 -2
- package/samples/BookmarkTest/RunTest.sh +0 -2
- package/samples/CAD2PDFTest/RunTest.bat +0 -2
- package/samples/CAD2PDFTest/RunTest.sh +0 -2
- package/samples/ContentReplacerTest/RunTest.bat +0 -2
- package/samples/ContentReplacerTest/RunTest.sh +0 -2
- package/samples/ConvertTest/RunTest.bat +0 -2
- package/samples/ConvertTest/RunTest.sh +0 -2
- package/samples/DigitalSignaturesTest/RunTest.bat +0 -2
- package/samples/DigitalSignaturesTest/RunTest.sh +0 -2
- package/samples/ElementBuilderTest/RunTest.bat +0 -2
- package/samples/ElementBuilderTest/RunTest.sh +0 -2
- package/samples/ElementEditTest/RunTest.bat +0 -2
- package/samples/ElementEditTest/RunTest.sh +0 -2
- package/samples/ElementReaderAdvTest/RunTest.bat +0 -2
- package/samples/ElementReaderAdvTest/RunTest.sh +0 -2
- package/samples/ElementReaderTest/RunTest.bat +0 -2
- package/samples/ElementReaderTest/RunTest.sh +0 -2
- package/samples/EncTest/RunTest.bat +0 -2
- package/samples/EncTest/RunTest.sh +0 -2
- package/samples/FDFTest/RunTest.bat +0 -2
- package/samples/FDFTest/RunTest.sh +0 -2
- package/samples/HTML2PDFTest/RunTest.bat +0 -2
- package/samples/HTML2PDFTest/RunTest.sh +0 -2
- package/samples/ImageExtractTest/RunTest.bat +0 -2
- package/samples/ImageExtractTest/RunTest.sh +0 -2
- package/samples/ImpositionTest/RunTest.bat +0 -2
- package/samples/ImpositionTest/RunTest.sh +0 -2
- package/samples/InteractiveFormsTest/RunTest.bat +0 -2
- package/samples/InteractiveFormsTest/RunTest.sh +0 -2
- package/samples/JBIG2Test/RunTest.bat +0 -2
- package/samples/JBIG2Test/RunTest.sh +0 -2
- package/samples/LogicalStructureTest/RunTest.bat +0 -2
- package/samples/LogicalStructureTest/RunTest.sh +0 -2
- package/samples/OCRTest/RunTest.bat +0 -2
- package/samples/OCRTest/RunTest.sh +0 -2
- package/samples/OfficeToPDFTest/RunTest.bat +0 -2
- package/samples/OfficeToPDFTest/RunTest.sh +0 -2
- package/samples/OptimizerTest/RunTest.bat +0 -2
- package/samples/OptimizerTest/RunTest.sh +0 -2
- package/samples/PDF2HtmlTest/RunTest.bat +0 -2
- package/samples/PDF2HtmlTest/RunTest.sh +0 -2
- package/samples/PDF2OfficeTest/RunTest.bat +0 -2
- package/samples/PDF2OfficeTest/RunTest.sh +0 -2
- package/samples/PDFATest/RunTest.bat +0 -2
- package/samples/PDFATest/RunTest.sh +0 -2
- package/samples/PDFDocMemoryTest/RunTest.bat +0 -2
- package/samples/PDFDocMemoryTest/RunTest.sh +0 -2
- package/samples/PDFDrawTest/RunTest.bat +0 -2
- package/samples/PDFDrawTest/RunTest.sh +0 -2
- package/samples/PDFLayersTest/RunTest.bat +0 -2
- package/samples/PDFLayersTest/RunTest.sh +0 -2
- package/samples/PDFPackageTest/RunTest.bat +0 -2
- package/samples/PDFPackageTest/RunTest.sh +0 -2
- package/samples/PDFPageTest/RunTest.bat +0 -2
- package/samples/PDFPageTest/RunTest.sh +0 -2
- package/samples/PDFRedactTest/RunTest.bat +0 -2
- package/samples/PDFRedactTest/RunTest.sh +0 -2
- package/samples/PageLabelsTest/RunTest.bat +0 -2
- package/samples/PageLabelsTest/RunTest.sh +0 -2
- package/samples/PatternTest/RunTest.bat +0 -2
- package/samples/PatternTest/RunTest.sh +0 -2
- package/samples/RectTest/RunTest.bat +0 -2
- package/samples/RectTest/RunTest.sh +0 -2
- package/samples/SDFTest/RunTest.bat +0 -2
- package/samples/SDFTest/RunTest.sh +0 -2
- package/samples/StamperTest/RunTest.bat +0 -2
- package/samples/StamperTest/RunTest.sh +0 -2
- package/samples/TextExtractTest/RunTest.bat +0 -2
- package/samples/TextExtractTest/RunTest.sh +0 -2
- package/samples/TextSearchTest/RunTest.bat +0 -2
- package/samples/TextSearchTest/RunTest.sh +0 -2
- package/samples/U3DTest/RunTest.bat +0 -2
- package/samples/U3DTest/RunTest.sh +0 -2
- package/samples/UndoRedoTest/RunTest.bat +0 -2
- package/samples/UndoRedoTest/RunTest.sh +0 -2
- package/samples/UnicodeWriteTest/RunTest.bat +0 -2
- package/samples/UnicodeWriteTest/RunTest.sh +0 -2
- package/samples/WebViewerConvertTest/RunTest.bat +0 -2
- package/samples/WebViewerConvertTest/RunTest.sh +0 -2
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
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-2022 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
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
2
|
+
// Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
|
|
3
3
|
// Consult legal.txt regarding legal and license information.
|
|
4
4
|
//---------------------------------------------------------------------------------------
|
|
5
5
|
|
package/samples/runall.bat
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
@echo off
|
|
2
|
-
for /D %%s in (*) do (
|
|
2
|
+
for /D %%s in (*Test) do (
|
|
3
3
|
if exist %%s\%%~nxs.js (
|
|
4
4
|
cd %%s
|
|
5
|
-
echo %%s
|
|
5
|
+
echo %%s running...
|
|
6
6
|
call node %%~nxs.js
|
|
7
7
|
cd ..
|
|
8
8
|
echo %%s finished.
|
|
9
9
|
pause
|
|
10
10
|
)
|
|
11
11
|
)
|
|
12
|
-
|
|
13
|
-
echo Run all tests finished.
|
|
12
|
+
echo All tests finished.
|
package/samples/runall.sh
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
|
|
3
|
-
for SAMPLE in *
|
|
3
|
+
for SAMPLE in *Test
|
|
4
4
|
do
|
|
5
|
-
if [ -d $SAMPLE ] && [ -e $SAMPLE
|
|
5
|
+
if [ -d $SAMPLE ] && [ -e $SAMPLE/$SAMPLE.js ]
|
|
6
6
|
then
|
|
7
7
|
cd $SAMPLE
|
|
8
8
|
echo "$SAMPLE running"
|
|
9
|
-
|
|
9
|
+
node $SAMPLE.js
|
|
10
10
|
cd ..
|
|
11
11
|
echo "$SAMPLE finished. Press enter to continue..."
|
|
12
12
|
read -p "$*" a
|
|
13
13
|
fi
|
|
14
14
|
done
|
|
15
|
+
echo "All tests finished."
|