Read/Modify PDF Metadata using iTextSharp

随声附和 提交于 2019-11-27 08:29:40

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();

Try the examples in the iTextSharp book there are examples on modifying any part of the pdf file!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!