views:

830

answers:

1

Hello,

I am trying to use iTextSharp to read/modify PDF metadata. I figured out how to do it using pdfreader and pdfstamper. I was wondering if I could also read/modify additional metadata information like copyright information and few others within the XMP photoshop namespace.

I would greatly appreciate any pointers to the solution.

Thank you, Murugesh.

+1  A: 

You can read metadata using `PdfReader'. I've read metadata like this:

PdfReader reader = new PdfReader("HelloWorldNoMetadata.pdf");
string s = reader.Info["Author"];

You can try the iTextSharp.text.xml.xmp.XmpWriter class to write metadata. I've never done it but I found this code below:

PdfReader reader = new PdfReader("HelloWorldNoMetadata.pdf");
PdfStamper stamper = new PdfStamper(reader,
 new FileOutputStream("HelloWorldStampedMetadata.pdf"));
HashMap info = reader.getInfo();
info.put("Author", "Bruno Lowagie");
info.put("Title", "Hello World stamped");
stamper.setMoreInfo(info);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XmpWriter xmp = new XmpWriter(baos, info);
xmp.close();
stamper.setXmpMetadata(baos.toByteArray());
stamper.close();
Jay Riggs
Thanks for the response. It works. I am able to put values to any schema within XMP now. But whenever I insert a value other than the common metadata fields (Author, Title, Subject, Keywords) it adds them as a custom field which goes under "pdfx" schema in addition to the schema where I am inserting it. I don't want them to be added as custom fields. Any pointers?Thanks,Murugesh.
muruge
@muruge - No sorry I don't have any pointers; I've never tried what you're doing. I also couldn't find much on the iTextSharp.text.xml.xmp namespace.
Jay Riggs
@Jay - Thanks for the response.
muruge