使用PdfBox,如何检索PDDocument的内容作为字节数组? [英] Using PdfBox, how do I retrieve contents of PDDocument as a byte array?

查看:38
本文介绍了使用PdfBox,如何检索PDDocument的内容作为字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently using PdfBox as the driver for a pdf-file editor application. I need the contents of the PdfBox representation of a pdf file (PDDocument) as a byte array. Does anyone know how to do this?

推荐答案

我希望不会太晚...

I hope it's not too late...

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

瞧!您已经有了两个输入流!

And voila! You've got both input streams!

这篇关于使用PdfBox,如何检索PDDocument的内容作为字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