@pdftron/pdfnet-node-samples 9.5.0 → 10.0.0-4

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 (142) hide show
  1. package/package.json +3 -3
  2. package/samples/AddImageTest/AddImageTest.js +1 -1
  3. package/samples/AdvancedImagingTest/AdvancedImagingTest.js +3 -3
  4. package/samples/AnnotationTest/AnnotationTest.js +1 -1
  5. package/samples/BookmarkTest/BookmarkTest.js +1 -1
  6. package/samples/CAD2PDFTest/CAD2PDFTest.js +3 -3
  7. package/samples/ContentReplacerTest/ContentReplacerTest.js +1 -1
  8. package/samples/ConvertTest/ConvertTest.js +1 -1
  9. package/samples/DataExtractionTest/DataExtractionTest.js +7 -7
  10. package/samples/DigitalSignaturesTest/DigitalSignaturesTest.js +1 -1
  11. package/samples/DocumentCreationTest/DocumentCreationTest.js +78 -0
  12. package/samples/ElementBuilderTest/ElementBuilderTest.js +1 -1
  13. package/samples/ElementEditTest/ElementEditTest.js +1 -1
  14. package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +1 -1
  15. package/samples/ElementReaderTest/ElementReaderTest.js +1 -1
  16. package/samples/EncTest/EncTest.js +1 -1
  17. package/samples/FDFTest/FDFTest.js +1 -1
  18. package/samples/HTML2PDFTest/HTML2PDFTest.js +2 -2
  19. package/samples/HighlightsTest/HighlightsTest.js +1 -1
  20. package/samples/ImageExtractTest/ImageExtractTest.js +1 -1
  21. package/samples/ImpositionTest/ImpositionTest.js +1 -1
  22. package/samples/InteractiveFormsTest/InteractiveFormsTest.js +1 -1
  23. package/samples/JBIG2Test/JBIG2Test.js +1 -1
  24. package/samples/LicenseKey/LicenseKey.js +1 -1
  25. package/samples/LogicalStructureTest/LogicalStructureTest.js +1 -1
  26. package/samples/OCRTest/OCRTest.js +2 -2
  27. package/samples/OfficeTemplateTest/OfficeTemplateTest.js +1 -1
  28. package/samples/OfficeToPDFTest/OfficeToPDFTest.js +1 -1
  29. package/samples/OptimizerTest/OptimizerTest.js +1 -1
  30. package/samples/PDF2HtmlTest/PDF2HtmlTest.js +3 -3
  31. package/samples/PDF2OfficeTest/PDF2OfficeTest.js +3 -3
  32. package/samples/PDFATest/PDFATest.js +1 -1
  33. package/samples/PDFDocMemoryTest/PDFDocMemoryTest.js +1 -1
  34. package/samples/PDFDrawTest/PDFDrawTest.js +1 -1
  35. package/samples/PDFLayersTest/PDFLayersTest.js +1 -1
  36. package/samples/PDFPackageTest/PDFPackageTest.js +1 -1
  37. package/samples/PDFPageTest/PDFPageTest.js +1 -1
  38. package/samples/PDFRedactTest/PDFRedactTest.js +1 -1
  39. package/samples/PageLabelsTest/PageLabelsTest.js +1 -1
  40. package/samples/PatternTest/PatternTest.js +1 -1
  41. package/samples/RectTest/RectTest.js +1 -1
  42. package/samples/SDFTest/SDFTest.js +1 -1
  43. package/samples/StamperTest/StamperTest.js +1 -1
  44. package/samples/TextExtractTest/TextExtractTest.js +1 -1
  45. package/samples/TextSearchTest/TextSearchTest.js +1 -1
  46. package/samples/U3DTest/U3DTest.js +1 -1
  47. package/samples/UndoRedoTest/UndoRedoTest.js +1 -1
  48. package/samples/UnicodeWriteTest/UnicodeWriteTest.js +1 -1
  49. package/samples/WebViewerConvertTest/WebViewerConvertTest.js +1 -1
  50. package/samples/AddImageTest/NODEJS/AddImageTest.js +0 -116
  51. package/samples/AddImageTest/NODEJS/RunTest.sh +0 -2
  52. package/samples/AdvancedImagingTest/NODEJS/AdvancedImagingTest.js +0 -78
  53. package/samples/AdvancedImagingTest/NODEJS/RunTest.sh +0 -2
  54. package/samples/AnnotationTest/NODEJS/AnnotationTest.js +0 -642
  55. package/samples/AnnotationTest/NODEJS/RunTest.sh +0 -2
  56. package/samples/BookmarkTest/NODEJS/BookmarkTest.js +0 -220
  57. package/samples/BookmarkTest/NODEJS/RunTest.sh +0 -2
  58. package/samples/CAD2PDFTest/NODEJS/CAD2PDFTest.js +0 -80
  59. package/samples/CAD2PDFTest/NODEJS/RunTest.sh +0 -2
  60. package/samples/ContentReplacerTest/NODEJS/ContentReplacerTest.js +0 -75
  61. package/samples/ContentReplacerTest/NODEJS/RunTest.sh +0 -2
  62. package/samples/ConvertTest/NODEJS/ConvertTest.js +0 -270
  63. package/samples/ConvertTest/NODEJS/RunTest.sh +0 -2
  64. package/samples/DataExtractionTest/NODEJS/DataExtractionTest.js +0 -180
  65. package/samples/DataExtractionTest/NODEJS/RunTest.sh +0 -2
  66. package/samples/DigitalSignaturesTest/NODEJS/DigitalSignaturesTest.js +0 -527
  67. package/samples/DigitalSignaturesTest/NODEJS/RunTest.sh +0 -2
  68. package/samples/ElementBuilderTest/NODEJS/ElementBuilderTest.js +0 -514
  69. package/samples/ElementBuilderTest/NODEJS/RunTest.sh +0 -2
  70. package/samples/ElementEditTest/NODEJS/ElementEditTest.js +0 -111
  71. package/samples/ElementEditTest/NODEJS/RunTest.sh +0 -2
  72. package/samples/ElementReaderAdvTest/NODEJS/ElementReaderAdvTest.js +0 -305
  73. package/samples/ElementReaderAdvTest/NODEJS/RunTest.sh +0 -2
  74. package/samples/ElementReaderTest/NODEJS/ElementReaderTest.js +0 -77
  75. package/samples/ElementReaderTest/NODEJS/RunTest.sh +0 -2
  76. package/samples/EncTest/NODEJS/EncTest.js +0 -176
  77. package/samples/EncTest/NODEJS/RunTest.sh +0 -2
  78. package/samples/FDFTest/NODEJS/FDFTest.js +0 -219
  79. package/samples/FDFTest/NODEJS/RunTest.sh +0 -2
  80. package/samples/HTML2PDFTest/NODEJS/HTML2PDFTest.js +0 -166
  81. package/samples/HTML2PDFTest/NODEJS/RunTest.sh +0 -2
  82. package/samples/HighlightsTest/NODEJS/HighlightsTest.js +0 -97
  83. package/samples/HighlightsTest/NODEJS/RunTest.sh +0 -2
  84. package/samples/ImageExtractTest/NODEJS/ImageExtractTest.js +0 -130
  85. package/samples/ImageExtractTest/NODEJS/RunTest.sh +0 -2
  86. package/samples/ImpositionTest/NODEJS/ImpositionTest.js +0 -87
  87. package/samples/ImpositionTest/NODEJS/RunTest.sh +0 -2
  88. package/samples/InteractiveFormsTest/NODEJS/InteractiveFormsTest.js +0 -382
  89. package/samples/InteractiveFormsTest/NODEJS/RunTest.sh +0 -2
  90. package/samples/JBIG2Test/NODEJS/JBIG2Test.js +0 -89
  91. package/samples/JBIG2Test/NODEJS/RunTest.sh +0 -2
  92. package/samples/LicenseKey/NODEJS/LicenseKey.js +0 -11
  93. package/samples/LogicalStructureTest/NODEJS/LogicalStructureTest.js +0 -251
  94. package/samples/LogicalStructureTest/NODEJS/RunTest.sh +0 -2
  95. package/samples/OCRTest/NODEJS/OCRTest.js +0 -235
  96. package/samples/OCRTest/NODEJS/RunTest.sh +0 -2
  97. package/samples/OfficeTemplateTest/NODEJS/OfficeTemplateTest.js +0 -79
  98. package/samples/OfficeTemplateTest/NODEJS/RunTest.sh +0 -2
  99. package/samples/OfficeToPDFTest/NODEJS/OfficeToPDFTest.js +0 -125
  100. package/samples/OfficeToPDFTest/NODEJS/RunTest.sh +0 -2
  101. package/samples/OptimizerTest/NODEJS/OptimizerTest.js +0 -192
  102. package/samples/OptimizerTest/NODEJS/RunTest.sh +0 -2
  103. package/samples/PDF2HtmlTest/NODEJS/PDF2HtmlTest.js +0 -123
  104. package/samples/PDF2HtmlTest/NODEJS/RunTest.sh +0 -2
  105. package/samples/PDF2OfficeTest/NODEJS/PDF2OfficeTest.js +0 -158
  106. package/samples/PDF2OfficeTest/NODEJS/RunTest.sh +0 -2
  107. package/samples/PDFATest/NODEJS/PDFATest.js +0 -85
  108. package/samples/PDFATest/NODEJS/RunTest.sh +0 -2
  109. package/samples/PDFDocMemoryTest/NODEJS/PDFDocMemoryTest.js +0 -85
  110. package/samples/PDFDocMemoryTest/NODEJS/RunTest.sh +0 -2
  111. package/samples/PDFDrawTest/NODEJS/PDFDrawTest.js +0 -306
  112. package/samples/PDFDrawTest/NODEJS/RunTest.sh +0 -2
  113. package/samples/PDFLayersTest/NODEJS/PDFLayersTest.js +0 -295
  114. package/samples/PDFLayersTest/NODEJS/RunTest.sh +0 -2
  115. package/samples/PDFPackageTest/NODEJS/PDFPackageTest.js +0 -112
  116. package/samples/PDFPackageTest/NODEJS/RunTest.sh +0 -2
  117. package/samples/PDFPageTest/NODEJS/PDFPageTest.js +0 -190
  118. package/samples/PDFPageTest/NODEJS/RunTest.sh +0 -2
  119. package/samples/PDFRedactTest/NODEJS/PDFRedactTest.js +0 -75
  120. package/samples/PDFRedactTest/NODEJS/RunTest.sh +0 -2
  121. package/samples/PageLabelsTest/NODEJS/PageLabelsTest.js +0 -139
  122. package/samples/PageLabelsTest/NODEJS/RunTest.sh +0 -2
  123. package/samples/PatternTest/NODEJS/PatternTest.js +0 -227
  124. package/samples/PatternTest/NODEJS/RunTest.sh +0 -2
  125. package/samples/RectTest/NODEJS/RectTest.js +0 -41
  126. package/samples/RectTest/NODEJS/RunTest.sh +0 -2
  127. package/samples/SDFTest/NODEJS/RunTest.sh +0 -2
  128. package/samples/SDFTest/NODEJS/SDFTest.js +0 -88
  129. package/samples/StamperTest/NODEJS/RunTest.sh +0 -2
  130. package/samples/StamperTest/NODEJS/StamperTest.js +0 -256
  131. package/samples/TextExtractTest/NODEJS/RunTest.sh +0 -2
  132. package/samples/TextExtractTest/NODEJS/TextExtractTest.js +0 -287
  133. package/samples/TextSearchTest/NODEJS/RunTest.sh +0 -2
  134. package/samples/TextSearchTest/NODEJS/TextSearchTest.js +0 -122
  135. package/samples/U3DTest/NODEJS/RunTest.sh +0 -2
  136. package/samples/U3DTest/NODEJS/U3DTest.js +0 -105
  137. package/samples/UndoRedoTest/NODEJS/RunTest.sh +0 -2
  138. package/samples/UndoRedoTest/NODEJS/UndoRedoTest.js +0 -101
  139. package/samples/UnicodeWriteTest/NODEJS/RunTest.sh +0 -2
  140. package/samples/UnicodeWriteTest/NODEJS/UnicodeWriteTest.js +0 -174
  141. package/samples/WebViewerConvertTest/NODEJS/RunTest.sh +0 -2
  142. package/samples/WebViewerConvertTest/NODEJS/WebViewerConvertTest.js +0 -136
