创建后应下载jasper报告
问题描述:
这里我正在使用本地驱动器中的jasper报告和.jxml文件
(例如C:/jrxml/idcard.jrxml),现在我希望它与项目放在一起,并且应在生成时下载.
有人请建议我该怎么办?
Here i am using jasper report and .jxml file using from local drive
(like C:/jrxml/idcard.jrxml),now i want it to put with project and that should download when it generate.
anyone please suggest me what to do?
public void generateReport() {
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bsaigsamed?user=root&password=root");
InputStream input = new FileInputStream(new File("C:/jrxml/idcard.jrxml"));
JasperDesign jasperDesign = JRXmlLoader.load(input);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
//Exporting the report
OutputStream output = new FileOutputStream(new File("D:/Report/Reperesentative_id.pdf"));
JasperExportManager.exportReportToPdfStream(jasperPrint, output);
System.out.println("Report Generation Complete");
conn.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (JRException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
答
将其扔到操作系统上,然后让操作系统决定如何打开它.这很容易,免维护并且是常见的方法.
throw it against the OS and let the OS decide on how to open it. That''s easy, maintenance free and the common way.
final Program p = Program.findProgram("pdf");
p.execute(printFilePath);
然后,用户可以决定是否要使用它(例如打印它)或保存它.
The user can then decide if he wants to work with it (e.g. print it) or save it.