Tristate
Tristate

Reputation: 1831

Hot to set PDF/UA identifier with PDFBOX

The PAC 2024 Validation Tool, give me that error.

 Metadata: PDF/UA identifier is missing

I use

org.apache.pdfbox:pdfbox:3.0.2

How can I set the identifier to a PDDocument?

Upvotes: 0

Views: 221

Answers (1)

Tilman Hausherr
Tilman Hausherr

Reputation: 18956

// file from https://taggedpdf.com/xmp/pdfUA-ID.xmp
try (InputStream is = new FileInputStream(new File("pdfUA-ID.xmp")))
{
    XMPMetadata xmp = XMPMetadata.load(is);
    xmp.addDublinCoreSchema();
    XMPSchemaDublinCore dc = xmp.getDublinCoreSchema();
    dc.setTitle("Title");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    xmp.save(baos);
    PDMetadata meta = new PDMetadata(doc, new ByteArrayInputStream(baos.toByteArray()));
    doc.getDocumentCatalog().setMetadata(meta);
}

this one uses jempbox because xmpbox fails with that schema

<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>jempbox</artifactId>
    <version>1.8.17</version>
</dependency>

Upvotes: 0

Related Questions