@@ -1,75 +0,0 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3
- // Consult legal.txt regarding legal and license information.
4
- //---------------------------------------------------------------------------------------
5
-
6
- // PDF Redactor is a separately licensable Add-on that offers options to remove
7
- // (not just covering or obscuring) content within a region of PDF.
8
- // With printed pages, redaction involves blacking-out or cutting-out areas of
9
- // the printed page. With electronic documents that use formats such as PDF,
10
- // redaction typically involves removing sensitive content within documents for
11
- // safe distribution to courts, patent and government institutions, the media,
12
- // customers, vendors or any other audience with restricted access to the content.
13
- //
14
- // The redaction process in PDFNet consists of two steps:
15
- //
16
- // a) Content identification: A user applies redact annotations that specify the
17
- // pieces or regions of content that should be removed. The content for redaction
18
- // can be identified either interactively (e.g. using 'pdftron.PDF.PDFViewCtrl'
19
- // as shown in PDFView sample) or programmatically (e.g. using 'pdftron.PDF.TextSearch'
20
- // or 'pdftron.PDF.TextExtractor'). Up until the next step is performed, the user
21
- // can see, move and redefine these annotations.
22
- // b) Content removal: Using 'pdftron.PDF.Redactor.Redact()' the user instructs
23
- // PDFNet to apply the redact regions, after which the content in the area specified
24
- // by the redact annotations is removed. The redaction function includes number of
25
- // options to control the style of the redaction overlay (including color, text,
26
- // font, border, transparency, etc.).
27
- //
28
- // PDFTron Redactor makes sure that if a portion of an image, text, or vector graphics
29
- // is contained in a redaction region, that portion of the image or path data is
30
- // destroyed and is not simply hidden with clipping or image masks. PDFNet API can also
31
- // be used to review and remove metadata and other content that can exist in a PDF
32
- // document, including XML Forms Architecture (XFA) content and Extensible Metadata
33
- // Platform (XMP) content.
34
-
35
- const { PDFNet } = require('../../../lib/pdfnet.js');
36
- const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
37
-
38
- ((exports) => {
39
-
40
- exports.runPDFRedactTest = () => {
41
- const redact = async(input, output, vec, app) => {
42
- const doc = await PDFNet.PDFDoc.createFromFilePath(input);
43
- if (await doc.initSecurityHandler()) {
44
- PDFNet.Redactor.redact(doc, vec, app, false, true);
45
- await doc.save(output, PDFNet.SDFDoc.SaveOptions.e_linearized);
46
- }
47
- };
48
-
49
- const main = async() => {
50
- // Relative path to the folder containing test files.
51
- const inputPath = '../../TestFiles/';
52
- try {
53
- const redactionArray = []; // we will contain a list of redaction objects in this array
54
- redactionArray.push(await PDFNet.Redactor.redactionCreate(1, (await PDFNet.Rect.init(100, 100, 550, 600)), false, 'Top Secret'));
55
- redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(30, 30, 450, 450)), true, 'Negative Redaction'));
56
- redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(0, 0, 100, 100)), false, 'Positive'));
57
- redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(100, 100, 200, 200)), false, 'Positive'));
58
- redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(300, 300, 400, 400)), false, ''));
59
- redactionArray.push(await PDFNet.Redactor.redactionCreate(2, (await PDFNet.Rect.init(500, 500, 600, 600)), false, ''));
60
- redactionArray.push(await PDFNet.Redactor.redactionCreate(3, (await PDFNet.Rect.init(0, 0, 700, 20)), false, ''));
61
-
62
- const appear = { redaction_overlay: true, border: false, show_redacted_content_regions: true };
63
- await redact(inputPath + 'newsletter.pdf', inputPath + 'Output/redacted.pdf', redactionArray, appear);
64
-
65
- console.log('Done...');
66
- } catch (err) {
67
- console.log(err.stack);
68
- }
69
- };
70
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
71
- };
72
- exports.runPDFRedactTest();
73
- })(exports);
74
- // eslint-disable-next-line spaced-comment
75
- //# sourceURL=PDFRedactTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node PDFRedactTest.js
@@ -1,139 +0,0 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3
- // Consult legal.txt regarding legal and license information.
4
- //---------------------------------------------------------------------------------------
5
-
6
- //-----------------------------------------------------------------------------------
7
- // The sample illustrates how to work with PDF page labels.
8
- //
9
- // PDF page labels can be used to describe a page. This is used to
10
- // allow for non-sequential page numbering or the addition of arbitrary
11
- // labels for a page (such as the inclusion of Roman numerals at the
12
- // beginning of a book). PDFNet PageLabel object can be used to specify
13
- // the numbering style to use (for example, upper- or lower-case Roman,
14
- // decimal, and so forth), the starting number for the first page,
15
- // and an arbitrary prefix to be pre-appended to each number (for
16
- // example, 'A-' to generate 'A-1', 'A-2', 'A-3', and so forth.)
17
- //-----------------------------------------------------------------------------------
18
-
19
- const { PDFNet } = require('../../../lib/pdfnet.js');
20
- const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
21
-
22
- ((exports) => {
23
- 'use strict';
24
-
25
- exports.runPageLabelsTest = () => {
26
- const main = async () => {
27
- const inputPath = '../../TestFiles/';
28
- const outputPath = inputPath + 'Output/';
29
- const outputFile = outputPath + 'newsletter_with_pagelabels.pdf';
30
-
31
- try {
32
- //-----------------------------------------------------------
33
- // Example 1: Add page labels to an existing or newly created PDF
34
- // document.
35
- //-----------------------------------------------------------
36
- {
37
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
38
- doc.initSecurityHandler();
39
-
40
- // Create a page labeling scheme that starts with the first page in
41
- // the document (page 1) and is using uppercase roman numbering
42
- // style.
43
- const L1 = await PDFNet.PageLabel.create(doc, PDFNet.PageLabel.Style.e_roman_uppercase, 'My Prefix ', 1);
44
- doc.setPageLabel(1, L1);
45
-
46
- // Create a page labeling scheme that starts with the fourth page in
47
- // the document and is using decimal Arabic numbering style.
48
- // Also the numeric portion of the first label should start with number
49
- // 4 (otherwise the first label would be 'My Prefix 1').
50
- const L2 = await PDFNet.PageLabel.create(doc, PDFNet.PageLabel.Style.e_decimal, 'My Prefix ', 4);
51
- doc.setPageLabel(4, L2);
52
-
53
- // Create a page labeling scheme that starts with the seventh page in
54
- // the document and is using alphabetic numbering style. The numeric
55
- // portion of the first label should start with number 1.
56
- const L3 = await PDFNet.PageLabel.create(doc, PDFNet.PageLabel.Style.e_alphabetic_uppercase, 'My Prefix ', 1);
57
- doc.setPageLabel(7, L3);
58
-
59
- doc.save(outputFile, PDFNet.SDFDoc.SaveOptions.e_linearized);
60
- console.log('Done. Result saved in newsletter_with_pagelabels.pdf...');
61
- }
62
-
63
- //-----------------------------------------------------------
64
- // Example 2: Read page labels from an existing PDF document.
65
- //-----------------------------------------------------------
66
- {
67
- const doc = await PDFNet.PDFDoc.createFromFilePath(outputFile);
68
- doc.initSecurityHandler();
69
-
70
- const page_num = await doc.getPageCount();
71
- for (let i = 1; i <= page_num; ++i) {
72
- console.log('Page number: ' + i);
73
- const label = await doc.getPageLabel(i);
74
- if (await label.isValid()) {
75
- console.log(' Label: ' + await label.getLabelTitle(i));
76
- }
77
- else {
78
- console.log(' No Label.');
79
- }
80
- }
81
- }
82
-
83
- //-----------------------------------------------------------
84
- // Example 3: Modify page labels from an existing PDF document.
85
- //-----------------------------------------------------------
86
- {
87
- const doc = await PDFNet.PDFDoc.createFromFilePath(outputFile);
88
- doc.initSecurityHandler();
89
-
90
- // Remove the alphabetic labels from example 1.
91
- doc.removePageLabel(7);
92
-
93
- // Replace the Prefix in the decimal labels (from example 1).
94
- const label = await doc.getPageLabel(4);
95
- if (await label.isValid()) {
96
- await label.setPrefix('A');
97
- label.setStart(1);
98
- }
99
-
100
- // Add a new label
101
- const new_label = await PDFNet.PageLabel.create(doc, PDFNet.PageLabel.Style.e_decimal, 'B', 1);
102
- doc.setPageLabel(10, new_label); // starting from page 10.
103
-
104
- doc.save(outputPath + 'newsletter_with_pagelabels_modified.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
105
- console.log('Done. Result saved in newsletter_with_pagelabels_modified.pdf...');
106
-
107
- const page_num = await doc.getPageCount();
108
- for (let i = 1; i <= page_num; ++i) {
109
- console.log('Page number: ' + i);
110
- const label = await doc.getPageLabel(i);
111
- if (await label.isValid()) {
112
- console.log(' Label: ' + await label.getLabelTitle(i));
113
- }
114
- else {
115
- console.log(' No Label.');
116
- }
117
- }
118
- }
119
-
120
- //-----------------------------------------------------------
121
- // Example 4: Delete all page labels in an existing PDF document.
122
- //-----------------------------------------------------------
123
- {
124
- const doc = await PDFNet.PDFDoc.createFromFilePath(outputFile);
125
- (await doc.getRoot()).eraseFromKey('PageLabels');
126
- }
127
-
128
- } catch (err) {
129
- console.log(err);
130
- }
131
- }
132
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
133
- console.log('Error: ' + JSON.stringify(error));
134
- }).then(function(){ return PDFNet.shutdown(); });
135
- };
136
- exports.runPageLabelsTest();
137
- })(exports);
138
- // eslint-disable-next-line spaced-comment
139
- //# sourceURL=PageLabelsTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node PageLabelsTest.js
@@ -1,227 +0,0 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3
- // Consult legal.txt regarding legal and license information.
4
- //---------------------------------------------------------------------------------------
5
-
6
- const { PDFNet } = require('../../../lib/pdfnet.js');
7
- const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
8
-
9
- ((exports) => {
10
- 'use strict';
11
-
12
- exports.runPatternTest = () => {
13
- const createTilingPattern = async (doc) => {
14
- const writer = await PDFNet.ElementWriter.create();
15
- const eb = await PDFNet.ElementBuilder.create();
16
-
17
- // Create a new pattern content stream - a heart. ------------
18
- writer.begin(doc);
19
- eb.pathBegin();
20
- eb.moveTo(0, 0);
21
- eb.curveTo(500, 500, 125, 625, 0, 500);
22
- eb.curveTo(-125, 625, -500, 500, 0, 0);
23
- const heart = await eb.pathEnd();
24
- heart.setPathFill(true);
25
-
26
- // Set heart color to red.
27
- const gstate = await heart.getGState();
28
- gstate.setFillColorSpace(await PDFNet.ColorSpace.createDeviceRGB());
29
- gstate.setStrokeColorWithColorPt(await PDFNet.ColorPt.init(1, 0, 0));
30
- writer.writeElement(heart);
31
-
32
- const patternDict = await writer.end();
33
-
34
- // Initialize pattern dictionary. For details on what each parameter represents please
35
- // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
36
- patternDict.putName('Type', 'Pattern');
37
- patternDict.putNumber('PatternType', 1);
38
-
39
- // TilingType - Constant spacing.
40
- patternDict.putNumber('TilingType', 1);
41
-
42
- // This is a Type1 pattern - A colored tiling pattern.
43
- patternDict.putNumber('PaintType', 1);
44
-
45
- // Set bounding box
46
- patternDict.putRect('BBox', -253, 0, 253, 545);
47
-
48
- // Create and set the matrix
49
- const pattern_mtx = await PDFNet.Matrix2D.create(0.04, 0, 0, 0.04, 0, 0);
50
- patternDict.putMatrix('Matrix', pattern_mtx);
51
-
52
- // Set the desired horizontal and vertical spacing between pattern cells,
53
- // measured in the pattern coordinate system.
54
- patternDict.putNumber('XStep', 1000);
55
- await patternDict.putNumber('YStep', 1000);
56
-
57
- return patternDict; // finished creating the Pattern resource
58
- }
59
-
60
- const createImageTilingPattern = async (doc) => {
61
- const writer = await PDFNet.ElementWriter.create();
62
- const eb = await PDFNet.ElementBuilder.create();
63
-
64
- // Create a new pattern content stream - a single bitmap object ----------
65
- writer.begin(doc);
66
- const image = await PDFNet.Image.createFromFile(doc, '../../TestFiles/dice.jpg');
67
- const imgElement = await eb.createImageScaled(image, 0, 0, await image.getImageWidth(), await image.getImageHeight());
68
- writer.writePlacedElement(imgElement);
69
-
70
- const patternDict = await writer.end();
71
-
72
- // Initialize pattern dictionary. For details on what each parameter represents please
73
- // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
74
- patternDict.putName('Type', 'Pattern');
75
- patternDict.putNumber('PatternType', 1);
76
-
77
- // TilingType - Constant spacing.
78
- patternDict.putNumber('TilingType', 1);
79
-
80
- // This is a Type1 pattern - A colored tiling pattern.
81
- patternDict.putNumber('PaintType', 1);
82
-
83
- // Set bounding box
84
- patternDict.putRect('BBox', -253, 0, 253, 545);
85
-
86
- // Create and set the matrix
87
- const pattern_mtx = await PDFNet.Matrix2D.create(0.3, 0, 0, 0.3, 0, 0);
88
- patternDict.putMatrix('Matrix', pattern_mtx);
89
-
90
- // Set the desired horizontal and vertical spacing between pattern cells,
91
- // measured in the pattern coordinate system.
92
- patternDict.putNumber('XStep', 300);
93
- await patternDict.putNumber('YStep', 300);
94
-
95
- return patternDict; // finished creating the Pattern resource
96
- }
97
-
98
- const createAxialShading = async (doc) => {
99
- // Create a new Shading object ------------
100
- const patternDict = await doc.createIndirectDict();
101
-
102
- // Initialize pattern dictionary. For details on what each parameter represents
103
- // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
104
- patternDict.putName('Type', 'Pattern');
105
- patternDict.putNumber('PatternType', 2); // 2 stands for shading
106
-
107
- const shadingDict = await patternDict.putDict('Shading');
108
- shadingDict.putNumber('ShadingType', 2);
109
- shadingDict.putName('ColorSpace', 'DeviceCMYK');
110
-
111
- // pass the coordinates of the axial shading to the output
112
- const shadingCoords = await shadingDict.putArray('Coords');
113
- shadingCoords.pushBackNumber(0);
114
- shadingCoords.pushBackNumber(0);
115
- shadingCoords.pushBackNumber(612);
116
- shadingCoords.pushBackNumber(794);
117
-
118
- // pass the function to the axial shading
119
- const func = await shadingDict.putDict('Function');
120
- const C0 = await func.putArray('C0');
121
- C0.pushBackNumber(1);
122
- C0.pushBackNumber(0);
123
- C0.pushBackNumber(0);
124
- await C0.pushBackNumber(0);
125
-
126
- const C1 = await func.putArray('C1');
127
- C1.pushBackNumber(0);
128
- C1.pushBackNumber(1);
129
- C1.pushBackNumber(0);
130
- await C1.pushBackNumber(0);
131
-
132
- const domain = await func.putArray('Domain');
133
- domain.pushBackNumber(0);
134
- await domain.pushBackNumber(1);
135
-
136
- func.putNumber('FunctionType', 2);
137
- await func.putNumber('N', 1);
138
-
139
- return patternDict;
140
- }
141
-
142
- const main = async () => {
143
- try {
144
- const doc = await PDFNet.PDFDoc.create();
145
- const writer = await PDFNet.ElementWriter.create();
146
- var eb = await PDFNet.ElementBuilder.create();
147
-
148
- // The following sample illustrates how to create and use tiling patterns
149
- var page = await doc.pageCreate();
150
- writer.beginOnPage(page);
151
-
152
- var element = await eb.createTextBeginWithFont(await PDFNet.Font.createAndEmbed(doc, PDFNet.Font.StandardType1Font.e_times_bold), 1);
153
- writer.writeElement(element); // Begin the text block
154
-
155
- const data = 'G';
156
- element = await eb.createNewTextRun(data);
157
- element.setTextMatrixEntries(720, 0, 0, 720, 20, 240);
158
- var gs = await element.getGState();
159
- gs.setTextRenderMode(PDFNet.GState.TextRenderingMode.e_fill_stroke_text);
160
- gs.setLineWidth(4);
161
-
162
- // Set the fill color space to the Pattern color space.
163
- gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
164
- var patterColor = await PDFNet.PatternColor.create(await createTilingPattern(doc));
165
- gs.setFillColorWithPattern(patterColor);
166
-
167
- writer.writeElement(element);
168
- writer.writeElement(await eb.createTextEnd()); // Finish the text block
169
-
170
- writer.end(); // Save the page
171
- doc.pagePushBack(page);
172
- //-----------------------------------------------
173
-
174
- /// The following sample illustrates how to create and use image tiling pattern
175
- page = await doc.pageCreate();
176
- writer.beginOnPage(page);
177
-
178
- eb.reset();
179
- element = await eb.createRect(0, 0, 612, 794);
180
-
181
- // Set the fill color space to the Pattern color space.
182
- gs = await element.getGState();
183
- gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
184
- patterColor = await PDFNet.PatternColor.create(await createImageTilingPattern(doc));
185
- gs.setFillColorWithPattern(patterColor);
186
- element.setPathFill(true);
187
-
188
- writer.writeElement(element);
189
-
190
- await writer.end(); // Save the page
191
- doc.pagePushBack(page);
192
- //-----------------------------------------------
193
-
194
- /// The following sample illustrates how to create and use PDF shadings
195
- page = await doc.pageCreate();
196
- writer.beginOnPage(page);
197
-
198
- eb.reset();
199
- element = await eb.createRect(0, 0, 612, 794);
200
-
201
- // Set the fill color space to the Pattern color space.
202
- gs = await element.getGState();
203
- gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
204
- patterColor = await PDFNet.PatternColor.create(await createAxialShading(doc));
205
- gs.setFillColorWithPattern(patterColor);
206
- element.setPathFill(true);
207
-
208
- writer.writeElement(element);
209
-
210
- await writer.end(); // Save the page
211
- doc.pagePushBack(page);
212
- //-----------------------------------------------
213
-
214
- await doc.save('../../TestFiles/Output/patterns.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
215
- console.log('Done. Result saved in patterns.pdf...');
216
- } catch (err) {
217
- console.log(err);
218
- }
219
- }
220
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
221
- console.log('Error: ' + JSON.stringify(error));
222
- }).then(function(){ return PDFNet.shutdown(); });
223
- };
224
- exports.runPatternTest();
225
- })(exports);
226
- // eslint-disable-next-line spaced-comment
227
- //# sourceURL=PatternTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node PatternTest.js
@@ -1,41 +0,0 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3
- // Consult legal.txt regarding legal and license information.
4
- //---------------------------------------------------------------------------------------
5
-
6
-
7
- const { PDFNet } = require('../../../lib/pdfnet.js');
8
- const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
9
-
10
- ((exports) => {
11
-
12
- exports.runRectTest = () => {
13
-
14
- const main = async() => {
15
- try {
16
- console.log('_______________________________________________');
17
- console.log('Opening the input pdf...');
18
-
19
- const inputPath = '../../TestFiles/';
20
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'tiger.pdf');
21
- doc.initSecurityHandler();
22
-
23
- const pgItr1 = await doc.getPageIterator();
24
- const mediaBox = await (await pgItr1.current()).getMediaBox();
25
- mediaBox.x1 -= 200; // translate page 200 units left(1 uint = 1/72 inch)
26
- mediaBox.x2 -= 200;
27
-
28
- await mediaBox.update();
29
-
30
- await doc.save(inputPath + 'Output/tiger_shift.pdf', 0);
31
- console.log('Done. Result saved in tiger_shift...');
32
- } catch (err) {
33
- console.log(err);
34
- }
35
- };
36
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
37
- };
38
- exports.runRectTest();
39
- })(exports);
40
- // eslint-disable-next-line spaced-comment
41
- //# sourceURL=AnnotationTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node RectTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node SDFTest.js
@@ -1,88 +0,0 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3
- // Consult legal.txt regarding legal and license information.
4
- //---------------------------------------------------------------------------------------
5
-
6
- // This sample illustrates how to use basic SDF API (also known as Cos) to edit an
7
- // existing document.
8
-
9
- const { PDFNet } = require('../../../lib/pdfnet.js');
10
- const PDFTronLicense = require('../../LicenseKey/NODEJS/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 doc = await PDFNet.SDFDoc.createFromFileUString(inputPath + 'fish.pdf');
25
- doc.initSecurityHandler();
26
- console.log('Modifying into dictionary, adding custom properties, embedding a stream...');
27
-
28
- const trailer = await doc.getTrailer(); // Get the trailer
29
-
30
- // Now we will change PDF document information properties using SDF API
31
-
32
- // Get the Info dictionary.
33
-
34
- let itr = await trailer.find('Info');
35
- let info;
36
- if (await itr.hasNext()) {
37
- info = await itr.value();
38
- // Modify 'Producer' entry.
39
- info.putString('Producer', 'PDFTron PDFNet');
40
-
41
- // read title entry if it is present
42
- itr = await info.find('Author');
43
- if (await itr.hasNext()) {
44
- const itrval = await itr.value();
45
- const oldstr = await itrval.getAsPDFText();
46
- info.putText('Author', oldstr + ' - Modified');
47
- } else {
48
- info.putString('Author', 'Me, myself, and I');
49
- }
50
- } else {
51
- // Info dict is missing.
52
- info = await trailer.putDict('Info');
53
- info.putString('Producer', 'PDFTron PDFNet');
54
- info.putString('Title', 'My document');
55
- }
56
-
57
- // Create a custom inline dictionary within Infor dictionary
58
- const customDict = await info.putDict('My Direct Dict');
59
- customDict.putNumber('My Number', 100); // Add some key/value pairs
60
- customDict.putArray('My Array');
61
-
62
- // Create a custom indirect array within Info dictionary
63
- const customArray = await doc.createIndirectArray();
64
- info.put('My Indirect Array', customArray); // Add some entries
65
-
66
- // create indirect link to root
67
- const trailerRoot = await trailer.get('Root');
68
- customArray.pushBack((await trailerRoot.value()));
69
-
70
- // Embed a custom stream (file mystream.txt).
71
- const embedFile = await PDFNet.Filter.createMappedFileFromUString(inputPath + 'my_stream.txt');
72
- const mystm = await PDFNet.FilterReader.create(embedFile);
73
- const indStream = await doc.createIndirectStreamFromFilter(mystm);
74
- customArray.pushBack(indStream);
75
-
76
- console.log('Saving modified test file...');
77
- await doc.save(inputPath + 'Output/sdftest_out.pdf', 0, '%PDF-1.4');
78
- console.log('Test completed.');
79
- } catch (err) {
80
- console.log(err);
81
- }
82
- };
83
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
84
- };
85
- exports.runSDFTest();
86
- })(exports);
87
- // eslint-disable-next-line spaced-comment
88
- //# sourceURL=SDFTest.js
@@ -1,2 +0,0 @@
1
- #!/bin/sh
2
- node StamperTest.js