如何在 iText 7 (.Net) 中添加元数据(标题、作者等)。我发现的所有线程和示例似乎都使用旧格式
\n\ndocument.addTitle(\xe2\x80\x9cTitle\xe2\x80\x9d); \nRun Code Online (Sandbox Code Playgroud)\n\n看来你可以\xe2\x80\x99t 在 iText 7 中执行此操作。
\n\n谢谢
\n请查看第 7 章,更具体地查看XMP 元数据小节。在该小节中,您将找到以下示例:
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(
new PdfWriter(dest,
new WriterProperties()
.addXmpMetadata()
.setPdfVersion(PdfVersion.PDF_1_6)));
PdfDocumentInfo info = pdf.getDocumentInfo();
info.setTitle("The Strange Case of Dr. Jekyll and Mr. Hyde");
info.setAuthor("Robert Louis Stevenson");
info.setSubject("A novel");
info.setKeywords("Dr. Jekyll, Mr. Hyde");
info.setCreator("A simple tutorial example");
Document document = new Document(pdf);
document.add(new Paragraph("Mr. Jekyl and Mr. Hyde"));
document.close();
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,元数据不再直接添加到文档中,而是添加到PdfDocumentInfo从PdfDocument实例获取的对象中。该PdfDocumentInfo对象用于创建 Info 字典(旧式元数据)以及 XMP 流(新式元数据)。仅当您addXmpMetadata()在WriterProperties.
注意:由于在 PDF 2.0 中信息字典已被弃用,取而代之的是 XMP 元数据,因此这将在 iText 的未来版本中发生变化。在这些版本中,我们将优先使用 XMP,而不是使用 Info 字典。
| 归档时间: |
|
| 查看次数: |
4530 次 |
| 最近记录: |