如何将 PDFBox PDPageContentStream 转换为 byteArrayInputStream

发布于 2025-01-15 18:52:45 字数 643 浏览 2 评论 0原文

我试图了解如何在网络应用程序中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文