Using PdfBox, how do I retrieve contents of PDDocument as a byte array?

若如初见. 提交于 2019-12-18 04:34:13

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/11593116/using-pdfbox-how-do-i-retrieve-contents-of-pddocument-as-a-byte-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!