jPDFPreflight Developer Guide
jPDFPreflight Developer Guide
Contents
Introduction
Loading a Document
Validating against PDF/A
Validating against PDF/X
Converting to PDF/A
Conversion Options
Distribution and JAR files
Source Code Samples
Javadoc API
Introduction
jPDFPreflight is a Java library to verify PDF compliance with different standards, including PDF/A and PDF/X and to convert documents to these standards.
Loading a Document
Simply load the document using the following call:
// Load the PDF Document PDFPreflight pdfPreflight = new PDFPreflight("C:\\input.pdf", null); |
Validating against PDF/A
The following PDF/A profiles are available for validation: PDFA_1_B_Verification, PDFA_2_B_Verification, PDFA_3_B_Verification. Here is sample code to validate against PDFA_1_B_Verification.
// Validate the document PreflightResults results = pdfPreflight.verifyDocument(new PDFA_1_B_Verification(), null); //Get validation results if (results.isSuccessful()) { System.out.println("PDF is compliant"); } else { System.out.println("PDF is not compliant"); // Add annotations to the document results.addResultAnnotations(); // Append report to the document results.appendPreflightReport(612, 792); // Save the PDF document (with annotations and report) pdfPreflight.saveDocument("C:\\validationreport.pdf"); } |
Validating against PDF/X
The following PDF/X profiles are available for validation: PDFX_1a_2001, PDFX_1a_2003, PDFX_3_2002, PDFX_3_2003. Here is a code sample to validate against PDFX_3_2002:
// Validate the document PreflightResults results = pdfPreflight.verifyDocument(new PDFX_3_2002(), null); //Get validation results if (results.isSuccessful()) { System.out.println("PDF is compliant"); } else { System.out.println("PDF is not compliant"); // Add annotations to the document results.addResultAnnotations(); // Append report to the document results.appendPreflightReport(612, 792); // Save the PDF document (with annotations and report) pdfPreflight.saveDocument("C:\\validationreport.pdf"); } |
Converting to PDF/A
The following PDF/A profiles are available for conversion: PDFA_1_B_Conversion, PDFA_2_B_Conversion, PDFA_3_B_Conversion. Here is sample code to convert to PDF/A-1b.
// Convert the document PreflightResults results = pdfPreflight.convertDocument(new PDFA_1_B_Conversion(), null); // Get conversion results if (results.isSuccessful()) { System.out.println("PDF was converted successfully"); // Save the PDF/A Document pdfPreflight.saveDocument("C:\\output_pdfa.pdf"); } else { System.out.println("PDF was not converted"); // Add annotations to the document results.addResultAnnotations(); // Append report to the document results.appendPreflightReport(612, 792); // Save the PDF document (with annotations and report) pdfPreflight.saveDocument("C:\\conversionreport.pdf"); } |
Conversion Options
It is possible to overwrite the default conversion options for PDF/A conversion:
// Create a new conversion profile PDFA_1_B_Conversion profile = new PDFA_1_B_Conversion(); // Set conversion options PDFAConversionOptions options = (PDFAConversionOptions) profile.getConversionOptions(); // delete any embedded files options.setEmbeddedFiles(PDFAConversionOptions.OPTION_DELETE); // give a warning / error during conversion if transparency is found options.setTransparency(PDFAConversionOptions.OPTION_WARN); // delete any unsupported annotations options.setUnsupportedAnnotations(PDFAConversionOptions.OPTION_DELETE); // convert the document to PDF/A PreflightResults results = pdfPreflight.convertDocument(new PDFA_1_B_Conversion(), null); |
Distribution and JAR Files
Required and optional jar files for jPDFPreflight can be found on the jPDFPreflight Download page.