I have an iText Document
object and I want to write some metadata into it or read from it.
How can I do that?
Imagine that the document is beeing passed to a method like :
public void prePreccess(Object document) {
Document pdfDocument = ((Document) document);
//What to do here with pdfDocument?
}
Do you want to populate the info dictionary of a PDF? That's explained in the MetadataPdf example:
Do you want to set the XMP metadata? This is explained in the MetadataXmp example:
Note that this method is deprecated: we have replaced the XMP functionality recently, but we still have to write some examples using the new code.
Maybe you want to set populate the info dictionary and create the XMP metadata at the same time:
If I were you, I'd use this option because it's the most complete solution.
You should not read the metadata from a
Document
object.You can read the XMP stream from an existing PDF like this:
You can read the entries in the info dictionary like this:
The
info
object will contain a series of keys and values that are stored as metadata inside the PDF.