【问题标题】:Using PdfBox, how do I retrieve contents of PDDocument as a byte array?使用 PdfBox,如何将 PDDocument 的内容检索为字节数组?
【发布时间】:2012-07-21 14:44:04
【问题描述】:

我目前正在使用 PdfBox 作为 pdf 文件编辑器应用程序的驱动程序。 我需要将 pdf 文件 (PDDocument) 的 PdfBox 表示的内容作为字节数组。 有谁知道怎么做?

【问题讨论】:

  • 你发现了吗?我也想知道...

标签: java pdfbox


【解决方案1】:

希望还不算太晚……

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
document.save(byteArrayOutputStream);
document.close();
InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());

瞧!你有两个输入流!

【讨论】:

  • 抱歉回复晚了。
  • 答案是正确的,至少对于我检查的PDFBox版本(1.8.4)
  • 在 org.apache.pdfbox:pdfbox:2.0.4 中工作正常
  • 在最新的可用版本 (2.0.23) 中也可以正常工作
  • 你救了我。 PDFMergeUtility 在 2.0.* 中是一团糟,无法将 PDDocuments 与 Type0 字体合并。所以我将这两个文件保存在一个流中,然后可以稍后将它们合并为输入流。
猜你喜欢
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 2016-11-17
  • 1970-01-01
  • 2019-05-10
  • 2017-03-15
  • 2015-03-06
  • 1970-01-01
相关资源
最近更新 更多