Sample C# code for using Apryse SDK to programmatically convert generic PDF documents into ISO-compliant, VeraPDF-valid PDF/A files, or to validate PDF/A compliance. Supports all three PDF/A parts (PDF/A-1, PDF/A-2, PDF/A-3), and covers all conformance levels (A, B, U). Learn more about our Server SDK and PDF/A Library. A command-line tool for batch conversion and validation is also available.
1//
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3//
4
5using System;
6using pdftron;
7using pdftron.SDF;
8using pdftron.PDF;
9using pdftron.PDF.PDFA;
10
11//-----------------------------------------------------------------------------------
12// The sample illustrates how to use PDF/A related API-s.
13//-----------------------------------------------------------------------------------
14namespace PDFATestCS
15{
16 class Class1
17 {
18 private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
19 static Class1() {}
20
21 // Relative path to the folder containing test files.
22 static string input_path = "../../../../TestFiles/";
23 static string output_path = "../../../../TestFiles/Output/";
24
25 /// <summary>
26 /// The main entry point for the application.
27 /// </summary>
28 [STAThread]
29 static void Main(string[] args)
30 {
31 PDFNet.Initialize(PDFTronLicense.Key);
32 PDFNet.SetColorManagement(PDFNet.CMSType.e_lcms); // Required for PDFA validation.
33
34 //-----------------------------------------------------------
35 // Example 1: PDF/A Validation
36 //-----------------------------------------------------------
37 try
38 {
39 string filename = "newsletter.pdf";
40 using (PDFACompliance pdf_a = new PDFACompliance(false, input_path+filename, null, PDFACompliance.Conformance.e_Level2B, null, 10, false))
41 {
42 PrintResults(pdf_a, filename);
43 }
44 }
45 catch (pdftron.Common.PDFNetException e)
46 {
47 Console.WriteLine(e.Message);
48 }
49
50 //-----------------------------------------------------------
51 // Example 2: PDF/A Conversion
52 //-----------------------------------------------------------
53 try
54 {
55 string filename = "fish.pdf";
56 using (PDFACompliance pdf_a = new PDFACompliance(true, input_path+filename, null, PDFACompliance.Conformance.e_Level2B, null, 10, false))
57 {
58 filename = "pdfa.pdf";
59 pdf_a.SaveAs(output_path + filename, false);
60 }
61
62 // Re-validate the document after the conversion...
63 filename = "pdfa.pdf";
64 using (PDFACompliance pdf_a = new PDFACompliance(false, output_path + filename, null, PDFACompliance.Conformance.e_Level2B, null, 10, false))
65 {
66 PrintResults(pdf_a, filename);
67 }
68 }
69 catch (pdftron.Common.PDFNetException e)
70 {
71 Console.WriteLine(e.Message);
72 }
73 PDFNet.Terminate();
74 Console.WriteLine("PDFACompliance test completed.");
75
76 }
77
78 static void PrintResults(PDFACompliance pdf_a, String filename)
79 {
80 int err_cnt = pdf_a.GetErrorCount();
81 if (err_cnt == 0)
82 {
83 Console.WriteLine("{0}: OK.", filename);
84 }
85 else
86 {
87 Console.WriteLine("{0} is NOT a valid PDFA.", filename);
88 for (int i=0; i<err_cnt; ++i)
89 {
90 PDFACompliance.ErrorCode c = pdf_a.GetError(i);
91 Console.WriteLine(" - e_PDFA {0}: {1}.",
92 (int)c, PDFACompliance.GetPDFAErrorMessage(c));
93
94 if (true)
95 {
96 int num_refs = pdf_a.GetRefObjCount(c);
97 if (num_refs > 0)
98 {
99 Console.Write(" Objects: ");
100 for (int j=0; j<num_refs; )
101 {
102 Console.Write("{0}", pdf_a.GetRefObj(c, j));
103 if (++j!=num_refs) Console.Write(", ");
104 }
105 Console.WriteLine();
106 }
107 }
108 }
109 Console.WriteLine();
110 }
111 }
112 }
113}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3// Consult LICENSE.txt regarding license information.
4//---------------------------------------------------------------------------------------
5
6package main
7import (
8 "fmt"
9 "strconv"
10 . "pdftron"
11)
12
13import "pdftron/Samples/LicenseKey/GO"
14
15//---------------------------------------------------------------------------------------
16// The following sample illustrates how to parse and check if a PDF document meets the
17// PDFA standard, using the PDFACompliance class object.
18//---------------------------------------------------------------------------------------
19
20func PrintResults(pdfa PDFACompliance, filename string){
21 errCnt := pdfa.GetErrorCount()
22 if errCnt == 0{
23 fmt.Println(filename + ": OK.")
24 }else{
25 fmt.Println(filename + " is NOT a valid PDFA.")
26 i := int64(0)
27 for i < errCnt{
28 c := pdfa.GetError(i)
29 str1 := " - e_PDFA " + strconv.Itoa(int(c)) + ": " + PDFAComplianceGetPDFAErrorMessage(c) + "."
30 if true{
31 num_refs := pdfa.GetRefObjCount(c)
32 if num_refs > int64(0){
33 str1 = str1 + "\n Objects: "
34 j := int64(0)
35 for j < num_refs{
36 str1 = str1 + strconv.Itoa(int(pdfa.GetRefObj(c, j)))
37 if j < num_refs-1{
38 str1 = str1 + ", "
39 }
40 j = j + 1
41 }
42 }
43 }
44 fmt.Println(str1)
45 i = i + 1
46 }
47 fmt.Println("")
48 }
49}
50
51func main(){
52 // Relative path to the folder containing the test files.
53 inputPath := "../../TestFiles/"
54 outputPath := "../../TestFiles/Output/"
55
56 PDFNetInitialize(PDFTronLicense.Key)
57 PDFNetSetColorManagement() // Enable color management (required for PDFA validation).
58
59 //-----------------------------------------------------------
60 // Example 1: PDF/A Validation
61 //-----------------------------------------------------------
62 filename := "newsletter.pdf"
63 var cErrorCode PdftronPDFPDFAPDFAComplianceErrorCode
64 // The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number
65 // of object numbers that are collected for particular error codes. The default value is 10
66 // in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs.
67 pdfa := NewPDFACompliance(false, inputPath + filename, "", PDFAComplianceE_Level2B, &cErrorCode, 0, 10)
68 PrintResults(pdfa, filename)
69 pdfa.Destroy()
70
71 //-----------------------------------------------------------
72 // Example 2: PDF/A Conversion
73 //-----------------------------------------------------------
74 filename = "fish.pdf"
75 pdfa = NewPDFACompliance(true, inputPath + filename, "", PDFAComplianceE_Level2B, &cErrorCode, 0, 10)
76 filename = "pdfa.pdf"
77 pdfa.SaveAs(outputPath + filename, false)
78 pdfa.Destroy()
79
80 // Re-validate the document after the conversion...
81 pdfa = NewPDFACompliance(false, outputPath + filename, "", PDFAComplianceE_Level2B, &cErrorCode, 0, 10)
82 PrintResults(pdfa, filename)
83 pdfa.Destroy()
84
85 PDFNetTerminate()
86 fmt.Println("PDFACompliance test completed.")
87}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6import com.pdftron.common.PDFNetException;
7import com.pdftron.pdf.*;
8import com.pdftron.pdf.pdfa.*;
9
10public class PDFATest {
11
12 // Relative path to the folder containing test files.
13 public static final String input_path = "../../TestFiles/";
14 public static final String output_path = "../../TestFiles/Output/";
15
16 public static void main(String[] args) {
17 try{
18 PDFNet.initialize(PDFTronLicense.Key());
19 PDFNet.setColorManagement(PDFNet.e_lcms); // Required for proper PDF/A validation and conversion.
20
21 //-----------------------------------------------------------
22 // Example 1: PDF/A Validation
23 //-----------------------------------------------------------
24
25 String filename = "newsletter.pdf";
26 /* The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number
27 of object numbers that are collected for particular error codes. The default value is 10
28 in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs. */
29 PDFACompliance pdf_a = new PDFACompliance(false, input_path + filename, null, PDFACompliance.e_Level2B, null, 10);
30 printResults(pdf_a, filename);
31 pdf_a.destroy();
32 } catch (PDFNetException e) {
33 System.out.println(e.getMessage());
34 }
35
36
37
38 //-----------------------------------------------------------
39 // Example 2: PDF/A Conversion
40 //-----------------------------------------------------------
41 try {
42 String filename = "fish.pdf";
43 PDFACompliance pdf_a = new PDFACompliance(true, input_path + filename, null, PDFACompliance.e_Level2B, null, 10);
44 filename = "pdfa.pdf";
45 pdf_a.saveAs(output_path + filename, false);
46 pdf_a.destroy();
47 // output "pdf_a.pdf"
48
49 // Re-validate the document after the conversion...
50 pdf_a = new PDFACompliance(false, output_path + filename, null, PDFACompliance.e_Level2B, null, 10);
51 printResults(pdf_a, filename);
52 pdf_a.destroy();
53
54 PDFNet.terminate();
55 } catch (PDFNetException e) {
56 System.out.println(e.getMessage());
57 }
58
59 System.out.println("PDFACompliance test completed.");
60 }
61
62 static void printResults(PDFACompliance pdf_a, String filename) {
63 try {
64 int err_cnt = pdf_a.getErrorCount();
65 System.out.print(filename);
66 if (err_cnt == 0) {
67 System.out.print(": OK.\n");
68 } else {
69 System.out.println(" is NOT a valid PDFA.");
70 for (int i = 0; i < err_cnt; ++i) {
71 int c = pdf_a.getError(i);
72 System.out.println(" - e_PDFA " + c + ": " + PDFACompliance.getPDFAErrorMessage(c) + ".");
73 if (true) {
74 int num_refs = pdf_a.getRefObjCount(c);
75 if (num_refs > 0) {
76 System.out.print(" Objects: ");
77 for (int j = 0; j < num_refs; ) {
78 System.out.print(String.valueOf(pdf_a.getRefObj(c, j)));
79 if (++j != num_refs) System.out.print(", ");
80 }
81 System.out.println();
82 }
83 }
84 }
85 System.out.println();
86 }
87 } catch (PDFNetException e) {
88 System.out.println(e.getMessage());
89 }
90 }
91
92}
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#include <PDF/PDFNet.h>
7//#include <PDF/PDFDoc.h>
8#include <PDF/PDFA/PDFACompliance.h>
9#include <string>
10#include <iostream>
11#include "../../LicenseKey/CPP/LicenseKey.h"
12
13using namespace std;
14using namespace pdftron;
15using namespace pdftron::PDF;
16using namespace pdftron::PDF::PDFA;
17
18void PrintResults(PDFACompliance& pdf_a, UString filename)
19{
20 int err_cnt = static_cast<int>(pdf_a.GetErrorCount());
21 if (err_cnt == 0)
22 {
23 cout << filename << ": OK.\n";
24 }
25 else
26 {
27 cout << filename << " is NOT a valid PDFA.\n";
28 for (int i=0; i<err_cnt; ++i)
29 {
30 PDFACompliance::ErrorCode c = pdf_a.GetError(i);
31 cout << " - e_PDFA " << c << ": " << PDFACompliance::GetPDFAErrorMessage(c) << ".\n";
32 if (true)
33 {
34 int num_refs = static_cast<int>(pdf_a.GetRefObjCount(c));
35 if (num_refs > 0)
36 {
37 cout << " Objects: ";
38 for (int j=0; j<num_refs; ++j)
39 {
40 cout << pdf_a.GetRefObj(c, j);
41 if (j<num_refs-1)
42 cout << ", ";
43 }
44 cout << endl;
45 }
46 }
47 }
48 cout << endl;
49 }
50}
51
52
53
54//---------------------------------------------------------------------------------------
55// The following sample illustrates how to parse and check if a PDF document meets the
56// PDFA standard, using the PDFACompliance class object.
57//---------------------------------------------------------------------------------------
58int main(int argc, char *argv[])
59{
60 int ret = 0;
61 UString input_path("../../TestFiles/");
62 UString output_path("../../TestFiles/Output/");
63 PDFNet::Initialize(LicenseKey);
64 PDFNet::SetColorManagement(); // Enable color management (required for PDFA validation).
65
66 //-----------------------------------------------------------
67 // Example 1: PDF/A Validation
68 //-----------------------------------------------------------
69 try
70 {
71 UString filename("newsletter.pdf");
72 /* The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number
73 of object numbers that are collected for particular error codes. The default value is 10
74 in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs. */
75 PDFACompliance pdf_a(false, input_path+filename, 0, PDFACompliance::e_Level2B, 0, 0, 10);
76 PrintResults(pdf_a, filename);
77 }
78 catch (Common::Exception& e)
79 {
80 cout << e << endl;
81 ret = 1;
82 }
83 catch (...) {
84 cout << "Unknown Exception" << endl;
85 ret = 1;
86 }
87
88 //-----------------------------------------------------------
89 // Example 2: PDF/A Conversion
90 //-----------------------------------------------------------
91 try
92 {
93 UString filename("fish.pdf");
94 PDFACompliance pdf_a(true, input_path+filename, 0, PDFACompliance::e_Level2B, 0, 0, 10);
95 filename = "pdfa.pdf";
96 pdf_a.SaveAs(output_path + filename);
97
98 // Re-validate the document after the conversion...
99 PDFACompliance comp(false, output_path + filename, 0, PDFACompliance::e_Level2B, 0, 0, 10);
100 PrintResults(comp, filename);
101 }
102 catch (Common::Exception& e)
103 {
104 cout << e << endl;
105 ret = 1;
106 }
107 catch (...) {
108 cout << "Unknown Exception" << endl;
109 ret = 1;
110 }
111
112 cout << "PDFACompliance test completed." << endl;
113 PDFNet::Terminate();
114 return ret;
115}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6const { PDFNet } = require('@pdftron/pdfnet-node');
7const PDFTronLicense = require('../LicenseKey/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<?php
2//---------------------------------------------------------------------------------------
3// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
4// Consult LICENSE.txt regarding license information.
5//---------------------------------------------------------------------------------------
6if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
7include("../../../PDFNetC/Lib/PDFNetPHP.php");
8include("../../LicenseKey/PHP/LicenseKey.php");
9
10//---------------------------------------------------------------------------------------
11// The following sample illustrates how to parse and check if a PDF document meets the
12// PDFA standard, using the PDFACompliance class object.
13//---------------------------------------------------------------------------------------
14
15
16function PrintResults($pdf_a, $filename)
17{
18 $err_cnt = $pdf_a->GetErrorCount();
19 if ($err_cnt == 0)
20 {
21 echo nl2br($filename.": OK.\n");
22 }
23 else
24 {
25 echo nl2br($filename." is NOT a valid PDFA.\n");
26 for ($i=0; $i<$err_cnt; ++$i)
27 {
28 $c = $pdf_a->GetError($i);
29 $str1 = " - e_PDFA ".$c.": ".PDFACompliance::GetPDFAErrorMessage($c).".";
30 if (true)
31 {
32 $num_refs = $pdf_a->GetRefObjCount($c);
33 if ($num_refs > 0)
34 {
35 $str1 = $str1."\n Objects: ";
36 for ($j=0; $j<$num_refs; ++$j)
37 {
38 $str1 = $str1.$pdf_a->GetRefObj($c, $j);
39 if ($j<$num_refs-1)
40 $str1 = $str1. ", ";
41 }
42 }
43 }
44 echo nl2br($str1."\n");
45 }
46 echo nl2br("\n");
47 }
48}
49
50 // Relative path to the folder containing the test files.
51 $input_path = getcwd()."/../../TestFiles/";
52 $output_path = getcwd()."/../../TestFiles/Output/";
53
54 PDFNet::Initialize($LicenseKey);
55 PDFNet::GetSystemFontList(); // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.
56 PDFNet::SetColorManagement(); // Enable color management (required for PDFA validation).
57
58 //-----------------------------------------------------------
59 // Example 1: PDF/A Validation
60 //-----------------------------------------------------------
61 $filename = "newsletter.pdf";
62 // The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number
63 // of object numbers that are collected for particular error codes. The default value is 10
64 // in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs.
65 $pdf_a = new PDFACompliance(false, $input_path.$filename, "", PDFACompliance::e_Level2B, 0, 0, 10);
66 PrintResults($pdf_a, $filename);
67 $pdf_a->Destroy();
68
69 //-----------------------------------------------------------
70 // Example 2: PDF/A Conversion
71 //-----------------------------------------------------------
72 $filename = "fish.pdf";
73
74 $pdf_a = new PDFACompliance(true, $input_path.$filename, "", PDFACompliance::e_Level2B, 0, 0, 10);
75 $filename = "pdfa.pdf";
76 $pdf_a->SaveAs($output_path.$filename, false);
77 $pdf_a->Destroy();
78
79 // Re-validate the document after the conversion...
80 $pdf_a = new PDFACompliance(false, $output_path.$filename, "", PDFACompliance::e_Level2B, 0, 0, 10);
81 PrintResults($pdf_a, $filename);
82 $pdf_a->Destroy();
83 PDFNet::Terminate();
84 echo nl2br("PDFACompliance test completed.\n");
85?>
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6import site
7site.addsitedir("../../../PDFNetC/Lib")
8import sys
9from PDFNetPython import *
10
11sys.path.append("../../LicenseKey/PYTHON")
12from LicenseKey import *
13
14#---------------------------------------------------------------------------------------
15# The following sample illustrates how to parse and check if a PDF document meets the
16# PDFA standard, using the PDFACompliance class object.
17#---------------------------------------------------------------------------------------
18
19def PrintResults(pdf_a, filename):
20 err_cnt = pdf_a.GetErrorCount()
21 if err_cnt == 0:
22 print(filename + ": OK.")
23 else:
24 print(filename + " is NOT a valid PDFA.")
25 i = 0
26 while i < err_cnt:
27 c = pdf_a.GetError(i)
28 str1 = " - e_PDFA " + str(c) + ": " + PDFACompliance.GetPDFAErrorMessage(c) + "."
29 if True:
30 num_refs = pdf_a.GetRefObjCount(c)
31 if num_refs > 0:
32 str1 = str1 + "\n Objects: "
33 j = 0
34 while j < num_refs:
35 str1 = str1 + str(pdf_a.GetRefObj(c, j))
36 if j < num_refs-1:
37 str1 = str1 + ", "
38 j = j + 1
39 print(str1)
40 i = i + 1
41 print('')
42
43def main():
44 # Relative path to the folder containing the test files.
45 input_path = "../../TestFiles/"
46 output_path = "../../TestFiles/Output/"
47
48 PDFNet.Initialize(LicenseKey)
49 PDFNet.SetColorManagement() # Enable color management (required for PDFA validation).
50
51 #-----------------------------------------------------------
52 # Example 1: PDF/A Validation
53 #-----------------------------------------------------------
54 filename = "newsletter.pdf"
55 # The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number
56 # of object numbers that are collected for particular error codes. The default value is 10
57 # in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs.
58 pdf_a = PDFACompliance(False, input_path+filename, None, PDFACompliance.e_Level2B, 0, 0, 10)
59 PrintResults(pdf_a, filename)
60 pdf_a.Destroy()
61
62 #-----------------------------------------------------------
63 # Example 2: PDF/A Conversion
64 #-----------------------------------------------------------
65 filename = "fish.pdf"
66 pdf_a = PDFACompliance(True, input_path + filename, None, PDFACompliance.e_Level2B, 0, 0, 10)
67 filename = "pdfa.pdf"
68 pdf_a.SaveAs(output_path + filename, False)
69 pdf_a.Destroy()
70
71 # Re-validate the document after the conversion...
72 pdf_a = PDFACompliance(False, output_path + filename, None, PDFACompliance.e_Level2B, 0, 0, 10)
73 PrintResults(pdf_a, filename)
74 pdf_a.Destroy()
75
76 PDFNet.Terminate()
77 print("PDFACompliance test completed.")
78
79if __name__ == '__main__':
80 main()
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6require '../../../PDFNetC/Lib/PDFNetRuby'
7include PDFNetRuby
8require '../../LicenseKey/RUBY/LicenseKey'
9
10$stdout.sync = true
11
12#---------------------------------------------------------------------------------------
13# The following sample illustrates how to parse and check if a PDF document meets the
14# PDFA standard, using the PDFACompliance class object.
15#---------------------------------------------------------------------------------------
16
17# Relative path to the folder containing the test files.
18input_path = "../../TestFiles/"
19output_path = "../../TestFiles/Output/"
20
21def PrintResults(pdf_a, filename)
22 err_cnt = pdf_a.GetErrorCount
23 if err_cnt == 0
24 puts filename + ": OK."
25 else
26 puts filename + " is NOT a valid PDFA."
27 i = 0
28 while i < err_cnt do
29 c = pdf_a.GetError(i)
30 str1 = " - e_PDFA " + c.to_s + ": " + PDFACompliance.GetPDFAErrorMessage(c) + "."
31 if true
32 num_refs = pdf_a.GetRefObjCount(c)
33 if num_refs > 0
34 str1 = str1 + "\n Objects: "
35 j = 0
36 while j < num_refs do
37 str1 = str1 + pdf_a.GetRefObj(c, j).to_s
38 if j < num_refs-1
39 str1 = str1 + ", "
40 end
41 j = j + 1
42 end
43 end
44 end
45 puts str1
46 i = i + 1
47 end
48 puts "\n"
49 end
50end
51
52 PDFNet.Initialize(PDFTronLicense.Key)
53 PDFNet.SetColorManagement # Enable color management (required for PDFA validation).
54
55 #-----------------------------------------------------------
56 # Example 1: PDF/A Validation
57 #-----------------------------------------------------------
58 filename = "newsletter.pdf"
59 # The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number
60 # of object numbers that are collected for particular error codes. The default value is 10
61 # in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs.
62 pdf_a = PDFACompliance.new(false, input_path+filename, nil, PDFACompliance::E_Level2B, 0, 0, 10)
63 PrintResults(pdf_a, filename)
64 pdf_a.Destroy
65
66 #-----------------------------------------------------------
67 # Example 2: PDF/A Conversion
68 #-----------------------------------------------------------
69 filename = "fish.pdf"
70 pdf_a = PDFACompliance.new(true, input_path + filename, nil, PDFACompliance::E_Level2B, 0, 0, 10)
71 filename = "pdfa.pdf"
72 pdf_a.SaveAs(output_path + filename, false)
73 pdf_a.Destroy
74
75 # Re-validate the document after the conversion...
76 pdf_a = PDFACompliance.new(false, output_path + filename, nil, PDFACompliance::E_Level2B, 0, 0, 10)
77 PrintResults(pdf_a, filename)
78 pdf_a.Destroy
79 PDFNet.Terminate
80 puts "PDFACompliance test completed."
1'---------------------------------------------------------------------------------------
2' Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3' Consult legal.txt regarding legal and license information.
4'---------------------------------------------------------------------------------------
5Imports System
6
7Imports PDFTRON
8Imports PDFTRON.PDF
9Imports PDFTRON.PDF.PDFA
10
11'-----------------------------------------------------------------------------------
12' The sample illustrates how to use PDF/A related API-s.
13'-----------------------------------------------------------------------------------
14
15Module mainModule
16 Dim pdfNetLoader As PDFNetLoader
17 Sub New()
18 pdfNetLoader = pdftron.PDFNetLoader.Instance()
19 End Sub
20
21 ' The main entry point for the application.
22 Sub Main()
23
24 PDFNet.Initialize(PDFTronLicense.Key)
25 PDFNet.SetColorManagement(PDFNet.CMSType.e_lcms) 'Required for PDFA validation.
26
27 'Relative path to the folder containing test files.
28 Dim input_path As String = "../../../../TestFiles/"
29 Dim filename As String = "newsletter.pdf"
30 Dim output_path As String = "../../../../TestFiles/Output/"
31
32
33 '//-----------------------------------------------------------
34 '// Example 1: PDF/A Validation
35 '//-----------------------------------------------------------
36 Try
37 filename = "newsletter.pdf"
38 Dim pdf_a As PDFACompliance = New PDFACompliance(False, input_path + filename, Nothing, PDFACompliance.Conformance.e_Level2B, Nothing, 10, False)
39 PrintResults(pdf_a, filename)
40 pdf_a.Dispose()
41 Catch e As PDFTRON.Common.PDFNetException
42 Console.WriteLine(e.Message)
43 End Try
44
45 '//-----------------------------------------------------------
46 '// Example 2: PDF/A Conversion
47 '//-----------------------------------------------------------
48 Try
49 filename = "fish.pdf"
50 Using pdf_a As PDFACompliance = New PDFACompliance(True, input_path + filename, Nothing, PDFACompliance.Conformance.e_Level2B, Nothing, 10, False)
51 filename = "pdfa.pdf"
52 pdf_a.SaveAs(output_path + filename, False)
53 End Using
54
55 '// Re-validate the document after the conversion...
56 filename = "pdfa.pdf"
57 Using pdf_a As PDFACompliance = New PDFACompliance(False, output_path + filename, Nothing, PDFACompliance.Conformance.e_Level2B, Nothing, 10, False)
58 PrintResults(pdf_a, filename)
59 End Using
60 Catch e As pdftron.Common.PDFNetException
61 Console.WriteLine(e.Message)
62 End Try
63 PDFNet.Terminate()
64 Console.WriteLine("PDFACompliance test completed.")
65 End Sub
66
67 Function PrintResults(ByRef pdf_a As PDFACompliance, ByVal filename As String) As Int32
68 PrintResults = 0
69 Dim err_cnt As Int32 = pdf_a.GetErrorCount()
70 If err_cnt = 0 Then
71 Console.WriteLine("{0}: OK.", filename)
72 Else
73 Dim i As Int32
74 Console.WriteLine("{0} is NOT a valid PDFA.", filename)
75 For i = 0 To err_cnt - 1 Step 1
76 Dim c As PDFACompliance.ErrorCode = pdf_a.GetError(i)
77 Console.WriteLine(" - e_PDFA {0}: {1}.", Int(c), PDFACompliance.GetPDFAErrorMessage(c))
78 If True Then
79 Dim num_refs As Int32 = pdf_a.GetRefObjCount(c)
80 If num_refs > 0 Then
81 Console.Write(" Objects: ")
82 Dim j As Int32
83 For j = 0 To num_refs - 1 Step 1
84 Console.Write("{0}", pdf_a.GetRefObj(c, j))
85 If Not (j + 1) = num_refs Then
86 Console.Write(", ")
87 End If
88 Next j
89 Console.WriteLine()
90 End If
91 End If
92 Next i
93 Console.WriteLine()
94 End If
95 End Function
96
97End Module
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales