使用 iTextSharp 读取/修改 PDF 元数据
我正在尝试使用 iTextSharp 读取/修改 PDF 元数据.我想出了如何使用 pdfreader 和 pdfstamper 做到这一点.我想知道我是否还可以在 XMP photoshop 命名空间中读取/修改其他元数据信息,例如版权信息和其他一些信息.
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.
谢谢,穆鲁格什.
您可以使用 `PdfReader' 读取元数据.我读过这样的元数据:
You can read metadata using `PdfReader'. I've read metadata like this:
PdfReader reader = new PdfReader("HelloWorldNoMetadata.pdf");
string s = reader.Info["Author"];
您可以尝试使用 iTextSharp.text.xml.xmp.XmpWriter
类来编写元数据.我从来没有做过,但是 我找到了这个代码 下面:
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();