Detecting PDF/A document

PDF/A is an ISO-standardized version of PDF for digital preservation and long-term archiving of electronic documents. Unlike standard PDF, PDF/A prohibits features unsuitable for long-term archiving, such as font linking and encryption, and requires that certain features be included, such as embedded fonts and color profiles.

There are several conformance levels defined across multiple PDF/A versions:

  • PDF/A-1 (ISO 19005-1) — based on PDF 1.4, with conformance levels a (accessible) and b (basic)
  • PDF/A-2 (ISO 19005-2) — based on PDF 1.7, adding conformance level u (Unicode)
  • PDF/A-3 (ISO 19005-3) — same as PDF/A-2 but allows embedding arbitrary file formats as attachments
  • PDF/A-4 (ISO 19005-4) — based on PDF 2.0, with the e (engineering) and f (embedded files) variants

Using GroupDocs.Metadata for Java you can detect whether a loaded PDF document conforms to a PDF/A standard and find out its exact version and conformance level.

Detecting PDF/A conformance

The following steps and Java code sample show how to detect the PDF/A type of a PDF document in a Java application:

  1. Load a PDF document
  2. Extract the root metadata package
  3. Get the file format package using the getPdfType method
  4. Check the isPdfA flag and read the getPdfFormat value

advanced_usage.managing_metadata_for_specific_formats.document.pdf.PdfDetectPdfA

try (Metadata metadata = new Metadata(Constants.InputPdfA)) {
    PdfRootPackage root = metadata.getRootPackageGeneric();

    if (root.getPdfType().isPdfA()) {
        System.out.println(String.format("PDF/A version: %s", root.getPdfType().getPdfFormat()));
    } else {
        System.out.println("The document is not PDF/A compliant.");
    }
}

For a PDF/A-1b document the code prints PDF/A version: PdfA1B.

The getPdfFormat method returns one of the PdfFormat enumeration values:

GroupValues
PDF/APdfA1A, PdfA1B, PdfA2A, PdfA2B, PdfA2U, PdfA3A, PdfA3B, PdfA3U, PdfA4, PdfA4E, PdfA4F
PDF/XPdfX1A2001, PdfX1A, PdfX3, PdfX4
Plain PDFPdf10, Pdf11, Pdf12, Pdf13, Pdf14, Pdf15, Pdf16, Pdf17, Pdf20
OtherPdfUa1, ZugFeRD, Unknown

isPdfA returns true for any value from the PDF/A group, and isPdfX returns true for any value from the PDF/X group.

Detecting PDF/A type and version information together

The code sample below shows how to read the PDF/A conformance information together with general PDF file format properties.

try (Metadata metadata = new Metadata(Constants.InputPdfA)) {
    PdfRootPackage root = metadata.getRootPackageGeneric();
    PdfTypePackage pdfType = root.getPdfType();

    System.out.println(String.format("File format : %s", pdfType.getFileFormat()));
    System.out.println(String.format("PDF version : %s", pdfType.getVersion()));
    System.out.println(String.format("MIME type   : %s", pdfType.getMimeType()));
    System.out.println(String.format("PDF format  : %s", pdfType.getPdfFormat()));
    System.out.println(String.format("Is PDF/A    : %s", pdfType.isPdfA()));
    System.out.println(String.format("Is PDF/X    : %s", pdfType.isPdfX()));
}

Checking a folder of PDF documents

Before PDF files are moved to an archive, it is common to check which of them are already PDF/A. The following code sample prints the detected format of every PDF file in a folder.

File folder = new File(Constants.InputPath);
for (File file : folder.listFiles((dir, name) -> name.toLowerCase().endsWith(".pdf"))) {
    try (Metadata metadata = new Metadata(file.getAbsolutePath())) {
        PdfRootPackage root = metadata.getRootPackageGeneric();
        PdfFormat format = root.getPdfType().getPdfFormat();

        if (root.getPdfType().isPdfA()) {
            System.out.println(String.format("%s: %s", file.getName(), format));
        } else {
            System.out.println(String.format("%s: not PDF/A (%s)", file.getName(), format));
        }
    }
}
Note
GroupDocs.Metadata reports the conformance level that the document declares about itself. The check does not validate the file against the PDF/A standard, so use a dedicated validator if you need proof of compliance.

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document metadata management App

Along with full featured Java library we provide simple, but powerful free Apps. You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.