将这些用于生成 PDF 的产品与 Java 中的给定要求进行比较:iText、Apache PDFBox 还是 FOP?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6625849/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 08:21:51  来源:igfitidea点击:

Compare these products for PDF generation with Java given requirements inside: iText, Apache PDFBox or FOP?

javapdfpdf-generationitextapache-fop

提问by topchef

There were questions on that but not recently and technology must have gone ahead since then.

有人对此提出了疑问,但不是最近,而且从那时起技术肯定已经向前发展了。

Requirements:

要求:

  • generating pdf documents based on predefined template (I can use either pdf forms or xsl-fo)
  • being able to fill textual data
  • being able to fill graphical data (generated bar codes)
  • being able to alter pdf template in production environment without patching (recompiling)
  • generating pdf file to be saved in the database (as blob) and/or printed
  • open source/free
  • 基于预定义模板生成 pdf 文档(我可以使用 pdf 表单或 xsl-fo)
  • 能够填充文本数据
  • 能够填充图形数据(生成的条形码)
  • 无需修补(重新编译)即可在生产环境中更改 pdf 模板
  • 生成要保存在数据库中(作为 blob)和/或打印的 pdf 文件
  • 开源/免费

The options assumed are iText, PDFBox, FOP, anything else? What are recommendations based on the requirements above?

假定的选项是 iText、PDFBox、FOP,还有什么?基于上述要求有哪些建议?

