I can easily add XMP meta data to my PDFs with the following C# Code:
- Code: Select all
PdfDocument doc = new PdfDocument(PdfConformanceLevel.Pdf_A1A);
doc.FileInfo.Version = PdfVersion.Version1_7;
XmpMetadata meta = doc.XmpMetaData;
meta.SetCustomProperty("CustomProp", "TestEntry");
doc.SaveToFile("D:\\Test_CSharp.pdf");
doc = new PdfDocument("D:\\Test_CSharp.pdf");
File.WriteAllText("D:\\Test_CSharp.txt", doc.XmpMetaData.GetCustomProperty("CustomProp"));
doc.Close();
It generates a PDF with the XMP data and I can read back these values.
I can also inspect the PDF with an editor and find the CustomProp:
But I need to do this with Java and it doesn't work:
- Code: Select all
PdfDocument doc = new PdfDocument(PdfConformanceLevel.Pdf_A_1_A);
doc.getFileInfo().setVersion(PdfVersion.Version_1_7);
XmpMetadata meta = doc.getXmpMetaData();
meta.setCustomProperty("CustomProp", "TestEntry");
doc.saveToFile("D:\\Test_Java.pdf");
doc = new PdfDocument("D:\\Test_Java.pdf");
try {
Files.write(Paths.get("D:\\Test_Java.txt"), doc.getXmpMetaData().getCustomProperty("CustomProp").getBytes(),
StandardOpenOption.CREATE, StandardOpenOption.WRITE);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
doc.close();
It generates a PDF with the CustomProp but the CustomProp has no value, which can also be seen in the editor:
Also, I cannot read back the value (because it doesn't exist in the PDF, of course).
I am using the latest release 3.7.4.
Can you please provide a hotfix or tell me what I'm doing wrong?
We desperately need custom XMP meta data.
Thank you in advance.