40.7. Document Info and Metadata

A PDF document may include general information such as the document's title, author, and creation and modification dates.

Historically this information is stored using special Info structure. This structure is available for read and writing as an associative array using properties public property of Zend_Pdf objects:

$pdf = Zend_Pdf::load($pdfPath);

echo $pdf->properties['Title'] . "\n";
echo $pdf->properties['Author'] . "\n";

$pdf->properties['Title'] = 'New Title.';
$pdf->save($pdfPath);

The following keys are defined by PDF v1.4 (Acrobat 5) standard:

Since PDF v 1.6 metadata can be stored in the special XML document attached to the PDF (XMP - Extensible Metadata Platform).

This XML document can be retrieved and attached to the PDF with Zend_Pdf::getMetadata() and Zend_Pdf::setMetadata($metadata) methods:

$pdf = Zend_Pdf::load($pdfPath);
$metadata = $pdf->getMetadata();
$metadataDOM = new DOMDocument();
$metadataDOM->loadXML($metadata);

$xpath = new DOMXPath($metadataDOM);
$pdfPreffixNamespaceURI = $xpath->query('/rdf:RDF/rdf:Description')
                                ->item(0)
                                ->lookupNamespaceURI('pdf');
$xpath->registerNamespace('pdf', $pdfPreffixNamespaceURI);

$titleNode = $xpath->query('/rdf:RDF/rdf:Description/pdf:Title')->item(0);
$title = $titleNode->nodeValue;
...

$titleNode->nodeValue = 'New title';
$pdf->setMetadata($metadataDOM->saveXML());
$pdf->save($pdfPath);

Common document properties are duplicated in the Info structure and Metadata document (if presented). It's user application responsibility now to keep them synchronized.