简体   繁体   English

用Java顺序编写大型PDF

[英]Write large PDFs with Java sequentially

I am looking for a Java library that let's you write large PDFs sequentially with a minimum amount of memory. 我正在寻找一个Java库,让您以最少的内存顺序编写大型PDF。 Most of the libraries I had a look at has to build up the document in memory first before you can actually write it. 我看过的大多数库都必须先在内存中构建文档才能实际编写它。

The problem I have to deal with are OutOfMemoryErrors. 我必须处理的问题是OutOfMemoryErrors。 It would be great if I could flush the writer programmatically whenever needed eg for each page. 如果我可以在需要的时候以编程方式刷新编写器,例如每个页面,那将是很棒的。

Does anyone have any recommendations? 有没有人有任何建议? I need something with a license along the lines of the LGPL (so not the GPL or the Affero GPL that iText uses). 我需要一些带有LGPL许可证的东西(所以不是GPL或iText使用的Affero GPL)。

You can do that with iText . 你可以用iText做到这一点。 It supports writing to OutputStream s . 它支持写入OutputStream

The free version of Docmosis has a fairly open license so it might suit you. 免费版Docmosis有一个相当开放的许可证,所以它可能适合你。 It uses a template-approach which is different from building from code. 它使用的模板方法与构建代码不同。 Docmosis processes all documents in a stream-based fashion since it's intended for singificant parallel use and for large documents. Docmosis以基于流的方式处理所有文档,因为它旨在用于单独的并行使用和大型文档。 It also allows you to offload the most CPU intensive part processing to another server. 它还允许您将最耗费CPU的部件处理卸载到另一台服务器。 Hope that helps. 希望有所帮助。

I actually, had same issue as you do, a friend help me out, but he did in C# and using an api called GhostScriptSharp, you should check for it. 我实际上,和你一样有同样的问题,一个朋友帮助我,但是他在C#中使用了一个名为GhostScriptSharp的api,你应该检查它。

I can't give you a copy of the code, since its copyrighted, but i'm sure it would help you out, since the tool i think is builded on Java. 我不能给你一份代码,因为它受版权保护,但我相信它会帮助你,因为我认为这个工具是在Java上构建的。

jPod can swap indirect objects and supports incremental writing. jPod可以交换间接对象并支持增量写入。

This is still not optimal as you need an "increment" on each flush, but better than nothing... 这仍然不是最佳的,因为你需要在每次冲洗时“增量”,但总比没有好......

EDIT 编辑

Öhhh - this is one of the famous examples of self describing code :-) Your're right, theres not much of a tutorial or that - but the Javadoc is quite good. Öhhh - 这是自我描述代码的着名例子之一:-)你是对的,没有太多的教程或那 - 但Javadoc非常好。

  • jPod writes incremental by default. jPod默认写入增量。 See "CosDocument.setWriteModeHint" to set to full mode. 请参阅“CosDocument.setWriteModeHint”以设置为完整模式。
  • The example "CreateDoc" and "AppendPage" are simple examples of how to add pages. 示例“CreateDoc”和“AppendPage”是如何添加页面的简单示例。 You may do the same and call "save" every 10 or 100 pages. 您也可以这样做,每10或100页调用“保存”。 This should "soften" all references to pages in memory and if not held by some other references of yours, the can be garbage collected. 这应该“软化”对内存中页面的所有引用,如果不是由你的其他引用保存,则可以进行垃圾回收。

THere's still the question how you fill the pages? 这仍然是你如何填写页面的问题? THere are examples dealing with content streams, too (DrawText,..). 这些也是处理内容流的例子(DrawText,..)。 BUT jPod is not like iText, jasper or whatever. 但是 jPod不像iText,jasper或者其他什么。 There's only PDF model abstractions. 只有PDF模型抽象。 You have no "Layouter" or "Renderer" that creates page content from text, html or something like that. 你没有“Layouter”或“Renderer”来创建文本,html或类似内容的页面内容。 How do you do this? 你怎么做到这一点?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM