问题
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:
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();
回答2:
Try the examples in the iTextSharp book there are examples on modifying any part of the pdf file!
来源:https://stackoverflow.com/questions/2761646/read-modify-pdf-metadata-using-itextsharp