如何在 Java 中生成报告?

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

How do I generate reports in Java?

javasqlreportreportgenerator

提问by user2525364

How do I generate reports in Java using IO?

如何使用 IO 在 Java 中生成报告?

I want to generate PDF files with database records.

我想用数据库记录生成PDF文件。

At the moment I have something like this...

目前我有这样的事情......

try{
    ResultSet rs = ps.executeQuery();
    while(rs.next()){
    FileOutputStream fos = new FileOutputStream("Desktop/Test.pdf");
    ObjectOutputStream out = new ObjectOutputStream(fos);
    out.writeChars("Name of user: ");
    out.writeChars("Age: ");
    out.close();
}
}
    catch (IOException ioe){
    }

It keeps saying that the PDF file is corrupted.

它一直说PDF文件已损坏。

I would greatly appreciate it if someone could help me out here.

如果有人能在这里帮助我,我将不胜感激。

Edit: I do not want to use iReports/JasperReports/iText/other report generators.

编辑:我不想使用 iReports/JasperReports/iText/其他报告生成器。

Many thanks

非常感谢

回答by user_msr_3485950

Try itex API. To use IText PDF API for Java you must first download the IText JAR file from the IText website (http://itextpdf.com/), and include it on your application class path:

试试itex API。要使用适用于 Java 的 IText PDF API,您必须首先从 IText 网站 ( http://itextpdf.com/)下载 IText JAR 文件,并将其包含在您的应用程序类路径中:

http://tutorials.jenkov.com/java-itext/getting-started.html

http://tutorials.jenkov.com/java-itext/getting-started.html

回答by Massa

Well, first of all, if you don't want to use any of the java PDF/reporting libraries, you have to understand what is a PDF.

好吧,首先,如果您不想使用任何 java PDF/报告库,您必须了解什么是 PDF。

Start here with an article about the structure of a PDF, then go here for the complete, raw reference of the PDF format.

这里开始,从一篇关于 PDF 结构的文章开始,然后到这里获取 PDF 格式的完整原始参考

Hint: this is very hard. PDF is a print/display-oriented format and really complex. Another option is generating an HTML and using some tool to generate the PDF in the end. This is usually easier, as HTML is a far simpler format than PDF.

提示:这很难。PDF 是一种面向打印/显示的格式,非常复杂。另一种选择是生成 HTML 并使用一些工具最终生成 PDF。这通常更容易,因为 HTML 是一种比 PDF 简单得多的格式。

HTH!

哼!