Convert PDF to PDF/A formats

Aspose.PDF for PHP allows you to convert a PDF file to a PDF/A compliant PDF file. Before doing so, the file must be validated. This article explains how.

Please note we follow Adobe Preflight for validating PDF/A conformance. All tools on the market have their own “representation” of PDF/A conformance. Please check this article on PDF/A validation tools for reference. We chose Adobe products for verifying how Aspose.PDF produces PDF files because Adobe is at the center of everything connected to PDF.

Before converting the PDF to a PDF/A compliant file, validate the PDF using the validate method. The validation result is stored in an XML file and then this result is also passed to the convert method. You can also specify the action for the elements which can not be converted using the ConvertErrorAction enumeration.

PDF to PDF/A Conversion

The following code snippet shows how to convert PDF files to PDF/A-1b compliant PDF.

// Create a new Document object and load the input PDF file.
$document = new Document($inputFile);

// Convert the document to PDF/A-1a format and specify the log file and error action.
$res = $document->convert($logFile, PdfFormat::$PDF_A_1A, ConvertErrorAction::$Delete);

// Save the converted document to the output file.
$document->save($outputFile);

To perform validation only, use the following line of code:

// Create a new Document object and load the input PDF file.
$document = new Document($inputFile);

// Convert the document to PDF/A-1a format and specify the log file and error action.
$res = $document->convert($logFile, PdfFormat::$PDF_A_1A, ConvertErrorAction::$Delete);

// Validate PDF for PDF/A-1a
if ($document->validate("validation-result-A1A.xml", PdfFormat.PDF_A_1A))
{
    echo "Valid";
}
else
{
    echo "Not valid";
}