java 使用 PdfBox,如何以字节数组的形式检索 PDDocument 的内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11593116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using PdfBox, how do I retrieve contents of PDDocument as a byte array?
提问by Gabriel Ruiu
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?
我目前使用 PdfBox 作为 pdf 文件编辑器应用程序的驱动程序。我需要 pdf 文件 (PDDocument) 的 PdfBox 表示的内容作为字节数组。有谁知道如何做到这一点?
回答by Ian Traum
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!
瞧!你有两个输入流!