@pdftron/pdfnet-node-samples 10.12.1 → 11.0.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.
@@ -0,0 +1,120 @@
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
+ const fs = require('fs');
8
+ const { PDFNet } = require('@pdftron/pdfnet-node');
9
+ const PDFTronLicense = require('../LicenseKey/LicenseKey');
10
+
11
+ ((exports) => {
12
+ 'use strict';
13
+
14
+ //---------------------------------------------------------------------------------------
15
+ // The Barcode Module is an optional PDFNet add-on that can be used to extract
16
+ // various types of barcodes from PDF documents.
17
+ //
18
+ // The Apryse SDK Barcode Module can be downloaded from https://dev.apryse.com/
19
+ //---------------------------------------------------------------------------------------
20
+ exports.runBarcodeTest = () => {
21
+ const main = async () => {
22
+
23
+ PDFNet.addResourceSearchPath('../../lib/');
24
+
25
+ if (!(await PDFNet.BarcodeModule.isModuleAvailable())) {
26
+ console.log('\nUnable to run BarcodeTest: Apryse SDK Barcode Module not available.');
27
+ console.log('---------------------------------------------------------------');
28
+ console.log('The Barcode Module is an optional add-on, available for download');
29
+ console.log('at https://dev.apryse.com/. If you have already downloaded this');
30
+ console.log('module, ensure that the SDK is able to find the required files');
31
+ console.log('using the PDFNet.addResourceSearchPath() function.\n');
32
+
33
+ return;
34
+ }
35
+
36
+ // Relative path to the folder containing test files.
37
+ const input_path = '../TestFiles/Barcode/';
38
+ const output_path = '../TestFiles/Output/';
39
+
40
+ //--------------------------------------------------------------------------------
41
+ // Example 1) Detect and extract all barcodes from a PDF document into a JSON file
42
+ try {
43
+
44
+ console.log('Example 1: extracting barcodes from barcodes.pdf to barcodes.json');
45
+
46
+ // A) Open the .pdf document
47
+ const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'barcodes.pdf');
48
+
49
+ // B) Detect PDF barcodes with the default options
50
+ await PDFNet.BarcodeModule.extractBarcodes(doc, output_path + 'barcodes.json');
51
+
52
+ } catch (err) {
53
+ console.log(err);
54
+ }
55
+
56
+ //--------------------------------------------------------------------------------
57
+ // Example 2) Limit barcode extraction to a range of pages, and retrieve the JSON into a
58
+ // local string variable, which is then written to a file in a separate function call
59
+ try {
60
+
61
+ console.log('Example 2: extracting barcodes from pages 1-2 to barcodes_from_pages_1-2.json');
62
+
63
+ // A) Open the .pdf document
64
+ const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'barcodes.pdf');
65
+
66
+ // B) Detect PDF barcodes with custom options
67
+ const options = new PDFNet.BarcodeModule.BarcodeOptions();
68
+
69
+ // Convert only the first two pages
70
+ options.setPages('1-2');
71
+
72
+ const json = await PDFNet.BarcodeModule.extractBarcodesAsString(doc, options);
73
+
74
+ // C) Save JSON to file
75
+ fs.writeFileSync(output_path + 'barcodes_from_pages_1-2.json', json);
76
+
77
+ } catch (err) {
78
+ console.log(err);
79
+ }
80
+
81
+ //--------------------------------------------------------------------------------
82
+ // Example 3) Narrow down barcode types and allow the detection of both horizontal
83
+ // and vertical barcodes
84
+ try {
85
+
86
+ console.log('Example 3: extracting basic horizontal and vertical barcodes');
87
+
88
+ // A) Open the .pdf document
89
+ const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'barcodes.pdf');
90
+
91
+ // B) Detect only basic 1D barcodes, both horizontal and vertical
92
+ const options = new PDFNet.BarcodeModule.BarcodeOptions();
93
+
94
+ // Limit extraction to basic 1D barcode types, such as EAN 13, EAN 8, UPCA, UPCE,
95
+ // Code 3 of 9, Code 128, Code 2 of 5, Code 93, Code 11 and GS1 Databar.
96
+ options.setBarcodeSearchTypes(PDFNet.BarcodeModule.BarcodeOptions.BarcodeTypeGroup.e_linear);
97
+
98
+ // Search for barcodes oriented horizontally and vertically
99
+ options.setBarcodeOrientations(
100
+ PDFNet.BarcodeModule.BarcodeOptions.BarcodeOrientation.e_horizontal |
101
+ PDFNet.BarcodeModule.BarcodeOptions.BarcodeOrientation.e_vertical);
102
+
103
+ await PDFNet.BarcodeModule.extractBarcodes(doc, output_path + 'barcodes_1D.json', options);
104
+
105
+ } catch (err) {
106
+ console.log(err);
107
+ }
108
+
109
+ //////////////////////////////////////////////////////////////////////////
110
+
111
+ console.log('Done.');
112
+ };
113
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
114
+ console.log('Error: ' + JSON.stringify(error));
115
+ }).then(function(){ return PDFNet.shutdown(); });
116
+ };
117
+ exports.runBarcodeTest();
118
+ })(exports);
119
+ // eslint-disable-next-line spaced-comment
120
+ //# sourceURL=BarcodeTest.js
@@ -0,0 +1,88 @@
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 { PDFNet } = require('@pdftron/pdfnet-node');
7
+ const PDFTronLicense = require('../LicenseKey/LicenseKey');
8
+
9
+ ((exports) => {
10
+ 'use strict';
11
+
12
+ exports.runPDFUATest = () => {
13
+
14
+ //---------------------------------------------------------------------------------------
15
+ // The following sample illustrates how to make sure a file meets the PDF/UA standard, using the PDFUAConformance class object.
16
+ // Note: this feature is currently experimental and subject to change
17
+ //
18
+ // DataExtractionModule is required (Mac users can use StructuredOutputModule instead)
19
+ // https://docs.apryse.com/documentation/core/info/modules/#data-extraction-module
20
+ // https://docs.apryse.com/documentation/core/info/modules/#structured-output-module (Mac)
21
+ //---------------------------------------------------------------------------------------
22
+ const main = async () => {
23
+
24
+ // Relative path to the folder containing test files.
25
+ const input_path = '../TestFiles/';
26
+ const output_path = '../TestFiles/Output/';
27
+
28
+ // DataExtraction library location, replace if desired, should point to a folder that includes the contents of <DataExtractionModuleRoot>/Lib.
29
+ // If using default, unzip the DataExtraction zip to the parent folder of Samples, and merge with existing "Lib" folder
30
+ const extraction_module_path = '../../lib/';
31
+
32
+ const input_file1 = input_path + 'autotag_input.pdf';
33
+ const input_file2 = input_path + 'table.pdf';
34
+ const output_file1 = output_path + 'autotag_pdfua.pdf';
35
+ const output_file2 = output_path + 'table_pdfua_linearized.pdf';
36
+
37
+ try {
38
+ //-----------------------------------------------------------
39
+ // Example: PDF/UA Conversion
40
+ //-----------------------------------------------------------
41
+ console.log('AutoConverting...');
42
+
43
+ await PDFNet.addResourceSearchPath(extraction_module_path);
44
+ if (!await PDFNet.DataExtractionModule.isModuleAvailable(PDFNet.DataExtractionModule.DataExtractionEngine.e_DocStructure)) {
45
+ console.log('');
46
+ console.log('Unable to run PDFUATest: Apryse SDK Data Extraction module not available.');
47
+ console.log('---------------------------------------------------------------');
48
+ console.log('The Data Extraction module is an optional add-on, available for download');
49
+ console.log('at https://apryse.com/. If you have already downloaded this');
50
+ console.log('module, ensure that the SDK is able to find the required files');
51
+ console.log('using the PDFNet.addResourceSearchPath() function.');
52
+ console.log('');
53
+ return;
54
+ }
55
+
56
+ const pdf_ua = await PDFNet.PDFUAConformance.create();
57
+
58
+ console.log('Simple Conversion...');
59
+ {
60
+ // Perform conversion using default options
61
+ await pdf_ua.autoConvert(input_file1, output_file1);
62
+ }
63
+
64
+ console.log('Converting With Options...');
65
+ {
66
+ const pdf_ua_opts = await PDFNet.PDFUAConformance.createPDFUAOptions();
67
+ pdf_ua_opts.setSaveLinearized(true); // Linearize when saving output
68
+ // Note: if file is password protected, you can use pdf_ua_opts.setPassword()
69
+
70
+ // Perform conversion using the options we specify
71
+ await pdf_ua.autoConvert(input_file2, output_file2, pdf_ua_opts);
72
+ }
73
+
74
+ } catch (err) {
75
+ console.log(err);
76
+ }
77
+
78
+ console.log('PDFUAConformance test completed.');
79
+ }
80
+
81
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
82
+ console.log('Error: ' + JSON.stringify(error));
83
+ }).then(function () { return PDFNet.shutdown(); });
84
+ };
85
+ exports.runPDFUATest();
86
+ })(exports);
87
+ // eslint-disable-next-line spaced-comment
88
+ //# sourceURL=PDFUATest.js
@@ -23,7 +23,7 @@
23
23
  //
24
24
  // Please note that PDFNet Publisher (i.e. 'pdftron.PDF.Convert.ToXod') is an
25
25
  // optionally licensable add-on to PDFNet Core SDK. For details, please see
26
- // http://www.pdftron.com/webviewer/licensing.html.
26
+ // https://apryse.com/pricing.
27
27
  //---------------------------------------------------------------------------------------
28
28
 
29
29
  const { PDFNet } = require('@pdftron/pdfnet-node');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdftron/pdfnet-node-samples",
3
- "version": "10.12.1",
3
+ "version": "11.0.0",
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.pdftron.com",
14
14
  "dependencies": {
15
- "@pdftron/pdfnet-node": "^10.12.1",
15
+ "@pdftron/pdfnet-node": "^11.0.0",
16
16
  "run-script-os": "^1.1.6",
17
17
  "underscore": "^1.13.6",
18
18
  "xhr2": "^0.2.1"