@pdftron/pdfnet-node-samples 9.2.0 → 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.
Files changed (140) hide show
  1. package/package.json +2 -2
  2. package/samples/AddImageTest/AddImageTest.js +115 -115
  3. package/samples/AdvancedImagingTest/AdvancedImagingTest.js +78 -64
  4. package/samples/AnnotationTest/AnnotationTest.js +641 -641
  5. package/samples/BookmarkTest/BookmarkTest.js +219 -219
  6. package/samples/CAD2PDFTest/CAD2PDFTest.js +4 -4
  7. package/samples/ContentReplacerTest/ContentReplacerTest.js +75 -75
  8. package/samples/ConvertTest/ConvertTest.js +5 -5
  9. package/samples/DigitalSignaturesTest/DigitalSignaturesTest.js +1 -1
  10. package/samples/ElementBuilderTest/ElementBuilderTest.js +513 -513
  11. package/samples/ElementEditTest/ElementEditTest.js +110 -110
  12. package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +305 -305
  13. package/samples/ElementReaderTest/ElementReaderTest.js +77 -77
  14. package/samples/EncTest/EncTest.js +175 -175
  15. package/samples/FDFTest/FDFTest.js +1 -1
  16. package/samples/HTML2PDFTest/HTML2PDFTest.js +53 -43
  17. package/samples/HighlightsTest/HighlightsTest.js +97 -0
  18. package/samples/ImageExtractTest/ImageExtractTest.js +1 -1
  19. package/samples/ImpositionTest/ImpositionTest.js +1 -1
  20. package/samples/InteractiveFormsTest/InteractiveFormsTest.js +1 -1
  21. package/samples/JBIG2Test/JBIG2Test.js +1 -1
  22. package/samples/LicenseKey/LicenseKey.js +11 -11
  23. package/samples/LogicalStructureTest/LogicalStructureTest.js +250 -250
  24. package/samples/OCRTest/OCRTest.js +19 -34
  25. package/samples/OfficeTemplateTest/OfficeTemplateTest.js +77 -0
  26. package/samples/OfficeToPDFTest/OfficeToPDFTest.js +1 -1
  27. package/samples/OptimizerTest/OptimizerTest.js +1 -1
  28. package/samples/PDF2HtmlTest/PDF2HtmlTest.js +123 -123
  29. package/samples/PDF2OfficeTest/PDF2OfficeTest.js +158 -158
  30. package/samples/PDFATest/PDFATest.js +85 -85
  31. package/samples/PDFDocMemoryTest/PDFDocMemoryTest.js +1 -1
  32. package/samples/PDFDrawTest/PDFDrawTest.js +305 -305
  33. package/samples/PDFLayersTest/PDFLayersTest.js +294 -294
  34. package/samples/PDFPackageTest/PDFPackageTest.js +1 -1
  35. package/samples/PDFPageTest/PDFPageTest.js +189 -189
  36. package/samples/PDFRedactTest/PDFRedactTest.js +74 -74
  37. package/samples/PageLabelsTest/PageLabelsTest.js +1 -1
  38. package/samples/PatternTest/PatternTest.js +1 -1
  39. package/samples/RectTest/RectTest.js +40 -40
  40. package/samples/SDFTest/SDFTest.js +88 -88
  41. package/samples/StamperTest/StamperTest.js +255 -255
  42. package/samples/TestFiles/Misc-Fixed.pfa +1166 -1166
  43. package/samples/TestFiles/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +34 -34
  44. package/samples/TestFiles/form1_annots.xfdf +33 -33
  45. package/samples/TestFiles/form1_data.xfdf +139 -139
  46. package/samples/TestFiles/my_stream.txt +2310 -2310
  47. package/samples/TextExtractTest/TextExtractTest.js +286 -286
  48. package/samples/TextSearchTest/TextSearchTest.js +121 -121
  49. package/samples/U3DTest/U3DTest.js +1 -1
  50. package/samples/UndoRedoTest/UndoRedoTest.js +101 -101
  51. package/samples/UnicodeWriteTest/UnicodeWriteTest.js +173 -173
  52. package/samples/WebViewerConvertTest/WebViewerConvertTest.js +1 -1
  53. package/samples/runall.bat +6 -7
  54. package/samples/runall.sh +15 -14
  55. package/samples/AddImageTest/RunTest.bat +0 -2
  56. package/samples/AddImageTest/RunTest.sh +0 -2
  57. package/samples/AdvancedImagingTest/RunTest.bat +0 -2
  58. package/samples/AdvancedImagingTest/RunTest.sh +0 -2
  59. package/samples/AnnotationTest/RunTest.bat +0 -2
  60. package/samples/AnnotationTest/RunTest.sh +0 -2
  61. package/samples/BookmarkTest/RunTest.bat +0 -2
  62. package/samples/BookmarkTest/RunTest.sh +0 -2
  63. package/samples/CAD2PDFTest/RunTest.bat +0 -2
  64. package/samples/CAD2PDFTest/RunTest.sh +0 -2
  65. package/samples/ContentReplacerTest/RunTest.bat +0 -2
  66. package/samples/ContentReplacerTest/RunTest.sh +0 -2
  67. package/samples/ConvertTest/RunTest.bat +0 -2
  68. package/samples/ConvertTest/RunTest.sh +0 -2
  69. package/samples/DigitalSignaturesTest/RunTest.bat +0 -2
  70. package/samples/DigitalSignaturesTest/RunTest.sh +0 -2
  71. package/samples/ElementBuilderTest/RunTest.bat +0 -2
  72. package/samples/ElementBuilderTest/RunTest.sh +0 -2
  73. package/samples/ElementEditTest/RunTest.bat +0 -2
  74. package/samples/ElementEditTest/RunTest.sh +0 -2
  75. package/samples/ElementReaderAdvTest/RunTest.bat +0 -2
  76. package/samples/ElementReaderAdvTest/RunTest.sh +0 -2
  77. package/samples/ElementReaderTest/RunTest.bat +0 -2
  78. package/samples/ElementReaderTest/RunTest.sh +0 -2
  79. package/samples/EncTest/RunTest.bat +0 -2
  80. package/samples/EncTest/RunTest.sh +0 -2
  81. package/samples/FDFTest/RunTest.bat +0 -2
  82. package/samples/FDFTest/RunTest.sh +0 -2
  83. package/samples/HTML2PDFTest/RunTest.bat +0 -2
  84. package/samples/HTML2PDFTest/RunTest.sh +0 -2
  85. package/samples/ImageExtractTest/RunTest.bat +0 -2
  86. package/samples/ImageExtractTest/RunTest.sh +0 -2
  87. package/samples/ImpositionTest/RunTest.bat +0 -2
  88. package/samples/ImpositionTest/RunTest.sh +0 -2
  89. package/samples/InteractiveFormsTest/RunTest.bat +0 -2
  90. package/samples/InteractiveFormsTest/RunTest.sh +0 -2
  91. package/samples/JBIG2Test/RunTest.bat +0 -2
  92. package/samples/JBIG2Test/RunTest.sh +0 -2
  93. package/samples/LogicalStructureTest/RunTest.bat +0 -2
  94. package/samples/LogicalStructureTest/RunTest.sh +0 -2
  95. package/samples/OCRTest/RunTest.bat +0 -2
  96. package/samples/OCRTest/RunTest.sh +0 -2
  97. package/samples/OfficeToPDFTest/RunTest.bat +0 -2
  98. package/samples/OfficeToPDFTest/RunTest.sh +0 -2
  99. package/samples/OptimizerTest/RunTest.bat +0 -2
  100. package/samples/OptimizerTest/RunTest.sh +0 -2
  101. package/samples/PDF2HtmlTest/RunTest.bat +0 -2
  102. package/samples/PDF2HtmlTest/RunTest.sh +0 -2
  103. package/samples/PDF2OfficeTest/RunTest.bat +0 -2
  104. package/samples/PDF2OfficeTest/RunTest.sh +0 -2
  105. package/samples/PDFATest/RunTest.bat +0 -2
  106. package/samples/PDFATest/RunTest.sh +0 -2
  107. package/samples/PDFDocMemoryTest/RunTest.bat +0 -2
  108. package/samples/PDFDocMemoryTest/RunTest.sh +0 -2
  109. package/samples/PDFDrawTest/RunTest.bat +0 -2
  110. package/samples/PDFDrawTest/RunTest.sh +0 -2
  111. package/samples/PDFLayersTest/RunTest.bat +0 -2
  112. package/samples/PDFLayersTest/RunTest.sh +0 -2
  113. package/samples/PDFPackageTest/RunTest.bat +0 -2
  114. package/samples/PDFPackageTest/RunTest.sh +0 -2
  115. package/samples/PDFPageTest/RunTest.bat +0 -2
  116. package/samples/PDFPageTest/RunTest.sh +0 -2
  117. package/samples/PDFRedactTest/RunTest.bat +0 -2
  118. package/samples/PDFRedactTest/RunTest.sh +0 -2
  119. package/samples/PageLabelsTest/RunTest.bat +0 -2
  120. package/samples/PageLabelsTest/RunTest.sh +0 -2
  121. package/samples/PatternTest/RunTest.bat +0 -2
  122. package/samples/PatternTest/RunTest.sh +0 -2
  123. package/samples/RectTest/RunTest.bat +0 -2
  124. package/samples/RectTest/RunTest.sh +0 -2
  125. package/samples/SDFTest/RunTest.bat +0 -2
  126. package/samples/SDFTest/RunTest.sh +0 -2
  127. package/samples/StamperTest/RunTest.bat +0 -2
  128. package/samples/StamperTest/RunTest.sh +0 -2
  129. package/samples/TextExtractTest/RunTest.bat +0 -2
  130. package/samples/TextExtractTest/RunTest.sh +0 -2
  131. package/samples/TextSearchTest/RunTest.bat +0 -2
  132. package/samples/TextSearchTest/RunTest.sh +0 -2
  133. package/samples/U3DTest/RunTest.bat +0 -2
  134. package/samples/U3DTest/RunTest.sh +0 -2
  135. package/samples/UndoRedoTest/RunTest.bat +0 -2
  136. package/samples/UndoRedoTest/RunTest.sh +0 -2
  137. package/samples/UnicodeWriteTest/RunTest.bat +0 -2
  138. package/samples/UnicodeWriteTest/RunTest.sh +0 -2
  139. package/samples/WebViewerConvertTest/RunTest.bat +0 -2
  140. package/samples/WebViewerConvertTest/RunTest.sh +0 -2
