change pdf producer

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');

It should be pointed out that the Metadata entry can include other info, such as data for Marked Content in PDF.

You can use the COSEdit tool that comes with PDFNet, and see what is in the metadata entry. See under Root->Metadata.

Or, if you want you can get the metadata as text string using PDFNet, and then load it in any xml parser, and rewrite the creator and producer entries.

There could be marked content in the PDF that references the metadata, so deleting Metadata could have secondary effects, but not to any actual rendering of the document. So modifying the xml is the only way I can think to get “New Producer” to appear in Adobe’s products.