采纳答案by home

  1. iText; nowadays iText is a commercial library, the latest version is not for free anymore (a fork of an older version remains under MIT license: OpenPDF)
  2. FOP; I worked a lot with FOP. It's fairly resource intensive (Java > XML > XSLT > PDF) and complex PDFs become a nightmare ( may result in XSLTs with 20k+ LoC)
  3. PDFBox; it seems to be the best alternative although I did not work with it in large projects
  4. Did not check Flying Saucer yet
  1. iText; 现在 iText 是一个商业库,最新版本不再免费(旧版本的一个分支仍然在 MIT 许可证下:OpenPDF
  2. FOP; 我在 FOP 方面做了很多工作。它是相当资源密集型的(Java > XML > XSLT > PDF)并且复杂的 PDF 变成了一场噩梦(可能导致 XSLT 具有 20k+ LoC)
  3. PDFBox; 虽然我没有在大型项目中使用它,但它似乎是最好的选择
  4. 还没有检查飞碟

To conclude, I'd give PDFBox a try. Depending on your bar code requirements you may need to inline your barcode (font) into the PDF or distribute the font to your clients - take care of those issues.

总而言之,我会尝试一下 PDFBox。根据您的条码要求,您可能需要将您的条码(字体)内联到 PDF 中或将字体分发给您的客户 - 请注意这些问题。

回答by Brian Hoover

I've done a project with Flying Saucer http://code.google.com/p/flying-saucer/which is based on iText. It's free, easy to use, has great support for CSS, and has nice open source.

我已经完成了一个基于 iText 的飞碟http://code.google.com/p/flying-saucer/项目。它是免费的,易于使用,对 CSS 有很好的支持,并且有很好的开源。

回答by mark stephens

It depends how exactly you want to create the PDF as well. FOP works from XML, IText lets you create programmatically from Java.

这也取决于您想要创建 PDF 的准确程度。FOP 从 XML 工作,IText 允许您从 Java 以编程方式创建。

回答by Mark Storer

I'm a bit biased (committer), but I suggest iText.

我有点偏见(提交者),但我建议使用 iText。

generating pdf documents based on predefined template (I can use either pdf forms or xsl-fo)

基于预定义模板生成 pdf 文档(我可以使用 pdf 表单或 xsl-fo)

PDF forms: Check

PDF 表格:检查

being able to fill textual data

能够填充文本数据

PDF Forms, check. You can also perform programmatic layout.

PDF 表格,检查。您还可以执行程序化布局。

being able to fill graphical data (generated bar codes)

能够填充图形数据(生成的条形码)

Check. Given a known location (which could be "the location of this particular annotation"), iText will draw a barcode for you given a symbology and value. You can deduce a list of supported symbologies from the constants listed here.

查看。给定一个已知位置(可能是“此特定注释的位置”),iText 将为您绘制条码给定符号系统和值。您可以从此处列出常量推断出支持的符号体系列表。

For this sort of thing, I use Button fields with an "Icon Only" appearance. The "icon" is some arbitrary PDF drawing instructions, or an image. iText's barcode stuff will create a PdfTemplateyou can stuff into the button without too much trouble.

对于这类事情,我使用具有“仅图标”外观的按钮字段。“图标”是一些任意的 PDF 绘图说明或图像。iText 的条码内容将创建一个PdfTemplate您可以轻松将内容插入按钮的内容。

being able to alter pdf template in production environment without patching (recompiling)

无需修补(重新编译)即可在生产环境中更改 pdf 模板

If all your layout is baked into the PDF template, and your "barcode goes here" info isn't hard coded into the source, then you're golden.

如果您的所有布局都融入到 PDF 模板中,并且您的“条码在此处”信息没有硬编码到源代码中,那么您就是黄金。

generating pdf file to be saved in the database (as blob) and/or printed

生成要保存在数据库中(作为 blob)和/或打印的 pdf 文件

A PDF is a PDF is a PDF. Heck, with some extra work on your part, you can use iText to build PDF/A files. "A" is for Archive.

PDF是PDF是PDF。哎呀,通过您的一些额外工作,您可以使用 iText 来构建 PDF/A 文件。“A”用于存档。

open source/free

开源/免费

Open Source: Yes. v2.1.7 was the last version to use the MPL. Since 5.x, all iText releases have been under the AGPL. Yes, iText skipped from 2.1.7 to 5.0, in order to synchronize the version numbering between iText and iTextSharp.

开源:是的。v2.1.7 是最后一个使用 MPL 的版本。从 5.x 开始,所有 iText 版本都在 AGPL 之下。是的,iText 从 2.1.7 跳过到 5.0,以便同步 iText 和 iTextSharp 之间的版本编号。

Not exactly "little f" free, but the 2.1.7 version isn't that hard to come by. OTOH, it's orphan-ware, unmaintained. Be an informed consumer.

不完全是“小f”免费,但2.1.7 版本并不难获得。OTOH,它是孤儿,无人维护。做一个知情的消费者。

回答by user986280

I think your criteria can be met with both iText and Apahce FOp but here you have some additional criteria:

我认为 iText 和 Apahce FOp 都可以满足您的标准,但在这里您还有一些额外的标准:

  • licensing: FOP is based on Apache license and therefore "friendly" also for commercial use
  • flexbility: a low level API like iText is more flexible than high level FOP
  • Visual tools: there is one designer for FOP here.
  • Programing Model: iText is based on programming API while FOP requires a XSLFO template and less programming.
  • Proprietary vs standard. Apache FOP is based on a standard and therefore vendor independent, while iText is a proprietaRy API
  • Performace: It is said FOP is more computing intensive. it depends of course of what your target PDF files are. It was a never issue for me using FOP.
  • 许可:FOP 基于 Apache 许可,因此“友好”也可用于商业用途
  • 灵活性:像 iText 这样的低级 API 比高级 FOP 更灵活
  • 视觉工具:这里有一位 FOP 设计师
  • 编程模型:iText基于编程API,而FOP需要XSLFO模板,编程少。
  • 专有与标准。Apache FOP 基于标准,因此与供应商无关,而 iText 是专有 API
  • 性能:据说 FOP 的计算强度更高。这当然取决于您的目标 PDF 文件是什么。使用 FOP 对我来说从来都不是问题。

I would not use PDFBox, it is good for reading and modifying an existing PDF file but createing a file from scratch using PDFBox can be a lot of work.

我不会使用 PDFBox,它适用于阅读和修改现有的 PDF 文件,但使用 PDFBox 从头开始​​创建文件可能需要大量工作。

回答by JunLei

nobody is talking about BFO(Big faceless)though it's commercial

没有人在谈论BFO(Big faceless),尽管它是商业广告

回答by Andreas Haufler

Another thumbs up for flying-saucer. It works quite well and is easy to use if you're familiar with html and css.

对飞碟的另一个赞许。如果您熟悉 html 和 css,它运行良好并且易于使用。

What isn't really documented is how to access iTexts built-in barcode functionality. However this can be easily accomplished. I've put up a short tutorial here: http://andreas.haufler.info/2012/12/generating-barcodes-in-pdfs-with-flying.html

没有真正记录的是如何访问 iTexts 内置条形码功能。然而,这很容易实现。我在这里提供了一个简短的教程:http: //andreas.haufler.info/2012/12/generating-barcodes-in-pdfs-with-flying.html