1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5(exports => {
6 exports.runPDFA = () => {
7 const PDFNet = exports.Core.PDFNet;
8
9 const main = async () => {
10 try {
11 console.log('PDFA validation test begins.');
12
13 const inputURL = '../TestFiles/';
14 const inputFilename = 'newsletter.pdf';
15
16 const convert = false;
17 const pwd = '';
18 let exceptions;
19 const maxRefObjs = 10;
20 const firstStop = false;
21 const url = inputURL + inputFilename;
22
23 const pdfa = await PDFNet.PDFACompliance.createFromUrl(convert, url, pwd, PDFNet.PDFACompliance.Conformance.e_Level1B, exceptions, maxRefObjs, firstStop);
24
25 const errorCount = await pdfa.getErrorCount();
26 if (errorCount === 0) {
27 console.log(inputFilename + ' is a valid PDFA.');
28 } else {
29 console.log(inputFilename + ' is NOT a valid PDFA.');
30 for (let i = 0; i < errorCount; i++) {
31 const errorCode = await pdfa.getError(i);
32 const errorMsg = await PDFNet.PDFACompliance.getPDFAErrorMessage(errorCode);
33 const numRefs = await pdfa.getRefObjCount(errorCode);
34 if (numRefs > 0) {
35 const objs = [];
36 for (let j = 0; j < numRefs; j++) {
37 const objRef = await pdfa.getRefObj(errorCode, j);
38 objs.push(objRef);
39 }
40 console.log('Error:' + errorMsg + '. Objects:' + objs.toString());
41 }
42 }
43 }
44 } catch (err) {
45 console.log(err);
46 }
47 try {
48 console.log('PDFA conversion test begins.');
49
50 const inputURL = '../TestFiles/';
51 const inputFilename = 'fish.pdf';
52 const outputFilename = 'fish_pdfa.pdf';
53
54 const convert = true;
55 const pwd = '';
56 let exceptions;
57 const maxRefObjs = 10;
58 const urlInput = inputURL + inputFilename;
59
60 console.log('Converting input document: ' + inputFilename);
61 const pdfa = await PDFNet.PDFACompliance.createFromUrl(convert, urlInput, pwd, PDFNet.PDFACompliance.Conformance.e_Level1B, exceptions, maxRefObjs);
62
63 const errorCount = await pdfa.getErrorCount();
64 if (errorCount === 0) {
65 console.log(inputFilename + ' is a valid PDFA.');
66 } else {
67 console.log(inputFilename + ' is NOT a valid PDFA.');
68 }
69
70 console.log('Save and validate the converted document: ' + outputFilename);
71 const linearize = true;
72 const docBuffer = await pdfa.saveAsFromBuffer(linearize);
73 saveBufferAsPDFDoc(docBuffer, outputFilename);
74 const validateOnly = false;
75 const pdfaValidate = await PDFNet.PDFACompliance.createFromBuffer(validateOnly, docBuffer, pwd, PDFNet.PDFACompliance.Conformance.e_Level1B, exceptions, maxRefObjs);
76 const errorCountValidate = await pdfaValidate.getErrorCount();
77 if (errorCountValidate === 0) {
78 console.log(outputFilename + ' is a valid PDFA.');
79 } else {
80 console.log(outputFilename + ' is NOT a valid PDFA.');
81 }
82 } catch (err) {
83 console.log(err);
84 }
85 };
86
87 // add your own license key as the second parameter, e.g. PDFNet.runWithCleanup(main, 'YOUR_LICENSE_KEY')
88 PDFNet.runWithCleanup(main);
89 };
90})(window);
91// eslint-disable-next-line spaced-comment
92//# sourceURL=PDFATest.js