【问题标题】:Remove ID field from PDF with Apache PDFBox使用 Apache PDFBox 从 PDF 中删除 ID 字段
【发布时间】:2014-06-03 14:31:32
【问题描述】:

我需要与使用 iText 创建的 PDF 文档进行比较。我实际上设法比较了这些文件,但我发现一个微小的差异。

在像 Notepad++ 这样的编辑器中打开 PDF 时,我可以看到文件末尾有类似这样的内容:

/Root 1 0 R
/ID [<Some ID here> <Some other ID here>]

正如我在这里 (What is the ID field in a pdf file?) 发现的那样,这个元素属于一种叫做“预告片”的东西。

我可以使用 Apache PDFBox 访问和修改这个“字段”吗?

【问题讨论】:

标签: pdf pdfbox


【解决方案1】:

以下 sn-p 对我来说很好。

PDDocument doc = PDDocument.load(pdf);
COSArray cosArray = doc.getDocument().getDocumentID();
// Clear or set whatever values...
cosArray.clear();
doc.getDocument().setDocumentID(cosArray);

【讨论】:

  • 你能提供更多解释为什么它对你有用吗?
  • 使用 cosArray.clear() 后跟 doc.getDocument().setDocumentID(cosArray) 我可以按照原始问题中的要求设置 ID 的值。
猜你喜欢
  • 1970-01-01
  • 2013-01-19
  • 2021-10-28
  • 2019-01-17
  • 1970-01-01
  • 1970-01-01
  • 2021-01-05
  • 2021-02-21
  • 1970-01-01
相关资源
最近更新 更多