@pdftron/pdfnet-node-samples 9.5.0 → 10.0.0-3
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/package.json +3 -3
- package/samples/AddImageTest/AddImageTest.js +1 -1
- package/samples/AdvancedImagingTest/AdvancedImagingTest.js +3 -3
- package/samples/AnnotationTest/AnnotationTest.js +1 -1
- package/samples/BookmarkTest/BookmarkTest.js +1 -1
- package/samples/CAD2PDFTest/CAD2PDFTest.js +3 -3
- package/samples/ContentReplacerTest/ContentReplacerTest.js +1 -1
- package/samples/ConvertTest/ConvertTest.js +1 -1
- package/samples/DataExtractionTest/DataExtractionTest.js +7 -7
- package/samples/DigitalSignaturesTest/DigitalSignaturesTest.js +1 -1
- package/samples/DocumentCreationTest/DocumentCreationTest.js +78 -0
- package/samples/ElementBuilderTest/ElementBuilderTest.js +1 -1
- package/samples/ElementEditTest/ElementEditTest.js +1 -1
- package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +1 -1
- package/samples/ElementReaderTest/ElementReaderTest.js +1 -1
- package/samples/EncTest/EncTest.js +1 -1
- package/samples/FDFTest/FDFTest.js +1 -1
- package/samples/HTML2PDFTest/HTML2PDFTest.js +2 -2
- package/samples/HighlightsTest/HighlightsTest.js +1 -1
- package/samples/ImageExtractTest/ImageExtractTest.js +1 -1
- package/samples/ImpositionTest/ImpositionTest.js +1 -1
- package/samples/InteractiveFormsTest/InteractiveFormsTest.js +1 -1
- package/samples/JBIG2Test/JBIG2Test.js +1 -1
- package/samples/LicenseKey/LicenseKey.js +1 -1
- package/samples/LogicalStructureTest/LogicalStructureTest.js +1 -1
- package/samples/OCRTest/OCRTest.js +2 -2
- package/samples/OfficeTemplateTest/OfficeTemplateTest.js +1 -1
- package/samples/OfficeToPDFTest/OfficeToPDFTest.js +1 -1
- package/samples/OptimizerTest/OptimizerTest.js +1 -1
- package/samples/PDF2HtmlTest/PDF2HtmlTest.js +3 -3
- package/samples/PDF2OfficeTest/PDF2OfficeTest.js +3 -3
- package/samples/PDFATest/PDFATest.js +1 -1
- package/samples/PDFDocMemoryTest/PDFDocMemoryTest.js +1 -1
- package/samples/PDFDrawTest/PDFDrawTest.js +1 -1
- package/samples/PDFLayersTest/PDFLayersTest.js +1 -1
- package/samples/PDFPackageTest/PDFPackageTest.js +1 -1
- package/samples/PDFPageTest/PDFPageTest.js +1 -1
- package/samples/PDFRedactTest/PDFRedactTest.js +1 -1
- package/samples/PageLabelsTest/PageLabelsTest.js +1 -1
- package/samples/PatternTest/PatternTest.js +1 -1
- package/samples/RectTest/RectTest.js +1 -1
- package/samples/SDFTest/SDFTest.js +1 -1
- package/samples/StamperTest/StamperTest.js +1 -1
- package/samples/TextExtractTest/TextExtractTest.js +1 -1
- package/samples/TextSearchTest/TextSearchTest.js +1 -1
- package/samples/U3DTest/U3DTest.js +1 -1
- package/samples/UndoRedoTest/UndoRedoTest.js +1 -1
- package/samples/UnicodeWriteTest/UnicodeWriteTest.js +1 -1
- package/samples/WebViewerConvertTest/WebViewerConvertTest.js +1 -1
- package/samples/AddImageTest/NODEJS/AddImageTest.js +0 -116
- package/samples/AddImageTest/NODEJS/RunTest.sh +0 -2
- package/samples/AdvancedImagingTest/NODEJS/AdvancedImagingTest.js +0 -78
- package/samples/AdvancedImagingTest/NODEJS/RunTest.sh +0 -2
- package/samples/AnnotationTest/NODEJS/AnnotationTest.js +0 -642
- package/samples/AnnotationTest/NODEJS/RunTest.sh +0 -2
- package/samples/BookmarkTest/NODEJS/BookmarkTest.js +0 -220
- package/samples/BookmarkTest/NODEJS/RunTest.sh +0 -2
- package/samples/CAD2PDFTest/NODEJS/CAD2PDFTest.js +0 -80
- package/samples/CAD2PDFTest/NODEJS/RunTest.sh +0 -2
- package/samples/ContentReplacerTest/NODEJS/ContentReplacerTest.js +0 -75
- package/samples/ContentReplacerTest/NODEJS/RunTest.sh +0 -2
- package/samples/ConvertTest/NODEJS/ConvertTest.js +0 -270
- package/samples/ConvertTest/NODEJS/RunTest.sh +0 -2
- package/samples/DataExtractionTest/NODEJS/DataExtractionTest.js +0 -180
- package/samples/DataExtractionTest/NODEJS/RunTest.sh +0 -2
- package/samples/DigitalSignaturesTest/NODEJS/DigitalSignaturesTest.js +0 -527
- package/samples/DigitalSignaturesTest/NODEJS/RunTest.sh +0 -2
- package/samples/ElementBuilderTest/NODEJS/ElementBuilderTest.js +0 -514
- package/samples/ElementBuilderTest/NODEJS/RunTest.sh +0 -2
- package/samples/ElementEditTest/NODEJS/ElementEditTest.js +0 -111
- package/samples/ElementEditTest/NODEJS/RunTest.sh +0 -2
- package/samples/ElementReaderAdvTest/NODEJS/ElementReaderAdvTest.js +0 -305
- package/samples/ElementReaderAdvTest/NODEJS/RunTest.sh +0 -2
- package/samples/ElementReaderTest/NODEJS/ElementReaderTest.js +0 -77
- package/samples/ElementReaderTest/NODEJS/RunTest.sh +0 -2
- package/samples/EncTest/NODEJS/EncTest.js +0 -176
- package/samples/EncTest/NODEJS/RunTest.sh +0 -2
- package/samples/FDFTest/NODEJS/FDFTest.js +0 -219
- package/samples/FDFTest/NODEJS/RunTest.sh +0 -2
- package/samples/HTML2PDFTest/NODEJS/HTML2PDFTest.js +0 -166
- package/samples/HTML2PDFTest/NODEJS/RunTest.sh +0 -2
- package/samples/HighlightsTest/NODEJS/HighlightsTest.js +0 -97
- package/samples/HighlightsTest/NODEJS/RunTest.sh +0 -2
- package/samples/ImageExtractTest/NODEJS/ImageExtractTest.js +0 -130
- package/samples/ImageExtractTest/NODEJS/RunTest.sh +0 -2
- package/samples/ImpositionTest/NODEJS/ImpositionTest.js +0 -87
- package/samples/ImpositionTest/NODEJS/RunTest.sh +0 -2
- package/samples/InteractiveFormsTest/NODEJS/InteractiveFormsTest.js +0 -382
- package/samples/InteractiveFormsTest/NODEJS/RunTest.sh +0 -2
- package/samples/JBIG2Test/NODEJS/JBIG2Test.js +0 -89
- package/samples/JBIG2Test/NODEJS/RunTest.sh +0 -2
- package/samples/LicenseKey/NODEJS/LicenseKey.js +0 -11
- package/samples/LogicalStructureTest/NODEJS/LogicalStructureTest.js +0 -251
- package/samples/LogicalStructureTest/NODEJS/RunTest.sh +0 -2
- package/samples/OCRTest/NODEJS/OCRTest.js +0 -235
- package/samples/OCRTest/NODEJS/RunTest.sh +0 -2
- package/samples/OfficeTemplateTest/NODEJS/OfficeTemplateTest.js +0 -79
- package/samples/OfficeTemplateTest/NODEJS/RunTest.sh +0 -2
- package/samples/OfficeToPDFTest/NODEJS/OfficeToPDFTest.js +0 -125
- package/samples/OfficeToPDFTest/NODEJS/RunTest.sh +0 -2
- package/samples/OptimizerTest/NODEJS/OptimizerTest.js +0 -192
- package/samples/OptimizerTest/NODEJS/RunTest.sh +0 -2
- package/samples/PDF2HtmlTest/NODEJS/PDF2HtmlTest.js +0 -123
- package/samples/PDF2HtmlTest/NODEJS/RunTest.sh +0 -2
- package/samples/PDF2OfficeTest/NODEJS/PDF2OfficeTest.js +0 -158
- package/samples/PDF2OfficeTest/NODEJS/RunTest.sh +0 -2
- package/samples/PDFATest/NODEJS/PDFATest.js +0 -85
- package/samples/PDFATest/NODEJS/RunTest.sh +0 -2
- package/samples/PDFDocMemoryTest/NODEJS/PDFDocMemoryTest.js +0 -85
- package/samples/PDFDocMemoryTest/NODEJS/RunTest.sh +0 -2
- package/samples/PDFDrawTest/NODEJS/PDFDrawTest.js +0 -306
- package/samples/PDFDrawTest/NODEJS/RunTest.sh +0 -2
- package/samples/PDFLayersTest/NODEJS/PDFLayersTest.js +0 -295
- package/samples/PDFLayersTest/NODEJS/RunTest.sh +0 -2
- package/samples/PDFPackageTest/NODEJS/PDFPackageTest.js +0 -112
- package/samples/PDFPackageTest/NODEJS/RunTest.sh +0 -2
- package/samples/PDFPageTest/NODEJS/PDFPageTest.js +0 -190
- package/samples/PDFPageTest/NODEJS/RunTest.sh +0 -2
- package/samples/PDFRedactTest/NODEJS/PDFRedactTest.js +0 -75
- package/samples/PDFRedactTest/NODEJS/RunTest.sh +0 -2
- package/samples/PageLabelsTest/NODEJS/PageLabelsTest.js +0 -139
- package/samples/PageLabelsTest/NODEJS/RunTest.sh +0 -2
- package/samples/PatternTest/NODEJS/PatternTest.js +0 -227
- package/samples/PatternTest/NODEJS/RunTest.sh +0 -2
- package/samples/RectTest/NODEJS/RectTest.js +0 -41
- package/samples/RectTest/NODEJS/RunTest.sh +0 -2
- package/samples/SDFTest/NODEJS/RunTest.sh +0 -2
- package/samples/SDFTest/NODEJS/SDFTest.js +0 -88
- package/samples/StamperTest/NODEJS/RunTest.sh +0 -2
- package/samples/StamperTest/NODEJS/StamperTest.js +0 -256
- package/samples/TextExtractTest/NODEJS/RunTest.sh +0 -2
- package/samples/TextExtractTest/NODEJS/TextExtractTest.js +0 -287
- package/samples/TextSearchTest/NODEJS/RunTest.sh +0 -2
- package/samples/TextSearchTest/NODEJS/TextSearchTest.js +0 -122
- package/samples/U3DTest/NODEJS/RunTest.sh +0 -2
- package/samples/U3DTest/NODEJS/U3DTest.js +0 -105
- package/samples/UndoRedoTest/NODEJS/RunTest.sh +0 -2
- package/samples/UndoRedoTest/NODEJS/UndoRedoTest.js +0 -101
- package/samples/UnicodeWriteTest/NODEJS/RunTest.sh +0 -2
- package/samples/UnicodeWriteTest/NODEJS/UnicodeWriteTest.js +0 -174
- package/samples/WebViewerConvertTest/NODEJS/RunTest.sh +0 -2
- package/samples/WebViewerConvertTest/NODEJS/WebViewerConvertTest.js +0 -136
|
@@ -1,85 +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
|
-
|
|
11
|
-
exports.runPDFA = () => {
|
|
12
|
-
|
|
13
|
-
const printResults = async (pdfa, filename) => {
|
|
14
|
-
|
|
15
|
-
const errorCount = await pdfa.getErrorCount();
|
|
16
|
-
if (errorCount === 0) {
|
|
17
|
-
console.log(filename + ': OK.');
|
|
18
|
-
} else {
|
|
19
|
-
console.log(filename + ' is NOT a valid PDFA.');
|
|
20
|
-
for (let i = 0; i < errorCount; i++) {
|
|
21
|
-
const errorCode = await pdfa.getError(i);
|
|
22
|
-
const errorMsg = await PDFNet.PDFACompliance.getPDFAErrorMessage(errorCode);
|
|
23
|
-
console.log(' - e_PDFA ' + errorCode + ': ' + errorMsg + '.');
|
|
24
|
-
const numRefs = await pdfa.getRefObjCount(errorCode);
|
|
25
|
-
if (numRefs > 0) {
|
|
26
|
-
const objs = [];
|
|
27
|
-
for (let j = 0; j < numRefs; j++) {
|
|
28
|
-
const objRef = await pdfa.getRefObj(errorCode, j);
|
|
29
|
-
objs.push(objRef);
|
|
30
|
-
}
|
|
31
|
-
console.log(' Objects: ' + objs.join(', '));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
console.log('');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//---------------------------------------------------------------------------------------
|
|
39
|
-
// The following sample illustrates how to parse and check if a PDF document meets the
|
|
40
|
-
// PDFA standard, using the PDFACompliance class object.
|
|
41
|
-
//---------------------------------------------------------------------------------------
|
|
42
|
-
const main = async () => {
|
|
43
|
-
const inputPath = '../../TestFiles/';
|
|
44
|
-
const outputPath = inputPath + 'Output/';
|
|
45
|
-
await PDFNet.setColorManagement(); // Enable color management (required for PDFA validation).
|
|
46
|
-
|
|
47
|
-
//-----------------------------------------------------------
|
|
48
|
-
// Example 1: PDF/A Validation
|
|
49
|
-
//-----------------------------------------------------------
|
|
50
|
-
try {
|
|
51
|
-
const filename = 'newsletter.pdf';
|
|
52
|
-
/* The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number
|
|
53
|
-
of object numbers that are collected for particular error codes. The default value is 10
|
|
54
|
-
in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs. */
|
|
55
|
-
const pdfa = await PDFNet.PDFACompliance.createFromFile(false, inputPath + filename, '', PDFNet.PDFACompliance.Conformance.e_Level2B);
|
|
56
|
-
await printResults(pdfa, filename);
|
|
57
|
-
} catch (err) {
|
|
58
|
-
console.log(err);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
//-----------------------------------------------------------
|
|
62
|
-
// Example 2: PDF/A Conversion
|
|
63
|
-
//-----------------------------------------------------------
|
|
64
|
-
try {
|
|
65
|
-
let filename = 'fish.pdf';
|
|
66
|
-
const pdfa = await PDFNet.PDFACompliance.createFromFile(true, inputPath + filename, '', PDFNet.PDFACompliance.Conformance.e_Level2B);
|
|
67
|
-
filename = 'pdfa.pdf';
|
|
68
|
-
await pdfa.saveAsFromFileName(outputPath + filename);
|
|
69
|
-
|
|
70
|
-
// Re-validate the document after the conversion...
|
|
71
|
-
const comp = await PDFNet.PDFACompliance.createFromFile(false, outputPath + filename, '', PDFNet.PDFACompliance.Conformance.e_Level2B);
|
|
72
|
-
await printResults(comp, filename);
|
|
73
|
-
} catch (err) {
|
|
74
|
-
console.log(err);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
console.log('PDFACompliance test completed.')
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
81
|
-
};
|
|
82
|
-
exports.runPDFA();
|
|
83
|
-
})(exports);
|
|
84
|
-
// eslint-disable-next-line spaced-comment
|
|
85
|
-
//# sourceURL=PDFATest.js
|
|
@@ -1,85 +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 fs = require('fs');
|
|
7
|
-
const { PDFNet } = require('../../../lib/pdfnet.js');
|
|
8
|
-
const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
|
|
9
|
-
|
|
10
|
-
((exports) => {
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
exports.runPDFDocMemoryTest = () => {
|
|
14
|
-
const main = async () => {
|
|
15
|
-
const outputPath = '../../TestFiles/Output/';
|
|
16
|
-
|
|
17
|
-
// The following sample illustrates how to read/write a PDF document from/to
|
|
18
|
-
// a memory buffer. This is useful for applications that work with dynamic PDF
|
|
19
|
-
// documents that don't need to be saved/read from a disk.
|
|
20
|
-
try {
|
|
21
|
-
// Read a PDF document in a memory buffer.
|
|
22
|
-
const file = await PDFNet.Filter.createMappedFileFromUString('../../TestFiles/tiger.pdf');
|
|
23
|
-
const file_sz = await file.mappedFileFileSize();
|
|
24
|
-
|
|
25
|
-
const file_reader = await PDFNet.FilterReader.create(file);
|
|
26
|
-
|
|
27
|
-
const mem = await file_reader.read(file_sz);
|
|
28
|
-
const doc = await PDFNet.PDFDoc.createFromBuffer(mem);
|
|
29
|
-
|
|
30
|
-
doc.initSecurityHandler();
|
|
31
|
-
const num_pages = await doc.getPageCount();
|
|
32
|
-
|
|
33
|
-
const writer = await PDFNet.ElementWriter.create();
|
|
34
|
-
const reader = await PDFNet.ElementReader.create();
|
|
35
|
-
|
|
36
|
-
// Create a duplicate of every page but copy only path objects
|
|
37
|
-
for (let i = 1; i <= num_pages; ++i) {
|
|
38
|
-
const itr = await doc.getPageIterator(2 * i - 1);
|
|
39
|
-
|
|
40
|
-
const cur_page = await itr.current();
|
|
41
|
-
reader.beginOnPage(cur_page);
|
|
42
|
-
const new_page = await doc.pageCreate(await cur_page.getMediaBox());
|
|
43
|
-
itr.next();
|
|
44
|
-
doc.pageInsert(itr, new_page);
|
|
45
|
-
|
|
46
|
-
writer.beginOnPage(new_page);
|
|
47
|
-
var element;
|
|
48
|
-
while (element = await reader.next()) { // Read page contents
|
|
49
|
-
writer.writeElement(element);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
await writer.end();
|
|
53
|
-
await reader.end();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
doc.save(outputPath + 'doc_memory_edit.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
|
|
57
|
-
|
|
58
|
-
// Save the document to a memory buffer.
|
|
59
|
-
const docbuf = await doc.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_remove_unused);
|
|
60
|
-
|
|
61
|
-
// Write the contents of the buffer to the disk
|
|
62
|
-
fs.appendFileSync(outputPath + 'doc_memory_edit.txt', docbuf);
|
|
63
|
-
|
|
64
|
-
let dataStr = ''
|
|
65
|
-
// Read some data from the file stored in memory
|
|
66
|
-
reader.beginOnPage(await doc.getPage(1));
|
|
67
|
-
while (element = await reader.next()) {
|
|
68
|
-
if (await element.getType() == PDFNet.Element.Type.e_path) dataStr += 'Path, ';
|
|
69
|
-
}
|
|
70
|
-
reader.end();
|
|
71
|
-
console.log(dataStr);
|
|
72
|
-
|
|
73
|
-
console.log('\nDone. Result saved in doc_memory_edit.pdf and doc_memory_edit.txt ...');
|
|
74
|
-
} catch (err) {
|
|
75
|
-
console.log(err);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
|
|
79
|
-
console.log('Error: ' + JSON.stringify(error));
|
|
80
|
-
}).then(function(){ return PDFNet.shutdown(); });
|
|
81
|
-
};
|
|
82
|
-
exports.runPDFDocMemoryTest();
|
|
83
|
-
})(exports);
|
|
84
|
-
// eslint-disable-next-line spaced-comment
|
|
85
|
-
//# sourceURL=PDFDocMemoryTest.js
|
|
@@ -1,306 +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 following sample illustrates how to convert PDF documents to various raster image
|
|
8
|
-
// formats (such as PNG, JPEG, BMP, TIFF, etc), as well as how to convert a PDF page to
|
|
9
|
-
// GDI+ Bitmap for further manipulation and/or display in WinForms applications.
|
|
10
|
-
//---------------------------------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
const { PDFNet } = require('../../../lib/pdfnet.js');
|
|
14
|
-
const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
|
|
15
|
-
|
|
16
|
-
((exports) => {
|
|
17
|
-
|
|
18
|
-
exports.runPDFDrawTest = () => {
|
|
19
|
-
|
|
20
|
-
const main = async () => {
|
|
21
|
-
// Relative path to the folder containing test files.
|
|
22
|
-
const inputPath = '../../TestFiles/';
|
|
23
|
-
const outputPath = inputPath + 'Output/';
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
|
|
27
|
-
// Optional: Set ICC color profiles to fine tune color conversion
|
|
28
|
-
// for PDF 'device' color spaces...
|
|
29
|
-
|
|
30
|
-
// PDFNet.setResourcesPath('../../resources');
|
|
31
|
-
// PDFNet.setColorManagement(PDFNet.CMSType.e_lcms);
|
|
32
|
-
// PDFNet.setDefaultDeviceCMYKProfile('D:/Misc/ICC/USWebCoatedSWOP.icc');
|
|
33
|
-
// PDFNet.setDefaultDeviceRGBProfile('AdobeRGB1998.icc'); // will search in PDFNet resource folder.
|
|
34
|
-
|
|
35
|
-
// ----------------------------------------------------
|
|
36
|
-
// Optional: Set predefined font mappings to override default font
|
|
37
|
-
// substitution for documents with missing fonts...
|
|
38
|
-
|
|
39
|
-
// PDFNet.addFontSubst('StoneSans-Semibold', 'C:/WINDOWS/Fonts/comic.ttf');
|
|
40
|
-
// PDFNet.addFontSubst('StoneSans', 'comic.ttf'); // search for 'comic.ttf' in PDFNet resource folder.
|
|
41
|
-
// PDFNet.addFontSubst(PDFNet.CharacterOrdering.e_Identity, 'C:/WINDOWS/Fonts/arialuni.ttf');
|
|
42
|
-
// PDFNet.addFontSubst(PDFNet.CharacterOrdering.e_Japan1, 'C:/Program Files/Adobe/Acrobat 7.0/Resource/CIDFont/KozMinProVI-Regular.otf');
|
|
43
|
-
// PDFNet.addFontSubst(PDFNet.CharacterOrdering.e_Japan2, 'c:/myfonts/KozMinProVI-Regular.otf');
|
|
44
|
-
// PDFNet.addFontSubst(PDFNet.CharacterOrdering.e_Korea1, 'AdobeMyungjoStd-Medium.otf');
|
|
45
|
-
// PDFNet.addFontSubst(PDFNet.CharacterOrdering.e_CNS1, 'AdobeSongStd-Light.otf');
|
|
46
|
-
// PDFNet.addFontSubst(PDFNet.CharacterOrdering.e_GB1, 'AdobeMingStd-Light.otf');
|
|
47
|
-
|
|
48
|
-
const draw = await PDFNet.PDFDraw.create(); // PDFDraw class is used to rasterize PDF pages.
|
|
49
|
-
|
|
50
|
-
//--------------------------------------------------------------------------------
|
|
51
|
-
// Example 1) Convert the first page to PNG and TIFF at 92 DPI.
|
|
52
|
-
// A three step tutorial to convert PDF page to an image.
|
|
53
|
-
try {
|
|
54
|
-
// A) Open the PDF document.
|
|
55
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'tiger.pdf');
|
|
56
|
-
|
|
57
|
-
// Initialize the security handler, in case the PDF is encrypted.
|
|
58
|
-
doc.initSecurityHandler();
|
|
59
|
-
|
|
60
|
-
// B) The output resolution is set to 92 DPI.
|
|
61
|
-
draw.setDPI(92);
|
|
62
|
-
|
|
63
|
-
const firstPage = await (await doc.getPageIterator()).current();
|
|
64
|
-
// C) Rasterize the first page in the document and save the result as PNG.
|
|
65
|
-
await draw.export(firstPage, outputPath + 'tiger_92dpi.png');
|
|
66
|
-
|
|
67
|
-
console.log('Example 1: tiger_92dpi.png');
|
|
68
|
-
|
|
69
|
-
// Export the same page as TIFF
|
|
70
|
-
await draw.export(firstPage, outputPath + 'tiger_92dpi.tif', 'TIFF');
|
|
71
|
-
} catch (err) {
|
|
72
|
-
console.log(err);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
//--------------------------------------------------------------------------------
|
|
76
|
-
// Example 2) Convert the all pages in a given document to JPEG at 72 DPI.
|
|
77
|
-
console.log('Example 2:');
|
|
78
|
-
const hint_set = await PDFNet.ObjSet.create(); // A collection of rendering 'hits'.
|
|
79
|
-
try {
|
|
80
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
|
|
81
|
-
// Initialize the security handler, in case the PDF is encrypted.
|
|
82
|
-
doc.initSecurityHandler();
|
|
83
|
-
|
|
84
|
-
draw.setDPI(72); // Set the output resolution is to 72 DPI.
|
|
85
|
-
|
|
86
|
-
// Use optional encoder parameter to specify JPEG quality.
|
|
87
|
-
const encoderParam = await hint_set.createDict();
|
|
88
|
-
await encoderParam.putNumber('Quality', 80);
|
|
89
|
-
|
|
90
|
-
// Traverse all pages in the document.
|
|
91
|
-
for (const itr = await doc.getPageIterator(); await itr.hasNext(); await itr.next()) {
|
|
92
|
-
const currPage = await itr.current();
|
|
93
|
-
const currPageIdx = await currPage.getIndex();
|
|
94
|
-
const path = outputPath + 'newsletter' + currPageIdx + '.jpg';
|
|
95
|
-
console.log('newsletter' + currPageIdx + '.jpg');
|
|
96
|
-
|
|
97
|
-
await draw.export(currPage, path, 'JPEG', encoderParam);
|
|
98
|
-
}
|
|
99
|
-
console.log('Done.');
|
|
100
|
-
} catch (err) {
|
|
101
|
-
console.log(err);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Examples 3-6
|
|
105
|
-
try {
|
|
106
|
-
// Common code for remaining samples.
|
|
107
|
-
const tiger_doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'tiger.pdf');
|
|
108
|
-
// Initialize the security handler, in case the PDF is encrypted.
|
|
109
|
-
tiger_doc.initSecurityHandler();
|
|
110
|
-
const page = await tiger_doc.getPage(1);
|
|
111
|
-
|
|
112
|
-
//--------------------------------------------------------------------------------
|
|
113
|
-
// Example 3) Convert the first page to raw bitmap. Also, rotate the
|
|
114
|
-
// page 90 degrees and save the result as RAW.
|
|
115
|
-
draw.setDPI(100); // Set the output resolution is to 100 DPI.
|
|
116
|
-
draw.setRotate(PDFNet.Page.Rotate.e_90); // Rotate all pages 90 degrees clockwise.
|
|
117
|
-
|
|
118
|
-
const bitmapInfo = await draw.getBitmap(page, PDFNet.PDFDraw.PixelFormat.e_rgb, false);
|
|
119
|
-
const buf = Buffer.from(bitmapInfo.buf, 0, bitmapInfo.height * bitmapInfo.stride)
|
|
120
|
-
|
|
121
|
-
// Save the raw RGB data to disk.
|
|
122
|
-
fs.appendFileSync(outputPath + 'tiger_100dpi_rot90.raw', buf, 'binary');
|
|
123
|
-
|
|
124
|
-
console.log('Example 3: tiger_100dpi_rot90.raw');
|
|
125
|
-
draw.setRotate(PDFNet.Page.Rotate.e_0); // Disable image rotation for remaining samples.
|
|
126
|
-
|
|
127
|
-
//--------------------------------------------------------------------------------
|
|
128
|
-
// Example 4) Convert PDF page to a fixed image size. Also illustrates some
|
|
129
|
-
// other features in PDFDraw class such as rotation, image stretching, exporting
|
|
130
|
-
// to grayscale, or monochrome.
|
|
131
|
-
|
|
132
|
-
// Initialize render 'gray_hint' parameter, that is used to control the
|
|
133
|
-
// rendering process. In this case we tell the rasterizer to export the image as
|
|
134
|
-
// 1 Bit Per Component (BPC) image.
|
|
135
|
-
const mono_hint = await hint_set.createDict();
|
|
136
|
-
await mono_hint.putNumber('BPC', 1);
|
|
137
|
-
|
|
138
|
-
// SetImageSize can be used instead of SetDPI() to adjust page scaling
|
|
139
|
-
// dynamically so that given image fits into a buffer of given dimensions.
|
|
140
|
-
draw.setImageSize(1000, 1000); // Set the output image to be 1000 wide and 1000 pixels tall
|
|
141
|
-
draw.export(page, outputPath + 'tiger_1000x1000.png', 'PNG', mono_hint);
|
|
142
|
-
console.log('Example 4: tiger_1000x1000.png');
|
|
143
|
-
|
|
144
|
-
draw.setImageSize(200, 400); // Set the output image to be 200 wide and 300 pixels tall
|
|
145
|
-
draw.setRotate(PDFNet.Page.Rotate.e_180); // Rotate all pages 90 degrees clockwise.
|
|
146
|
-
|
|
147
|
-
// 'gray_hint' tells the rasterizer to export the image as grayscale.
|
|
148
|
-
const gray_hint = await hint_set.createDict();
|
|
149
|
-
await gray_hint.putName('ColorSpace', 'Gray');
|
|
150
|
-
|
|
151
|
-
await draw.export(page, outputPath + 'tiger_200x400_rot180.png', 'PNG', gray_hint);
|
|
152
|
-
console.log('Example 4: tiger_200x400_rot180.png');
|
|
153
|
-
|
|
154
|
-
draw.setImageSize(400, 200, false); // The third parameter sets 'preserve-aspect-ratio' to false.
|
|
155
|
-
draw.setRotate(PDFNet.Page.Rotate.e_0); // Disable image rotation.
|
|
156
|
-
await draw.export(page, outputPath + 'tiger_400x200_stretch.jpg', 'JPEG');
|
|
157
|
-
console.log('Example 4: tiger_400x200_stretch.jpg');
|
|
158
|
-
|
|
159
|
-
//--------------------------------------------------------------------------------
|
|
160
|
-
// Example 5) Zoom into a specific region of the page and rasterize the
|
|
161
|
-
// area at 200 DPI and as a thumbnail (i.e. a 50x50 pixel image).
|
|
162
|
-
const zoom_rect = await PDFNet.Rect.init(216, 522, 330, 600);
|
|
163
|
-
await page.setCropBox(zoom_rect); // Set the page crop box.
|
|
164
|
-
|
|
165
|
-
// Select the crop region to be used for drawing.
|
|
166
|
-
draw.setPageBox(PDFNet.Page.Box.e_crop);
|
|
167
|
-
draw.setDPI(900); // Set the output image resolution to 900 DPI.
|
|
168
|
-
await draw.export(page, outputPath + 'tiger_zoom_900dpi.png', 'PNG');
|
|
169
|
-
console.log('Example 5: tiger_zoom_900dpi.png');
|
|
170
|
-
|
|
171
|
-
// -------------------------------------------------------------------------------
|
|
172
|
-
// Example 6)
|
|
173
|
-
draw.setImageSize(50, 50); // Set the thumbnail to be 50x50 pixel image.
|
|
174
|
-
await draw.export(page, outputPath + 'tiger_zoom_50x50.png', 'PNG');
|
|
175
|
-
console.log('Example 6: tiger_zoom_50x50.png');
|
|
176
|
-
} catch (err) {
|
|
177
|
-
console.log(err);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
//--------------------------------------------------------------------------------
|
|
181
|
-
// Example 7) Convert the first PDF page to CMYK TIFF at 92 DPI.
|
|
182
|
-
// A three step tutorial to convert PDF page to an image
|
|
183
|
-
try {
|
|
184
|
-
const cmyk_hint = await hint_set.createDict();
|
|
185
|
-
await cmyk_hint.putName('ColorSpace', 'CMYK');
|
|
186
|
-
// A) Open the PDF document.
|
|
187
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'tiger.pdf');
|
|
188
|
-
// Initialize the security handler, in case the PDF is encrypted.
|
|
189
|
-
doc.initSecurityHandler();
|
|
190
|
-
|
|
191
|
-
// B) The output resolution is set to 92 DPI.
|
|
192
|
-
draw.setDPI(92);
|
|
193
|
-
|
|
194
|
-
// C) Rasterize the first page in the document and save the result as TIFF.
|
|
195
|
-
const pg = await doc.getPage(1);
|
|
196
|
-
await draw.export(pg, outputPath + 'out1.tif', 'TIFF', cmyk_hint);
|
|
197
|
-
console.log('Example 7: out1.tif');
|
|
198
|
-
} catch (err) {
|
|
199
|
-
console.log(err);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
//--------------------------------------------------------------------------------
|
|
203
|
-
// Example 8) PDFRasterizer can be used for more complex rendering tasks, such as
|
|
204
|
-
// strip by strip or tiled document rendering. In particular, it is useful for
|
|
205
|
-
// cases where you cannot simply modify the page crop box (interactive viewing,
|
|
206
|
-
// parallel rendering). This example shows how you can rasterize the south-west
|
|
207
|
-
// quadrant of a page.
|
|
208
|
-
try {
|
|
209
|
-
// A) Open the PDF document.
|
|
210
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'tiger.pdf');
|
|
211
|
-
// Initialize the security handler, in case the PDF is encrypted.
|
|
212
|
-
doc.initSecurityHandler();
|
|
213
|
-
|
|
214
|
-
// B) Get the page matrix
|
|
215
|
-
const pg = await doc.getPage(1);
|
|
216
|
-
const box = PDFNet.Page.Rotate.e_crop;
|
|
217
|
-
let mtx = await pg.getDefaultMatrix(true, box);
|
|
218
|
-
// We want to render a quadrant, so use half of width and height
|
|
219
|
-
const pg_w = await pg.getPageWidth(box) / 2;
|
|
220
|
-
const pg_h = await pg.getPageHeight(box) / 2;
|
|
221
|
-
|
|
222
|
-
// C) Scale matrix from PDF space to buffer space
|
|
223
|
-
const dpi = 96.0;
|
|
224
|
-
const scale = dpi / 72.0; // PDF space is 72 dpi
|
|
225
|
-
const buf_w = Math.floor(scale * pg_w);
|
|
226
|
-
const buf_h = Math.floor(scale * pg_h);
|
|
227
|
-
const bytes_per_pixel = 4; // BGRA buffer
|
|
228
|
-
await mtx.translate(0, -pg_h); // translate by '-pg_h' since we want south-west quadrant
|
|
229
|
-
const scale_mtx = await PDFNet.Matrix2D.create(scale, 0, 0, scale, 0, 0);
|
|
230
|
-
await scale_mtx.multiply(mtx);
|
|
231
|
-
mtx = scale_mtx;
|
|
232
|
-
|
|
233
|
-
// D) Rasterize page into memory buffer, according to our parameters
|
|
234
|
-
const rast = await PDFNet.PDFRasterizer.create();
|
|
235
|
-
const buf = await rast.rasterize(pg, buf_w, buf_h, buf_w * bytes_per_pixel, bytes_per_pixel, true, mtx);
|
|
236
|
-
|
|
237
|
-
// buf now contains raw BGRA bitmap.
|
|
238
|
-
console.log('Example 8: Successfully rasterized into memory buffer.');
|
|
239
|
-
} catch (err) {
|
|
240
|
-
console.log(err);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
//--------------------------------------------------------------------------------
|
|
244
|
-
// Example 9) Export raster content to PNG using different image smoothing settings.
|
|
245
|
-
try {
|
|
246
|
-
const text_doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'lorem_ipsum.pdf');
|
|
247
|
-
text_doc.initSecurityHandler();
|
|
248
|
-
const itr = await text_doc.getPageIterator();
|
|
249
|
-
const page = await itr.current();
|
|
250
|
-
|
|
251
|
-
draw.setImageSmoothing(false, false);
|
|
252
|
-
let filename = 'raster_text_no_smoothing.png';
|
|
253
|
-
await draw.export(page, outputPath + filename);
|
|
254
|
-
console.log('Example 9 a): ' + filename + '. Done.');
|
|
255
|
-
|
|
256
|
-
filename = 'raster_text_smoothed.png';
|
|
257
|
-
draw.setImageSmoothing(true, false /*default quality bilinear resampling*/);
|
|
258
|
-
await draw.export(page, outputPath + filename);
|
|
259
|
-
console.log('Example 9 b): ' + filename + '. Done.');
|
|
260
|
-
|
|
261
|
-
filename = 'raster_text_high_quality.png';
|
|
262
|
-
draw.setImageSmoothing(true, true /*high quality area resampling*/);
|
|
263
|
-
await draw.export(page, outputPath + filename);
|
|
264
|
-
console.log('Example 9 c): ' + filename + '. Done.');
|
|
265
|
-
} catch (err) {
|
|
266
|
-
console.log(err);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
//--------------------------------------------------------------------------------
|
|
270
|
-
// Example 10) Export separations directly, without conversion to an output colorspace
|
|
271
|
-
try {
|
|
272
|
-
const separation_doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'op_blend_test.pdf');
|
|
273
|
-
separation_doc.initSecurityHandler();
|
|
274
|
-
const separation_hint = await hint_set.createDict();
|
|
275
|
-
await separation_hint.putName('ColorSpace', 'Separation');
|
|
276
|
-
draw.setDPI(96);
|
|
277
|
-
draw.setImageSmoothing(true, true);
|
|
278
|
-
draw.setOverprint(PDFNet.PDFRasterizer.OverprintPreviewMode.e_op_on);
|
|
279
|
-
|
|
280
|
-
const itr = await separation_doc.getPageIterator();
|
|
281
|
-
const page = await itr.current();
|
|
282
|
-
let filename = 'merged_separations.png';
|
|
283
|
-
await draw.export(page, outputPath + filename, 'PNG');
|
|
284
|
-
console.log('Example 10 a): ' + filename + '. Done.');
|
|
285
|
-
|
|
286
|
-
filename = 'separation';
|
|
287
|
-
await draw.export(page, outputPath + filename, 'PNG', separation_hint);
|
|
288
|
-
console.log('Example 10 b): ' + filename + '_[ink].png. Done.');
|
|
289
|
-
|
|
290
|
-
filename = 'separation_NChannel.tif';
|
|
291
|
-
await draw.export(page, outputPath + filename, 'TIFF', separation_hint);
|
|
292
|
-
console.log('Example 10 c): ' + filename + '. Done.');
|
|
293
|
-
} catch (err) {
|
|
294
|
-
console.log(err);
|
|
295
|
-
}
|
|
296
|
-
} catch (err) {
|
|
297
|
-
console.log(err);
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
302
|
-
};
|
|
303
|
-
exports.runPDFDrawTest();
|
|
304
|
-
})(exports);
|
|
305
|
-
// eslint-disable-next-line spaced-comment
|
|
306
|
-
//# sourceURL=PDFDrawTest.js
|