@pdftron/pdfnet-node-samples 9.1.0-2 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/package.json +18 -18
  2. package/samples/AddImageTest/AddImageTest.js +115 -115
  3. package/samples/AdvancedImagingTest/AdvancedImagingTest.js +64 -64
  4. package/samples/AnnotationTest/AnnotationTest.js +641 -641
  5. package/samples/BookmarkTest/BookmarkTest.js +219 -219
  6. package/samples/ContentReplacerTest/ContentReplacerTest.js +75 -75
  7. package/samples/ElementBuilderTest/ElementBuilderTest.js +513 -513
  8. package/samples/ElementEditTest/ElementEditTest.js +110 -110
  9. package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +305 -305
  10. package/samples/ElementReaderTest/ElementReaderTest.js +77 -77
  11. package/samples/EncTest/EncTest.js +175 -175
  12. package/samples/LicenseKey/LicenseKey.js +11 -11
  13. package/samples/LogicalStructureTest/LogicalStructureTest.js +250 -250
  14. package/samples/PDF2HtmlTest/PDF2HtmlTest.js +123 -117
  15. package/samples/PDF2OfficeTest/PDF2OfficeTest.js +158 -0
  16. package/samples/PDF2OfficeTest/RunTest.bat +2 -0
  17. package/samples/PDF2OfficeTest/RunTest.sh +2 -0
  18. package/samples/PDFATest/PDFATest.js +85 -85
  19. package/samples/PDFDrawTest/PDFDrawTest.js +305 -305
  20. package/samples/PDFLayersTest/PDFLayersTest.js +294 -294
  21. package/samples/PDFPageTest/PDFPageTest.js +189 -189
  22. package/samples/PDFRedactTest/PDFRedactTest.js +74 -74
  23. package/samples/RectTest/RectTest.js +40 -40
  24. package/samples/SDFTest/SDFTest.js +88 -88
  25. package/samples/StamperTest/StamperTest.js +255 -255
  26. package/samples/TestFiles/Misc-Fixed.pfa +1166 -1166
  27. package/samples/TestFiles/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +34 -34
  28. package/samples/TestFiles/form1_annots.xfdf +33 -33
  29. package/samples/TestFiles/form1_data.xfdf +139 -139
  30. package/samples/TestFiles/my_stream.txt +2310 -2310
  31. package/samples/TextExtractTest/TextExtractTest.js +286 -286
  32. package/samples/TextSearchTest/TextSearchTest.js +121 -121
  33. package/samples/UndoRedoTest/UndoRedoTest.js +101 -101
  34. package/samples/UnicodeWriteTest/UnicodeWriteTest.js +173 -173
  35. package/samples/runall.bat +3 -3
  36. package/samples/runall.sh +14 -14
  37. package/samples/PDF2WordTest/PDF2WordTest.js +0 -85
  38. package/samples/PDF2WordTest/RunTest.bat +0 -2
  39. package/samples/PDF2WordTest/RunTest.sh +0 -2
  40. package/samples/TestFiles/Output/addimage.pdf +0 -0
  41. package/samples/TestFiles/Output/annotation_test1.pdf +0 -0
  42. package/samples/TestFiles/Output/annotation_test2.pdf +0 -0
  43. package/samples/TestFiles/Output/bookmark.pdf +0 -0
  44. package/samples/TestFiles/Output/bookmark_remote.pdf +0 -0
  45. package/samples/TestFiles/Output/new_annot_test_api.pdf +0 -0
