Question:
I am trying to use PDFtron (PDFNet-6.1.2.1.jar) to change the producer in an existing pdf.
It works for some but I have a few documents where it does not work.
a) Not sure if I am doing something wrong or I stepped on a bug … ?
b) Also, I wasn’t sure what flags to use for saving (i.e. when I just want to update producer on existing PDF)
Here is the code I am using:
PDFDoc pdfDoc = new PDFDoc("input.pdf");
PDFDocInfo info = pdfDoc.getDocInfo();
info.setCreator("New Creator");
info.setProducer("New Producer");
pdfDoc.save("output.pdf", SDFDoc.e_incremental, null);
Answer:
There is nothing wrong with your code.
I assume what you mean by “does not work” is that viewing it in Adobe Acrobat, or Adobe Reader, it still shows the original creator/producer. If you view in another reader, such as Foxit or Nitro, you should see “New Producer”
This is because Adobe secretly stores this info in xml in a metadata entry. Add the following line of code, and you will see “New Producer”.
root = pdfDoc.getRoot();
root.erase('Metadata');