We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
如果时间很重要(当你的老板递给你一些东西时通常就是这种情况),我建议你查看iText(主要站点是此处)。
它学习起来非常非常简单(您可以在 20 分钟内安装、运行并生成简单的“Hello,PDF!”示例),并且可以将几乎任何内容导出到 PDF:表格、列表、图表、图像、超文本、 。
我自己承认,JasperReports 实现其
JRBeanCollectionDataSource
对您来说是一个更优雅、灵活、永久的解决方案 但是,如果您需要一个快速的库来生成 PDF,并且最后期限即将到来,我会下载 iText JAR 并使用它。该网站加载了实用的代码示例,几乎可以满足您想要完成的任何任务。
与 JasperReports 不同,iText 不是报告生成器。它只是一个 PDF 生成器(从我在你的问题中可以看出,听起来就像你所需要的那样)。因此,对于任何特定的 Bean,您只需选择要导出到 PDF 发票的属性,然后使用
Chunk
、Paragraph
等类将它们附加到您需要的文档:即使这不是您想要的,不惜一切代价我也会建议您避开 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: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!
作为 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.