@@ -1,89 +1,89 @@
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
- // This sample illustrates how to use basic SDF API (also known as Cos) to edit an
7
- // existing document.
8
-
9
- const { PDFNet } = require('@pdftron/pdfnet-node');
10
- const PDFTronLicense = require('../LicenseKey/LicenseKey');
11
-
12
- ((exports) => {
13
-
14
- exports.runSDFTest = () => {
15
-
16
- const main = async() => {
17
- // Relative path to the folder containing test files.
18
- const inputPath = '../TestFiles/';
19
-
20
- try {
21
- console.log('Opening the test file...');
22
- // Here we create a SDF/Cos document directly from PDF file. In case you have
23
- // PDFDoc you can always access SDF/Cos document using PDFDoc.GetSDFDoc() method.
24
- const docorig = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'fish.pdf');
25
- const doc = await docorig.getSDFDoc();
26
- doc.initSecurityHandler();
27
- console.log('Modifying into dictionary, adding custom properties, embedding a stream...');
28
-
29
- const trailer = await doc.getTrailer(); // Get the trailer
30
-
31
- // Now we will change PDF document information properties using SDF API
32
-
33
- // Get the Info dictionary.
34
-
35
- let itr = await trailer.find('Info');
36
- let info;
37
- if (await itr.hasNext()) {
38
- info = await itr.value();
39
- // Modify 'Producer' entry.
40
- info.putString('Producer', 'PDFTron PDFNet');
41
-
42
- // read title entry if it is present
43
- itr = await info.find('Author');
44
- if (await itr.hasNext()) {
45
- const itrval = await itr.value();
46
- const oldstr = await itrval.getAsPDFText();
47
- info.putText('Author', oldstr + ' - Modified');
48
- } else {
49
- info.putString('Author', 'Me, myself, and I');
50
- }
51
- } else {
52
- // Info dict is missing.
53
- info = await trailer.putDict('Info');
54
- info.putString('Producer', 'PDFTron PDFNet');
55
- info.putString('Title', 'My document');
56
- }
57
-
58
- // Create a custom inline dictionary within Infor dictionary
59
- const customDict = await info.putDict('My Direct Dict');
60
- customDict.putNumber('My Number', 100); // Add some key/value pairs
61
- customDict.putArray('My Array');
62
-
63
- // Create a custom indirect array within Info dictionary
64
- const customArray = await doc.createIndirectArray();
65
- info.put('My Indirect Array', customArray); // Add some entries
66
-
67
- // create indirect link to root
68
- const trailerRoot = await trailer.get('Root');
69
- customArray.pushBack((await trailerRoot.value()));
70
-
71
- // Embed a custom stream (file mystream.txt).
72
- const embedFile = await PDFNet.Filter.createMappedFileFromUString(inputPath + 'my_stream.txt');
73
- const mystm = await PDFNet.FilterReader.create(embedFile);
74
- const indStream = await doc.createIndirectStreamFromFilter(mystm);
75
- customArray.pushBack(indStream);
76
-
77
- console.log('Saving modified test file...');
78
- await doc.save(inputPath + 'Output/sdftest_out.pdf', 0, '%PDF-1.4');
79
- console.log('Test completed.');
80
- } catch (err) {
81
- console.log(err);
82
- }
83
- };
84
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
85
- };
86
- exports.runSDFTest();
87
- })(exports);
88
- // eslint-disable-next-line spaced-comment
1
+ //---------------------------------------------------------------------------------------
2
+ // Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3
+ // Consult legal.txt regarding legal and license information.
4
+ //---------------------------------------------------------------------------------------
5
+
6
+ // This sample illustrates how to use basic SDF API (also known as Cos) to edit an
7
+ // existing document.
8
+
9
+ const { PDFNet } = require('@pdftron/pdfnet-node');
10
+ const PDFTronLicense = require('../LicenseKey/LicenseKey');
11
+
12
+ ((exports) => {
13
+
14
+ exports.runSDFTest = () => {
15
+
16
+ const main = async() => {
17
+ // Relative path to the folder containing test files.
18
+ const inputPath = '../TestFiles/';
19
+
20
+ try {
21
+ console.log('Opening the test file...');
22
+ // Here we create a SDF/Cos document directly from PDF file. In case you have
23
+ // PDFDoc you can always access SDF/Cos document using PDFDoc.GetSDFDoc() method.
24
+ const docorig = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'fish.pdf');
25
+ const doc = await docorig.getSDFDoc();
26
+ doc.initSecurityHandler();
27
+ console.log('Modifying into dictionary, adding custom properties, embedding a stream...');
28
+
29
+ const trailer = await doc.getTrailer(); // Get the trailer
30
+
31
+ // Now we will change PDF document information properties using SDF API
32
+
33
+ // Get the Info dictionary.
34
+
35
+ let itr = await trailer.find('Info');
36
+ let info;
37
+ if (await itr.hasNext()) {
38
+ info = await itr.value();
39
+ // Modify 'Producer' entry.
40
+ info.putString('Producer', 'PDFTron PDFNet');
41
+
42
+ // read title entry if it is present
43
+ itr = await info.find('Author');
44
+ if (await itr.hasNext()) {
45
+ const itrval = await itr.value();
46
+ const oldstr = await itrval.getAsPDFText();
47
+ info.putText('Author', oldstr + ' - Modified');
48
+ } else {
49
+ info.putString('Author', 'Me, myself, and I');
50
+ }
51
+ } else {
52
+ // Info dict is missing.
53
+ info = await trailer.putDict('Info');
54
+ info.putString('Producer', 'PDFTron PDFNet');
55
+ info.putString('Title', 'My document');
56
+ }
57
+
58
+ // Create a custom inline dictionary within Infor dictionary
59
+ const customDict = await info.putDict('My Direct Dict');
60
+ customDict.putNumber('My Number', 100); // Add some key/value pairs
61
+ customDict.putArray('My Array');
62
+
63
+ // Create a custom indirect array within Info dictionary
64
+ const customArray = await doc.createIndirectArray();
65
+ info.put('My Indirect Array', customArray); // Add some entries
66
+
67
+ // create indirect link to root
68
+ const trailerRoot = await trailer.get('Root');
69
+ customArray.pushBack((await trailerRoot.value()));
70
+
71
+ // Embed a custom stream (file mystream.txt).
72
+ const embedFile = await PDFNet.Filter.createMappedFileFromUString(inputPath + 'my_stream.txt');
73
+ const mystm = await PDFNet.FilterReader.create(embedFile);
74
+ const indStream = await doc.createIndirectStreamFromFilter(mystm);
75
+ customArray.pushBack(indStream);
76
+
77
+ console.log('Saving modified test file...');
78
+ await doc.save(inputPath + 'Output/sdftest_out.pdf', 0, '%PDF-1.4');
79
+ console.log('Test completed.');
80
+ } catch (err) {
81
+ console.log(err);
82
+ }
83
+ };
84
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
85
+ };
86
+ exports.runSDFTest();
87
+ })(exports);
88
+ // eslint-disable-next-line spaced-comment
89
89
  //# sourceURL=SDFTest.js