3.25.  PDF/A

Overview

There are many tools for checking whether a PDF document complies with one of the PDF standards (PDF/A, PDF/X etc.). But only a few of them can be used for automated tests. PDFUnit uses the PDFBox's 'Preflight' parser internally to check the compliance with PDF/A.

Information on the 'Preflight' parser can be found on the project web site https://pdfbox.apache.org/1.8/cookbook/pdfavalidation.html.

A PDF/A validation starts with the following method:

// Validate PDF/A-1a and PDF/A-1b:
.compliesWith().pdfStandard(Standard)

Example

The next example checks compliance with PDF/A-1a:

@Test
public void compliesWithPDFA() throws Exception {
  String fileName = "pdf_a/documentUnderTest.pdf"; 1
  
  AssertThat.document(fileName)
            .compliesWith()
            .pdfStandard(PDFA_1A)                  2
  ;
}

1

Files can be tested but not byte-arrays or streams.

2

The validation can be parameterized using one of the two constants PDFA_1A and PDFA_1B.

The error messages from the Preflight parser are passed through to PDFUnit. The images below show examples in Eclipse and in an HTML browser:

A PDF/A validation can also be applied to all PDF documents in a given folder:

@Test
public void compliesWithPDFA_InFolder() throws Exception {
  File foldertoWatch = new File("pdf_a-1b");
  FilenameFilter filenameFilter = new FilenameContainingFilter("tn0001");
  
  AssertThat.eachDocument()
            .inFolder(foldertoWatch)
            .passedFilter(filenameFilter)
            .compliesWith()
            .pdfStandard(PDFA_1B)
  ;
}