如何将 PDFBox PDPageContentStream 转换为 byteArrayInputStream
我试图了解如何在网络应用程序中使用 PDFBox。 PDFBox 的例子到处都说先使用文件系统保存文件。 这是来自网络的示例...... try (PDDocument doc = new PDDocument()) {
PDPage myPage = new PDPage();
doc.addPage(myPage);
try (PDPageContentStream cont = new PDPageContentStream(doc, myPage)) {
cont.beginText();
.....
cont.endText();
}
doc.save("src/main/resources/wwii.pdf");
}
但是我怎样才能在生产环境中的Web应用程序(部署在WebLogic中)中做到这一点??? 因为部署应用程序后,我不能说要写入文件系统,因为我们不知道它使用什么类型的文件系统。 唯一的出路是知道如何将 cont 对象转换为字节数组并在显示之前将其存储在内存中。
我尝试了大量时间来找出如何将上面示例中的 cont 对象转换为字节数组输入流我可以在下一步中使用它 - 将其显示在网页中。
I am trying to understand how to use PDFBox in a web application.
PDFBox examples everywhere says to use the file system to save the file first.
Here is an example from web....
try (PDDocument doc = new PDDocument()) {
PDPage myPage = new PDPage();
doc.addPage(myPage);
try (PDPageContentStream cont = new PDPageContentStream(doc, myPage)) {
cont.beginText();
.....
cont.endText();
}
doc.save("src/main/resources/wwii.pdf");
}
But how can I do that in a webapplication (deployed in WebLogic) in a production environment????
Because after the application is deployed, I cannot say to write to a file system because we do not know what type of a file system it is used.
The only way out is to know how to convert the cont object to a byte array and store it in the memory before displaying..
I tried significant amount of time to find out how to coinvert the cont object in the above example to a byte array input stream to I could use it in the next step - which is displaying it in a webpage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论