简体   繁体   English

将Jasper设计文件编译成.jasper

[英]compile Jasper design file into .jasper

I have a .jrxml file which is used to generate a jasper report and then aa pdf file from that. 我有一个.jrxml文件,用于生成jasper报告,然后从中生成一个pdf文件。 for that I used this code. 因为我使用了这段代码。

JasperCompileManager.compileReportToFile("C:/Users/my-pc/Desktop/letters/report xml/testreport.jrxml");

But I got an issue with xsd and dtd which is described here. 但我遇到了xsddtd的问题,这里有描述。 That article introduces a way to solve the issue by using a java program called LegacyJasperInputStream . 该文介绍了一种使用名为LegacyJasperInputStream的java程序解决问题的方法。

This is how I should call it. 这就是我应该怎么称呼它。

JasperDesign design = JRXmlLoader.load(
   new LegacyJasperInputStream(new FileInputStream("C:/Users/my-pc/Desktop/letters/report xml/testreport.jrxml"))
);

My question is what is this JasperDesign . 我的问题是这个JasperDesign是什么。 Can I compile that into .jasper . 我可以将其编译成.jasper If so, how to do it? 如果是这样,怎么办?

Thanks! 谢谢!

After searching and trying....Here we go. 经过搜索和尝试......我们走了。

net.sf.jasperreports.engine.design.JasperDesign design = JRXmlLoader.load(
                    new LegacyJasperInputStream(new FileInputStream("C:/Users/my-pc/Desktop/letters/report xml/testreport.jrxml"))
                    );
            JasperReport jasperReport = asperCompileManager.compileReport(design);

            JasperPrint print = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
            System.out.println("INFO: Report is filled and to be exported to pdf now");

            try {
                // export report to pdf
                JasperExportManager.exportReportToPdfFile(print, "C:/Users/my-pc/Desktop/letters/report xml/test.pdf");
                System.out.println("DEBUG: Expported to pdf");
            } catch (Exception e) {

                System.out.println("EXCEPTION: while generating pdf : "+e);
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM