如何在 iText 中构建文档,然后将其单独写入磁盘

发布于 2024-09-10 09:21:15 字数 183 浏览 0 评论 0原文

我正在尝试编写一个程序来对 iText PDF 库进行基准测试,并且如果可能的话,我想将磁盘访问分开。我的计划是将所有内容写入内存中的文档,然后获取该文档并从中生成 PDF。问题是,我能看到将内容写入磁盘的唯一方法是使用 PdfWriter,它需要在我开始向文档添加内容之前启动。还有其他选择吗?我一直在寻找,但很难在网上找到 iText 的良好参考。

I'm trying to write a program to benchmark the iText PDF library and I'd like to separate out disk access if at all possible. My plan is to write everything into a Document in memory, then take that document and generate a PDF from it. Trouble is, the only way I can see to write the thing to disk is to use PdfWriter, which needs to be started before I begin adding things to the document. Is there any other option? I've been looking, but it's tough to find a good reference to iText online.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的鱼塘能养鲲 2024-09-17 09:21:15

有大量使用 iText 的在线资源 - 不确定您在哪里尝试过查找。如果 google 不太适合您,您可以随时购买《iText In Action》一书,这是一个很棒的资源。

无论如何,将 PdfWriter 包装在不写入文件的输出流中(如 ByteArrayOutputStream)。

PdfWriter.getInstance(document, new ByteArrayOutputStream());

尽管出于您的目的,您可能希望保留对 BAOS 的引用。

There are a huge number of online resources for using iText - not sure where you've tried looking. If google doesn't quite work for you, you can always buy the iText In Action book which is a fantastic resource.

Anyway, wrap your PdfWriter in an output stream that doesn't write to file (like a ByteArrayOutputStream).

PdfWriter.getInstance(document, new ByteArrayOutputStream());

although for your purposes, you may want to hold onto the reference to the BAOS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文