寻找 JasperReports 的替代品

发布于 2024-12-17 11:03:03 字数 1539 浏览 0 评论 0原文

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

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

发布评论

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

评论(2

无风消散 2024-12-24 11:03:03

如果时间很重要(当你的老板递给你一些东西时通常就是这种情况),我建议你查看iText(主要站点是此处)。

它学习起来非常非常简单(您可以在 20 分钟内安装、运行并生成简单的“Hello,PDF!”示例),并且可以将几乎任何内容导出到 PDF:表格、列表、图表、图像、超文本、 。

我自己承认,JasperReports 实现其 JRBeanCollectionDataSource 对您来说是一个更优雅、灵活、永久的解决方案 但是,如果您需要一个快速的库来生成 PDF,并且最后期限即将到来,我会下载 iText JAR 并使用它。

该网站加载了实用的代码示例,几乎可以满足您想要完成的任何任务。

与 JasperReports 不同,iText 不是报告生成器。它只是一个 PDF 生成器(从我在你的问题中可以看出,听起来就像你所需要的那样)。因此,对于任何特定的 Bean,您只需选择要导出到 PDF 发票的属性,然后使用 ChunkParagraph 等类将它们附加到您需要的文档:

// Your POJO/Bean/VO
Employee oEmp = new Employee();

Document oInvoicePdf = new Document();
PdfWriter.getInstance(document, new FileOutputStream("/invoices/2011/Invoice201.pdf"));
document.open();
document.add(new Chunk("Employee's name is : " + oEmp.getName()));
document.close();

即使这不是您想要的,不惜一切代价我也会建议您避开 Apache PdfBox。在我看来,这是纯粹的邪恶,只会伤透你的心。

希望这会有所帮助,祝你好运!

If time is of the essence (as is usually the case when your boss hands you something) I would recommend checking out iText (main site is here).

It is very, very simple to learn (you can have it up, running, and generating simple "Hello, PDF!" examples in 20 minutes) and can export just about anything into PDF: tables, lists, charts, images, hypertext, etc.

By my own admission, JasperReports implementing its JRBeanCollectionDataSource is a more elegant, flexible, permanent solution for you. But if you need a quick-n-dirty library to just produce PDFs, and looming deadlines are drawing nigh, I would download the iText JAR and have at it.

The site is loaded with practical code examples for just about anything you would want to accomplish.

Unlike JasperReports, iText is not a report generator. Its just a PDF generator (which, from what I can tell in your question, sounds like all you need). So, for any particular Bean, you would just select the properties you want exported to the PDF invoice, and use the Chunk, Paragraph, etc. classes to append them to the document as you need:

// Your POJO/Bean/VO
Employee oEmp = new Employee();

Document oInvoicePdf = new Document();
PdfWriter.getInstance(document, new FileOutputStream("/invoices/2011/Invoice201.pdf"));
document.open();
document.add(new Chunk("Employee's name is : " + oEmp.getName()));
document.close();

Even if this is not what you're looking for, at all costs I would recommend you steer clear of Apache PdfBox. In my humble opinion, it is pure evil and will only break your heart.

Hope this helps, and best of luck!

邮友 2024-12-24 11:03:03

作为 iReport 的替代方案,您可以尝试 JasperReports 的 JasperWave 设计器。
为了解决第二个问题,为什么不编写一些辅助java代码来将bean结构转换为报告结构呢?无论如何,将 java 对象映射到某种平面结构总是不容易的。创建一些java接口来隐藏底层bean结构的复杂性。不确定第二个问题是寻找替代报告解决方案的原因。

As an alternative to iReport you can try JasperWave designer for JasperReports.
To address the second issue why not to write some helper java code that translate beans structure to report structure? In any case it is always not easy to map java objects to some kind of flat structure. Create some java interface that will hide the complexity of underlying beans structure. Not sure that the second issue is the the reason to look for alternative reporting solution.

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