How To…Customize PDF/A Metadata

Question

“How can I alter the default metadata when exporting to PDF/A?”

Solution

Use the TppPDFDevice.OnGetPDFMetadata event to retrieve the default metadata and alter it to meet your specific needs.  All metadata is in XML format so it is beneficial to use the Delphi built-in XML classes to edit the data. The following example shows how to alter the Conformance Level when exporting to the PDF/A-3 ZUGFeRD format.

Download: ZUGFeRDCustomMetaData.zip

1. First implement the OnGetPDFMetadata event in the TppReport.OnFileDeviceCreate event.

 
2. Next, we plan to use the built-in Delphi XML classes to edit the XML.  For this example we will simply alter the value of an existing XML node.  To do so, we will need a separate routine to recursively find the XML node we need.

 
3. Finally, we put everthing together to alter a specific node in the existing metadata to meet our needs. The following code alters the “zf:ConformanceLevel” node to have a value of “COMFORT” instead of the default “BASIC”.