As explained in this post (removing PDFID in PDF) /ID is a recommended entry in the "trailer dictionary" (and required if an AcroForm is encrypted).
Using iText, IDs are accessed as a PdfArray
of two PdfString
objects in the trailer PdfDictionary
. The String values will look like garbage because each is a representation of a byte array. These are the hex values you need for "original" and "modified".
The following code will print out the two IDs, which can be verified against e.g. an export from Acrobat Pro (NB Hex.encodeHexString
is Apache commons-codec):
public void printIds(PdfReader reader) {
PdfDictionary trailer = reader.getTrailer();
if (trailer.contains(PdfName.ID)) {
PdfArray ids = (PdfArray) trailer.get(PdfName.ID);
PdfString original = ids.getAsString(0);
PdfString modified = ids.getAsString(1);
System.out.println(Hex.encodeHexString(original.getBytes()));
System.out.println(Hex.encodeHexString(modified.getBytes()));
}
}