@pdftron/pdfnet-node-samples 11.11.1 → 11.12.0-beta
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.
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
//---------------------------------------------------------------------------------------
|
|
2
|
+
// Copyright (c) 2001-2026 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 { PDFNet } = require('@pdftron/pdfnet-node');
|
|
8
|
+
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
9
|
+
|
|
10
|
+
((exports) => {
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
//---------------------------------------------------------------------------------------
|
|
14
|
+
// The Handwriting ICR Module is an optional PDFNet add-on that can be used to extract
|
|
15
|
+
// handwriting from image-based pages and apply them as hidden text.
|
|
16
|
+
//
|
|
17
|
+
// The Apryse SDK Handwriting ICR Module can be downloaded from https://dev.apryse.com/
|
|
18
|
+
//---------------------------------------------------------------------------------------
|
|
19
|
+
exports.runHandwritingICRTest = () => {
|
|
20
|
+
const main = async () => {
|
|
21
|
+
try {
|
|
22
|
+
// The location of the Handwriting ICR Module
|
|
23
|
+
PDFNet.addResourceSearchPath('../../lib/');
|
|
24
|
+
|
|
25
|
+
if (!(await PDFNet.HandwritingICRModule.isModuleAvailable())) {
|
|
26
|
+
console.log('\nUnable to run HandwritingICRTest: Apryse SDK Handwriting ICR Module');
|
|
27
|
+
console.log('not available.');
|
|
28
|
+
console.log('---------------------------------------------------------------');
|
|
29
|
+
console.log('The Handwriting ICR Module is an optional add-on, available for download');
|
|
30
|
+
console.log('at https://dev.apryse.com/. If you have already downloaded this');
|
|
31
|
+
console.log('module, ensure that the SDK is able to find the required files');
|
|
32
|
+
console.log('using the PDFNet.addResourceSearchPath() function.\n');
|
|
33
|
+
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Relative path to the folder containing test files.
|
|
38
|
+
const input_path = '../TestFiles/HandwritingICR/';
|
|
39
|
+
const output_path = '../TestFiles/Output/';
|
|
40
|
+
|
|
41
|
+
//--------------------------------------------------------------------------------
|
|
42
|
+
// Example 1) Process a PDF without specifying options
|
|
43
|
+
try {
|
|
44
|
+
console.log('Example 1: processing icr.pdf');
|
|
45
|
+
|
|
46
|
+
// Open the .pdf document
|
|
47
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'icr.pdf');
|
|
48
|
+
|
|
49
|
+
// Run ICR on the .pdf with the default options
|
|
50
|
+
await PDFNet.HandwritingICRModule.processPDF(doc);
|
|
51
|
+
|
|
52
|
+
// Save the result with hidden text applied
|
|
53
|
+
await doc.save(output_path + 'icr-simple.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.log(err);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//--------------------------------------------------------------------------------
|
|
59
|
+
// Example 2) Process a subset of PDF pages
|
|
60
|
+
try {
|
|
61
|
+
console.log('Example 2: processing pages from icr.pdf');
|
|
62
|
+
|
|
63
|
+
// Open the .pdf document
|
|
64
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'icr.pdf');
|
|
65
|
+
|
|
66
|
+
// Process handwriting with custom options
|
|
67
|
+
const options = await PDFNet.HandwritingICRModule.createHandwritingICROptions();
|
|
68
|
+
|
|
69
|
+
// Optionally, process a subset of pages
|
|
70
|
+
options.setPages("2-3");
|
|
71
|
+
|
|
72
|
+
// Run ICR on the .pdf
|
|
73
|
+
await PDFNet.HandwritingICRModule.processPDF(doc, options);
|
|
74
|
+
|
|
75
|
+
// Save the result with hidden text applied
|
|
76
|
+
await doc.save(output_path + 'icr-pages.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.log(err);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//--------------------------------------------------------------------------------
|
|
82
|
+
// Example 3) Ignore zones specified for each page
|
|
83
|
+
try {
|
|
84
|
+
console.log('Example 3: processing & ignoring zones');
|
|
85
|
+
|
|
86
|
+
// Open the .pdf document
|
|
87
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'icr.pdf');
|
|
88
|
+
|
|
89
|
+
// Process handwriting with custom options
|
|
90
|
+
const options = await PDFNet.HandwritingICRModule.createHandwritingICROptions();
|
|
91
|
+
|
|
92
|
+
// Process page 2 by ignoring the signature area on the bottom
|
|
93
|
+
options.setPages("2");
|
|
94
|
+
const ignore_zones_page2 = [];
|
|
95
|
+
// These coordinates are in PDF user space, with the origin at the bottom left corner of the page.
|
|
96
|
+
// Coordinates rotate with the page, if it has rotation applied.
|
|
97
|
+
ignore_zones_page2.push(new PDFNet.Rect(78, 850.1 - 770, 340, 850.1 - 676));
|
|
98
|
+
options.addIgnoreZonesForPage(ignore_zones_page2, 2);
|
|
99
|
+
|
|
100
|
+
// Run ICR on the .pdf
|
|
101
|
+
await PDFNet.HandwritingICRModule.processPDF(doc, options);
|
|
102
|
+
|
|
103
|
+
// Save the result with hidden text applied
|
|
104
|
+
await doc.save(output_path + 'icr-ignore.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
console.log(err);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//--------------------------------------------------------------------------------
|
|
110
|
+
// Example 4) The postprocessing workflow has also an option of extracting ICR results
|
|
111
|
+
// in JSON format, similar to the one used by the OCR Module
|
|
112
|
+
try {
|
|
113
|
+
console.log('Example 4: extract & apply');
|
|
114
|
+
|
|
115
|
+
// Open the .pdf document
|
|
116
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'icr.pdf');
|
|
117
|
+
|
|
118
|
+
// Extract ICR results in JSON format
|
|
119
|
+
const json = await PDFNet.HandwritingICRModule.getICRJsonFromPDF(doc);
|
|
120
|
+
fs.writeFileSync(output_path + "icr-get.json", json);
|
|
121
|
+
|
|
122
|
+
// Insert your post-processing step (whatever it might be)
|
|
123
|
+
// ...
|
|
124
|
+
|
|
125
|
+
// Apply potentially modified ICR JSON to the PDF
|
|
126
|
+
await PDFNet.HandwritingICRModule.applyICRJsonToPDF(doc, json);
|
|
127
|
+
|
|
128
|
+
// Save the result with hidden text applied
|
|
129
|
+
await doc.save(output_path + 'icr-get-apply.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
130
|
+
} catch (err) {
|
|
131
|
+
console.log(err);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
console.log('Done.');
|
|
135
|
+
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.log(err);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
|
|
141
|
+
console.log('Error: ' + JSON.stringify(error));
|
|
142
|
+
}).then(function(){ return PDFNet.shutdown(); });
|
|
143
|
+
};
|
|
144
|
+
exports.runHandwritingICRTest();
|
|
145
|
+
})(exports);
|
|
146
|
+
// eslint-disable-next-line spaced-comment
|
|
147
|
+
//# sourceURL=HandwritingICRTest.js
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//---------------------------------------------------------------------------------------
|
|
2
|
+
// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
|
|
3
|
+
// Consult legal.txt regarding legal and license information.
|
|
4
|
+
//---------------------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
//------------------------------------------------------------------------------
|
|
7
|
+
// PDFNet's Sanitizer is a security-focused feature that permanently removes
|
|
8
|
+
// hidden, sensitive, or potentially unsafe content from a PDF document.
|
|
9
|
+
// While redaction targets visible page content such as text or graphics,
|
|
10
|
+
// sanitization focuses on non-visual elements and embedded structures.
|
|
11
|
+
//
|
|
12
|
+
// PDFNet Sanitizer ensures hidden or inactive content is destroyed,
|
|
13
|
+
// not merely obscured or disabled. This prevents leakage of sensitive
|
|
14
|
+
// data such as authoring details, editing history, private identifiers,
|
|
15
|
+
// and residual form entries, and neutralizes scripts or attachments.
|
|
16
|
+
//
|
|
17
|
+
// Sanitization is recommended prior to external sharing with clients,
|
|
18
|
+
// partners, or regulatory bodies. It helps align with privacy policies
|
|
19
|
+
// and compliance requirements by permanently removing non-visual data.
|
|
20
|
+
//------------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
23
|
+
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
24
|
+
|
|
25
|
+
((exports) => {
|
|
26
|
+
|
|
27
|
+
exports.runPDFSanitizeTest = () => {
|
|
28
|
+
|
|
29
|
+
const main = async() => {
|
|
30
|
+
// Relative path to the folder containing test files.
|
|
31
|
+
const inputPath = '../TestFiles/';
|
|
32
|
+
const outputPath = '../TestFiles/Output/';
|
|
33
|
+
|
|
34
|
+
// The following example illustrates how to retrieve the existing
|
|
35
|
+
// sanitizable content categories within a document.
|
|
36
|
+
try {
|
|
37
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'numbered.pdf');
|
|
38
|
+
if (await doc.initSecurityHandler()) {
|
|
39
|
+
const opts = await PDFNet.Sanitizer.getSanitizableContent(doc);
|
|
40
|
+
if (opts.getMetadata()) {
|
|
41
|
+
console.log('Document has metadata.');
|
|
42
|
+
}
|
|
43
|
+
if (opts.getMarkups()) {
|
|
44
|
+
console.log('Document has markups.');
|
|
45
|
+
}
|
|
46
|
+
if (opts.getHiddenLayers()) {
|
|
47
|
+
console.log('Document has hidden layers.');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.log('Done...');
|
|
51
|
+
} catch (err) {
|
|
52
|
+
console.log(err.stack);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The following example illustrates how to sanitize a document with default options,
|
|
56
|
+
// which will remove all sanitizable content present within a document.
|
|
57
|
+
try {
|
|
58
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'financial.pdf');
|
|
59
|
+
if (await doc.initSecurityHandler()) {
|
|
60
|
+
await PDFNet.Sanitizer.sanitizeDocument(doc);
|
|
61
|
+
await doc.save(outputPath + 'financial_sanitized.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
62
|
+
}
|
|
63
|
+
console.log('Done...');
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.log(err.stack);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// The following example illustrates how to sanitize a document with custom set options,
|
|
69
|
+
// which will only remove the content categories specified by the options object.
|
|
70
|
+
try {
|
|
71
|
+
const options = new PDFNet.Sanitizer.SanitizeOptions();
|
|
72
|
+
options.setMetadata(true);
|
|
73
|
+
options.setFormData(true);
|
|
74
|
+
options.setBookmarks(true);
|
|
75
|
+
|
|
76
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'form1.pdf');
|
|
77
|
+
if (await doc.initSecurityHandler()) {
|
|
78
|
+
await PDFNet.Sanitizer.sanitizeDocument(doc, options);
|
|
79
|
+
await doc.save(outputPath + 'form1_sanitized.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
80
|
+
}
|
|
81
|
+
console.log('Done...');
|
|
82
|
+
} catch (err) {
|
|
83
|
+
console.log(err.stack);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
|
|
87
|
+
};
|
|
88
|
+
exports.runPDFSanitizeTest();
|
|
89
|
+
})(exports);
|
|
90
|
+
// eslint-disable-next-line spaced-comment
|
|
91
|
+
//# sourceURL=PDFSanitizeTest.js
|
|
@@ -39,7 +39,10 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
|
39
39
|
|
|
40
40
|
// Optionally, subset the pages to process
|
|
41
41
|
// This PDF only has a single page, but you can specify a subset of pages like this
|
|
42
|
-
// options.setPages("-2,5-6,9,11-");
|
|
42
|
+
// options.setPages("-2,5-6,9,11-");
|
|
43
|
+
|
|
44
|
+
// Optionally, set the XLIFF exported version, default is 1.2
|
|
45
|
+
// options.setXLIFFVersion(PDFNet.TransPDF.TransPDFOptions.XLIFFVersion.e_xliff_version_2);
|
|
43
46
|
|
|
44
47
|
// Extract the xlf to file and field the PDF for translation
|
|
45
48
|
await PDFNet.TransPDF.extractXLIFF(doc, outputPath + 'find-replace-test.xlf', options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdftron/pdfnet-node-samples",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.12.0-beta",
|
|
4
4
|
"description": "Sample code for the @pdftron/pdfnet-node package.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "run-script-os",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"license": "Commercial",
|
|
13
13
|
"homepage": "https://www.apryse.com",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@pdftron/pdfnet-node": "^11.
|
|
15
|
+
"@pdftron/pdfnet-node": "^11.12.0-beta",
|
|
16
16
|
"run-script-os": "^1.1.6",
|
|
17
17
|
"underscore": "^1.13.6",
|
|
18
18
|
"xhr2": "^0.2.1"
|