PDF change metadata
Sometimes it is useful to change PDF Metadata.
The following code snipped is based on Add an image to an existing PDF
hmpInfo.put("Title", "CV");
hmpInfo.put("Author", "rjahn");
PdfDictionary dictTrailer = pdr.getTrailer();
if (dictTrailer != null && dictTrailer.isDictionary())
{
PdfObject objInfo = PdfReader.getPdfObject(dictTrailer.get(PdfName.INFO));
if (objInfo != null && objInfo.isDictionary())
{
PdfDictionary infoDic = (PdfDictionary)objInfo;
for (Map.Entry<String, String>entry : hmpInfo.entrySet())
{
if (entry.getValue().length() == 0)
{
infoDic.remove(new PdfName(entry.getKey()));
}
else
{
infoDic.put(new PdfName(entry.getKey()),
new PdfString(entry.getValue(), PdfObject.TEXT_UNICODE));
}
}
}
}
pdr.getCatalog().remove(PdfName.METADATA);