Hello,
I have an input.pdf. The value of dc:subject is sub.
I want to change its value from sub into something else using the following code.
Before saving it to the output.pdf file, the dc:subject has the new values sub1 and sub2.
But after saving it to output.pdf, the dc:subject becomes sub, sub1, sub2.
So instead of replacing the value, it simply add the new values to dc:subject.
Did I do something wrong? What is the right way to modify the metadata in a pdf file?
Thanks.
Document doc = new Document(“C:/temp/pdf/utilities/metadata/input.pdf”);
PdfXmpMetadata xmpMeta = new PdfXmpMetadata();
xmpMeta.bindPdf(doc);
xmpMeta.removeItem(“dc:subject”);
Object[] newArr = new Object[] { “sub1”, “sub2” };
xmpMeta.set_Item(“dc:subject”, newArr);
Object[] arr = (Object[]) xmpMeta.get_Item(“dc:subject”);
System.out.println(arr.length);
System.out.println(arr[0]);
doc.save(“C:/temp/pdf/utilities/metadata/output.pdf”);
doc.close();
xmpMeta.close();