使用 java、xml 等设计 PDF 模板并在运行时填充数据

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

Design PDF template and populate data at runtime using java,xml etc

javapdfpdf-generation

提问by Samant

well i have been looking for a java based PDF solutions...we dont have a clean way i guess-still.. all solutions are primitive and kind of workarounds... No easy solution for this requirement - 1. Designing a PDF template using a IDE (eg. Livecycle designer ..which is not free) 2. Then at runtime using java, populate data into this PDF template...either using xml or other datasources...

好吧,我一直在寻找基于 Java 的 PDF 解决方案......我想我们仍然没有一个干净的方法......所有的解决方案都是原始的和一种变通方法......这个要求没有简单的解决方案 - 1. 设计一个 PDF 模板使用 IDE(例如 Livecycle 设计器 .. 不是免费的) 2. 然后在运行时使用 java,将数据填充到这个 PDF 模板中......使用 xml 或其他数据源......

such a simple requirement and NONE has a good "open-source and free" solution yet ! Is anyone aware of any ? I have been searching for since 3-4 years now..for a clean way out...

这么简单的要求,而且 NONE 还没有一个很好的“开源和免费”解决方案!有人知道吗?3-4 年来,我一直在寻找……寻找一条干净的出路……

Eclipse BIRT comes close.. but does not handle Barcode elements ..OOB. Jasper - ireport is also good but that tool does not have a table concept and is kind of annoying ! Also barcode support is not good.

Eclipse BIRT 接近.. 但不处理条码元素..OOB。Jasper-ireport 也不错,但该工具没有表格概念,有点烦人!条形码支持也不好。

XSL-FO has not free IDE for design .

XSL-FO 没有用于设计的免费 IDE。

Looking for a better answer .. got one ?

寻找更好的答案.. 有吗?

回答by me_here

If it's a "simple requirement", you could create a report designer around iText and release it as FOSS yourself.

如果这是一个“简单的要求”,您可以围绕 iText 创建一个报表设计器,然后自己将其作为 FOSS 发布。

回答by Paul Jowett

What are your key requirements? Does your input have to be a PDF? If so, you'll be probably working uphill for a long time still. Obviously you want to inject data and output a PDF.

您的主要要求是什么?您的输入必须是 PDF 吗?如果是这样,您可能还要长时间上坡工作。显然你想注入数据并输出一个PDF。

If your templates can be something other than PDF, you could try using the OpenOffice API to get OpenOffice to do manipulate documents and produce a PDF. JODReportsor Docmosiswould be better ways of interacting with OpenOffice and Docmosis allows you to treat documents (doc and odt) as templates.

如果您的模板可以不是 PDF,您可以尝试使用 OpenOffice API 来让 OpenOffice 处理文档并生成 PDF。 JODReportsDocmosis是与 OpenOffice 交互的更好方式,Docmosis 允许您将文档(doc 和 odt)视为模板。

回答by broc.seib

Have a look at XDocReport. You create your templates in word .docxor OpenOffice .odtfiles, then turn them into populated PDF files with Java code.

看看XDocReport。您可以在 Word.docx或 OpenOffice.odt文件中创建模板,然后使用 Java 代码将它们转换为填充的 PDF 文件。

回答by Venkat Sadasivam

You can create a PDF file with AcroField through iText API AcroField values can be populated. Note: Using OpenOffice you can create PDF document with FormFields.

您可以通过 iText API 使用 AcroField 创建 PDF 文件,可以填充 AcroField 值。注意:使用 OpenOffice,您可以使用 FormFields 创建 PDF 文档。

http://blog.rubypdf.com/2007/08/01/freely-fill-pdf-form-with-the-help-of-itext-or-itextsharp/

http://blog.rubypdf.com/2007/08/01/freely-fill-pdf-form-with-the-help-of-itext-or-itextsharp/

回答by paprika

You could use OpenOffice's UNO API. It looks rather heavyweight but at least you get something full-featured.

您可以使用 OpenOffice 的UNO API。它看起来相当重量级,但至少你得到了一些全功能的东西。