Reputation: 143
I have the task to create a PHP tool using TCPDF/FPDI that takes existing PDFs and converts them to PDF/A standard while adding a certificate.
Unfortunately all the generated PDFs did not conform to the PDF/A standard. I also tried to generate a random test document as shown here https://tcpdf.org/examples/example_065/ but that document did not conform either.
This is my code:
public static function convertPdf($path)
{
$pdf = new \FPDI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
$pagecount = $pdf->setSourceFile(ROOT . $path);
for ($i = 1; $i <= $pagecount; $i++) {
$tpl = $pdf->importPage($i);
$size = $pdf->getTemplateSize($tpl);
$orientation = $size['h'] > $size['w'] ? 'P':'L';
$pdf->AddPage($orientation);
$pdf->useTemplate($tpl, null, null, $size['w'], $size['h'], true);
}
$pdf->SetCreator("Creator");
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('My PDFA example');
$pdf->SetSubject('TCPDF Tutorial');
$certificatePath = 'file://' . ROOT . '/libs/TCPDF-master/examples/data/cert/tcpdf.crt';
// set additional information
$info = array(
'Name' => 'TCPDF',
'Location' => 'Office',
'Reason' => 'Testing TCPDF',
'ContactInfo' => 'http://www.tcpdf.org',
);
$pdf->setSignature($certificatePath, $certificatePath, 'tcpdfdemo', '', 2, $info);
$pdf->addEmptySignatureAppearance(0, 0, 0, 0);
$pdf->Output('example_065.pdf', 'I');
}
I used this https://www.pdf-online.com/osa/validate.aspx to validate my PDF. It generates this output:
Compliance pdfa-1b Result Document does not conform to PDF/A. Details Validating file "testerrrrrr.pdf" for conformance level pdfa-1b There is data after the EOF marker. pdfaExtension:schemas/[0] :: Missing required field 'property' in value type 'Schema'. pdfaExtension:schemas/[0] :: Missing required field 'valueType' in value type 'Schema'. pdfaExtension:schemas/[1] :: Missing required field 'valueType' in value type 'Schema'. pdfaExtension:schemas/[2] :: Missing required field 'valueType' in value type 'Schema'. The appearance dictionary doesn't contain an entry. The key S has a value Transparency which is prohibited. The document does not conform to the requested standard. The file format (header, trailer, objects, xref, streams) is corrupted. The document contains transparency. The document contains annotations or form fields with ambigous or without appropriate appearances. The document's meta data is either missing or inconsistent or corrupt. Done.
Upvotes: 1
Views: 3791
Reputation: 21
In my case (TCPDF v. 6.2.26), the problem was located in tcpdf.php file at line 9583:
$xmp .= "\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n";
$xmp .= "\t\t\t\t\t".'</rdf:li>'."\n";
$xmp .= "\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
After "Adobe PDF schema", the declaration of the property was missing. I solved adding the following code between pdfaSchema declaration and li closure tag:
$xmp .= "\t\t\t\t\t\t".'<pdfaSchema:property>'."\n";
$xmp .= "\t\t\t\t\t\t\t".'<rdf:Seq>'."\n";
$xmp .= "\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n";
$xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n";
$xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>A name object indicating whether the document has been modified to include trapping information</pdfaProperty:description>'."\n";
$xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>Trapped</pdfaProperty:name>'."\n";
$xmp .= "\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n";
$xmp .= "\t\t\t\t\t\t\t\t".'</rdf:li>'."\n";
$xmp .= "\t\t\t\t\t\t\t".'</rdf:Seq>'."\n";
$xmp .= "\t\t\t\t\t\t".'</pdfaSchema:property>'."\n";
Upvotes: 2
Reputation: 5058
Generally: If the document that is imported via FPDI is not PDF/A conform (comes e.g. with transparency), the result will never be validated successfully. Just by setting some PDF/A flags through TCPDF doesn't make the imported pages PDF/A conform.
TCPDF fakes the signature appearance because the appearance is written to the pages content stream while the real appearance is empty (in view to "The appearance dictionary doesn't contain an entry.").
The missing attributes should be added in the TCPDF code (other "validators" do not complain about them).
Upvotes: 0