@@ -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-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-2021 by PDFTron Systems Inc. All Rights Reserved.
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
 
@@ -1,13 +1,12 @@
1
1
  @echo off
2
- for /D %%s in (*) do (
3
- if exist %%s\NODEJS\%%~nxs.js (
4
- cd %%s\NODEJS
5
- echo %%s starting...
2
+ for /D %%s in (*Test) do (
3
+ if exist %%s\%%~nxs.js (
4
+ cd %%s
5
+ echo %%s running...
6
6
  call node %%~nxs.js
7
- cd ..\..
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
- #!/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
+ #!/bin/sh
2
+
3
+ for SAMPLE in *Test
4
+ do
5
+ if [ -d $SAMPLE ] && [ -e $SAMPLE/$SAMPLE.js ]
6
+ then
7
+ cd $SAMPLE
8
+ echo "$SAMPLE running"
9
+ node $SAMPLE.js
10
+ cd ..
11
+ echo "$SAMPLE finished. Press enter to continue..."
12
+ read -p "$*" a
13
+ fi
14
+ done
15
+ echo "All tests finished."
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node AddImageTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node AddImageTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node AdvancedImagingTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node AdvancedImagingTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node AnnotationTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node AnnotationTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node BookmarkTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node BookmarkTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node CAD2PDFTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node CAD2PDFTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node ContentReplacerTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node ContentReplacerTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node ConvertTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node ConvertTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node DigitalSignaturesTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node DigitalSignaturesTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node ElementBuilderTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node ElementBuilderTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node ElementEditTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node ElementEditTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node ElementReaderAdvTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node ElementReaderAdvTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node ElementReaderTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node ElementReaderTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node EncTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node EncTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node FDFTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node FDFTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node HTML2PDFTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node HTML2PDFTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node ImageExtractTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node ImageExtractTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node ImpositionTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node ImpositionTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node InteractiveFormsTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node InteractiveFormsTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node JBIG2Test.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node JBIG2Test.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node LogicalStructureTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node LogicalStructureTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node OCRTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node OCRTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node OfficeToPDFTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node OfficeToPDFTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node OptimizerTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node OptimizerTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node PDF2HtmlTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node PDF2HtmlTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node PDF2OfficeTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node PDF2OfficeTest.js
@@ -1,2 +0,0 @@
1
- @echo off
2
- call node PDFATest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node PDFATest.js