@pdftron/pdfnet-node-samples 10.9.0 → 10.10.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/{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 +622 -527
- 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 -21
- 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,101 +1,101 @@
|
|
|
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
|
-
// The following sample illustrates how to use the UndoRedo API.
|
|
8
|
-
//---------------------------------------------------------------------------------------
|
|
9
|
-
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
10
|
-
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
11
|
-
|
|
12
|
-
((exports) => {
|
|
13
|
-
|
|
14
|
-
exports.runUndoRedoTest = () => {
|
|
15
|
-
|
|
16
|
-
const main = async () => {
|
|
17
|
-
try {
|
|
18
|
-
// Relative path to the folder containing test files.
|
|
19
|
-
const inputPath = '../TestFiles/';
|
|
20
|
-
const outputPath = inputPath + 'Output/';
|
|
21
|
-
|
|
22
|
-
// Open the PDF document.
|
|
23
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
|
|
24
|
-
|
|
25
|
-
const undo_manager = await doc.getUndoManager();
|
|
26
|
-
|
|
27
|
-
// Take a snapshot to which we can undo after making changes.
|
|
28
|
-
const snap0 = await undo_manager.takeSnapshot();
|
|
29
|
-
|
|
30
|
-
const snap0_state = await snap0.currentState();
|
|
31
|
-
|
|
32
|
-
const page = await doc.pageCreate(); // Start a new page
|
|
33
|
-
|
|
34
|
-
const bld = await PDFNet.ElementBuilder.create(); // Used to build new Element objects
|
|
35
|
-
const writer = await PDFNet.ElementWriter.create(); // Used to write Elements to the page
|
|
36
|
-
writer.beginOnPage(page); // Begin writing to this page
|
|
37
|
-
|
|
38
|
-
// ----------------------------------------------------------
|
|
39
|
-
// Add JPEG image to the file
|
|
40
|
-
const img = await PDFNet.Image.createFromFile(doc, inputPath + 'peppers.jpg');
|
|
41
|
-
const element = await bld.createImageFromMatrix(img, await PDFNet.Matrix2D.create(200, 0, 0, 250, 50, 500));
|
|
42
|
-
writer.writePlacedElement(element);
|
|
43
|
-
|
|
44
|
-
await writer.end(); // Finish writing to the page
|
|
45
|
-
await doc.pagePushFront(page);
|
|
46
|
-
|
|
47
|
-
// Take a snapshot after making changes, so that we can redo later (after undoing first).
|
|
48
|
-
const snap1 = await undo_manager.takeSnapshot();
|
|
49
|
-
|
|
50
|
-
if (await (await snap1.previousState()).equals(snap0_state)) {
|
|
51
|
-
console.log('snap1 previous state equals snap0_state; previous state is correct');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const snap1_state = await snap1.currentState();
|
|
55
|
-
|
|
56
|
-
await doc.save(outputPath + 'addimage.pdf', PDFNet.SDFDoc.SaveOptions.e_incremental);
|
|
57
|
-
|
|
58
|
-
if (await undo_manager.canUndo()) {
|
|
59
|
-
const undo_snap = await undo_manager.undo();
|
|
60
|
-
|
|
61
|
-
await doc.save(outputPath + 'addimage_undone.pdf', PDFNet.SDFDoc.SaveOptions.e_incremental);
|
|
62
|
-
|
|
63
|
-
const undo_snap_state = await undo_snap.currentState();
|
|
64
|
-
|
|
65
|
-
if (await undo_snap_state.equals(snap0_state)) {
|
|
66
|
-
console.log('undo_snap_state equals snap0_state; undo was successful');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (await undo_manager.canRedo()) {
|
|
70
|
-
const redo_snap = await undo_manager.redo();
|
|
71
|
-
|
|
72
|
-
await doc.save(outputPath + 'addimage_redone.pdf', PDFNet.SDFDoc.SaveOptions.e_incremental);
|
|
73
|
-
|
|
74
|
-
if (await (await redo_snap.previousState()).equals(undo_snap_state)) {
|
|
75
|
-
console.log('redo_snap previous state equals undo_snap_state; previous state is correct');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const redo_snap_state = await redo_snap.currentState();
|
|
79
|
-
|
|
80
|
-
if (await redo_snap_state.equals(snap1_state)) {
|
|
81
|
-
console.log('Snap1 and redo_snap are equal; redo was successful');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
console.log('Problem encountered - cannot redo.');
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
console.log('Problem encountered - cannot undo.');
|
|
90
|
-
}
|
|
91
|
-
} catch (err) {
|
|
92
|
-
console.log(err.stack);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
97
|
-
};
|
|
98
|
-
exports.runUndoRedoTest();
|
|
99
|
-
})(exports);
|
|
100
|
-
// eslint-disable-next-line spaced-comment
|
|
101
|
-
//# sourceURL=UndoRedoTest.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
|
+
// The following sample illustrates how to use the UndoRedo API.
|
|
8
|
+
//---------------------------------------------------------------------------------------
|
|
9
|
+
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
10
|
+
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
11
|
+
|
|
12
|
+
((exports) => {
|
|
13
|
+
|
|
14
|
+
exports.runUndoRedoTest = () => {
|
|
15
|
+
|
|
16
|
+
const main = async () => {
|
|
17
|
+
try {
|
|
18
|
+
// Relative path to the folder containing test files.
|
|
19
|
+
const inputPath = '../TestFiles/';
|
|
20
|
+
const outputPath = inputPath + 'Output/';
|
|
21
|
+
|
|
22
|
+
// Open the PDF document.
|
|
23
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
|
|
24
|
+
|
|
25
|
+
const undo_manager = await doc.getUndoManager();
|
|
26
|
+
|
|
27
|
+
// Take a snapshot to which we can undo after making changes.
|
|
28
|
+
const snap0 = await undo_manager.takeSnapshot();
|
|
29
|
+
|
|
30
|
+
const snap0_state = await snap0.currentState();
|
|
31
|
+
|
|
32
|
+
const page = await doc.pageCreate(); // Start a new page
|
|
33
|
+
|
|
34
|
+
const bld = await PDFNet.ElementBuilder.create(); // Used to build new Element objects
|
|
35
|
+
const writer = await PDFNet.ElementWriter.create(); // Used to write Elements to the page
|
|
36
|
+
writer.beginOnPage(page); // Begin writing to this page
|
|
37
|
+
|
|
38
|
+
// ----------------------------------------------------------
|
|
39
|
+
// Add JPEG image to the file
|
|
40
|
+
const img = await PDFNet.Image.createFromFile(doc, inputPath + 'peppers.jpg');
|
|
41
|
+
const element = await bld.createImageFromMatrix(img, await PDFNet.Matrix2D.create(200, 0, 0, 250, 50, 500));
|
|
42
|
+
writer.writePlacedElement(element);
|
|
43
|
+
|
|
44
|
+
await writer.end(); // Finish writing to the page
|
|
45
|
+
await doc.pagePushFront(page);
|
|
46
|
+
|
|
47
|
+
// Take a snapshot after making changes, so that we can redo later (after undoing first).
|
|
48
|
+
const snap1 = await undo_manager.takeSnapshot();
|
|
49
|
+
|
|
50
|
+
if (await (await snap1.previousState()).equals(snap0_state)) {
|
|
51
|
+
console.log('snap1 previous state equals snap0_state; previous state is correct');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const snap1_state = await snap1.currentState();
|
|
55
|
+
|
|
56
|
+
await doc.save(outputPath + 'addimage.pdf', PDFNet.SDFDoc.SaveOptions.e_incremental);
|
|
57
|
+
|
|
58
|
+
if (await undo_manager.canUndo()) {
|
|
59
|
+
const undo_snap = await undo_manager.undo();
|
|
60
|
+
|
|
61
|
+
await doc.save(outputPath + 'addimage_undone.pdf', PDFNet.SDFDoc.SaveOptions.e_incremental);
|
|
62
|
+
|
|
63
|
+
const undo_snap_state = await undo_snap.currentState();
|
|
64
|
+
|
|
65
|
+
if (await undo_snap_state.equals(snap0_state)) {
|
|
66
|
+
console.log('undo_snap_state equals snap0_state; undo was successful');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (await undo_manager.canRedo()) {
|
|
70
|
+
const redo_snap = await undo_manager.redo();
|
|
71
|
+
|
|
72
|
+
await doc.save(outputPath + 'addimage_redone.pdf', PDFNet.SDFDoc.SaveOptions.e_incremental);
|
|
73
|
+
|
|
74
|
+
if (await (await redo_snap.previousState()).equals(undo_snap_state)) {
|
|
75
|
+
console.log('redo_snap previous state equals undo_snap_state; previous state is correct');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const redo_snap_state = await redo_snap.currentState();
|
|
79
|
+
|
|
80
|
+
if (await redo_snap_state.equals(snap1_state)) {
|
|
81
|
+
console.log('Snap1 and redo_snap are equal; redo was successful');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
console.log('Problem encountered - cannot redo.');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
console.log('Problem encountered - cannot undo.');
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
console.log(err.stack);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
97
|
+
};
|
|
98
|
+
exports.runUndoRedoTest();
|
|
99
|
+
})(exports);
|
|
100
|
+
// eslint-disable-next-line spaced-comment
|
|
101
|
+
//# sourceURL=UndoRedoTest.js
|
|
@@ -1,174 +1,174 @@
|
|
|
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
|
-
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-2024 by Apryse Software 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
|