PDF/A is an ISO-standardized subset of PDF designed for long-term archiving, and PDF/A-3 is the only PDF/A version that allows any file type to be attached to the document. JPedal provides a PdfA3Converter class to convert PDF files into valid PDF/A-3 files, either in Java or from the command line.
Converting a PDF to PDF/A-3 in Java
Create a PdfA3Converter with the conformance level to validate against, then call convert. Currently, only PdfA3Converter.Level.B is supported.
// Create an instance
final PdfA3Converter converter = new PdfA3Converter(PdfA3Converter.Level.B);
// Convert an unencrypted file
final PdfA3Converter.ConversionResult result = converter.convert(new File("inputFile.pdf"), new File("outputFile.pdf"));
// Convert a password-protected file
final PdfA3Converter.ConversionResult result = converter.convert(new File("inputFile.pdf"), "password".getBytes(), new File("outputFile.pdf"));
Checking the result of a conversion
convert returns a PdfA3Converter.ConversionResult, which lists any issues found with the file and any lossy changes made to fix them. If issues is empty, the output file is PDF/A-3b compliant; if it is not empty, no output file is written.
if (result.issues().isEmpty()) {
// If no issues reported then file converted successfully
// A list of changes to the file are also reported
System.out.println("Success!");
for (final String change : result.changes()) {
// Iterate over lossy changes made to the file to make it compliant
}
} else {
// File was not able to convert
System.out.println("Failure");
for (final String issue : result.issues()) {
// Iterate over issues found with the file
}
}
Converting a PDF to PDF/A-3 from the command line
PdfA3Converter can also be run from the command line to convert one or more files, or all the PDF files in a directory, into an output directory.
java -cp jpedal.jar org.jpedal.tools.pdfa.PdfA3Converter --level B --output outputFolder inputFile1.pdf inputFile2.pdf
Files can also be passed with --input/-i, each optionally followed by --password/-p and a password for that file. Only files passed this way can have a password argument.
java -cp jpedal.jar org.jpedal.tools.pdfa.PdfA3Converter --level B --output outputFolder --input inputFile1.pdf --input inputFile2.pdf --password inputFile2Password
An input can also be a directory, in which case every PDF file it contains is converted. You cannot provide passwords for entire directories.
java -cp jpedal.jar org.jpedal.tools.pdfa.PdfA3Converter --level B --output outputFolder inputFolder
Confirming compliance
Note it is recommended to confirm the compliance of a converted PDF/A-3 file with a validation tool such as veraPDF, which is the PDF Association’s free, open-source reference implementation.