XMP Metadata gets lost after PDF/A-3 conversion (ZUGFeRD 2.x EN_16931)

Hi,
i’m trying to generate a valid ZUGFeRD 2.x EN_16931 file.
If i add the xmp bevor the conversion to PDF/A-3 then the metadata is not there afterwards. If i add the xmp after the PDF/A-3 conversion the file is not a valid PDF/A-3 format. To validate if the file is valid i use https://www.portinvoice.com/

Here is the code i use to create my pdf file:

        String path = Paths.get(testPath, "RE-20201121_508.pdf").toString();
        File blanko = new File(path);
        assertTrue(blanko.exists());
        path = Paths.get(testPath, "factur-x.xml").toString();
        File zugferd = new File(path);
        assertTrue(zugferd.exists());
        String filename = "factur-x.xml";

        String jobId = "123"; // for logging
        Document doc = new Document(blanko.getAbsolutePath());

        File log = new File(Tools.getBasicTempDirectory(), "PDFmakeA3compliant_" + jobId + ".xml");
        DocumentInfo docInfo = new DocumentInfo(doc);
        docInfo.setAuthor("Lobster");
        docInfo.setProducer("Lobster Unit Test");
        docInfo.setCreator( "Lobster");
        docInfo.setCreationDate(new java.util.Date());
        docInfo.setModDate(new java.util.Date());
        docInfo.setSubject("PDFmakeA3compliant");

        byte[] xml = Files.readAllBytes(zugferd.toPath());

        String description = "Invoice metadata conforming to ZUGFeRD/Factur-X, Version: 1.0";
        FileSpecification fileSpecification = new FileSpecification(filename, description);
        fileSpecification.setContents(xml);
        fileSpecification.setMIMEType("text/xml");
        fileSpecification.setAFRelationship(AFRelationship.Alternative);// TODO change to DATA again
        fileSpecification.setName(filename);

        doc.getEmbeddedFiles().add(fileSpecification);

        Metadata meta = doc.getMetadata();

        String prefix = "fx";

        meta.registerNamespaceUri("pdfaid", "http://www.aiim.org/pdfa/ns/id/");
        meta.registerNamespaceUri(prefix, "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#");
        meta.registerNamespaceUri("xmp", "http://ns.adobe.com/xap/1.0/");
        meta.registerNamespaceUri("pdf", "http://ns.adobe.com/pdf/1.3/");

        String now = ZonedDateTime.now(ZoneId.systemDefault()).toString();
        meta.setItem("xmp:CreateDate", new XmpValue(now));
        meta.setItem("xmp:CreatorTool", new XmpValue("Lobster ZUGFeRD-to-PDF/A Converter"));
        meta.setItem("xmp:ModifyDate", new XmpValue(now));
        meta.setItem("pdf:Producer", new XmpValue("Lobster data platform"));

        meta.setItem("pdfaid:part", new XmpValue("3")); // PDF/A-3
        meta.setItem("pdfaid:conformance", new XmpValue("A")); // Conformance level A


        meta.setItem(prefix + ":DocumentType", new XmpValue("INVOICE"));
        meta.setItem(prefix + ":DocumentFileName", new XmpValue(filename));
        meta.setItem(prefix + ":ConformanceLevel", new XmpValue("EN 16931"));
        meta.setItem(prefix + ":Version", new XmpValue("1.0"));


        meta.registerNamespaceUri("pdfaExtension", "http://www.aiim.org/pdfa/ns/extension/");
        meta.setItem("pdfaExtension:DocumentFileName", new XmpValue(filename));


        PdfFormatConversionOptions options = new PdfFormatConversionOptions(PdfFormat.PDF_A_3A, ConvertErrorAction.Delete);
        options.setLogFileName(log.getAbsolutePath());
        doc.convert(options);

        path = Paths.get(testPath, "Generated.pdf").toString();
        doc.save(path);

i also included all my pdf aswell as the invoce.xml
Files.zip (58,8 KB)

@SoftwareDATA

It appears you are encountering an issue with XMP metadata being lost during the conversion to PDF/A-3 format while attempting to create a valid ZUGFeRD 2.x EN_16931 file.

When XMP metadata is added before the conversion, it does not persist after the conversion to PDF/A-3. Conversely, adding it after the conversion can lead to an invalid PDF/A-3 file.

To ensure that your XMP metadata is retained, you should follow this approach:

  1. Convert the document to PDF/A-3 first.
  2. After the conversion, add the XMP metadata to the resulting PDF document.

Here’s a code snippet to illustrate this:

// Convert to PDF/A-3 first
PdfFormatConversionOptions options = new PdfFormatConversionOptions(PdfFormat.PDF_A_3A, ConvertErrorAction.Delete);
options.setLogFileName(log.getAbsolutePath());
doc.convert(options);

// Save the PDF/A-3 document
String path = Paths.get(testPath, "Generated.pdf").toString();
doc.save(path);

// Now, reopen the saved PDF to add XMP metadata
Document pdfDoc = new Document(path);
Metadata meta = pdfDoc.getMetadata();

// Add your XMP metadata here
meta.setItem("xmp:CreateDate", new XmpValue(now));
meta.setItem("xmp:CreatorTool", new XmpValue("Lobster ZUGFeRD-to-PDF/A Converter"));
// Add other metadata items as needed

// Save the updated PDF with XMP metadata
pdfDoc.save(path);

This method ensures that PDF/A-3 compliance is maintained while also including the necessary XMP metadata.

Finally, make sure to validate the final PDF using your validation tool to confirm compliance with ZUGFeRD standards.

this is not working, the pdf is no valid PDF/A-3 format. I also check it with veraPDF

@SoftwareDATA

Have you tried using the latest version of the API? Can you please share your sample PDF output along with the screenshot of compliance check results from veraPDF? We will further proceed accordingly.

we are using latest aspose-pdf 25.8. i added the report results as xml in the zip.
Result.zip (86,0 KB)

@SoftwareDATA

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-45398

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.