我只是在做一个测试,我想打印一些静态文本但它不保存 pdf。
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="FirstReport">
<detail>
<band height="20">
<staticText>
<reportElement x="20" y="0" width="200" height="20" />
<text>
<![CDATA[If you don't see this, it didn't work]]>
</text>
</staticText>
</band>
</detail>
</jasperReport>
代码是:
public class PDF {
public void genereazaRaport() {
try {
InputStream input = new FileInputStream(new File("jrxml/test.jrxml"));
JasperDesign jasperDesign = JRXmlLoader.load(input);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
//Map<String, Object> parameters = new HashMap<String, Object>();
//parameters.put("Titlu Raport", "PDF JasperReport");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, new JREmptyDataSource());
OutputStream out = new FileOutputStream(new File("raport/raport.pdf"));
JasperExportManager.exportReportToPdfStream(jasperPrint, out);
} catch (FileNotFoundException e) {
System.out.println("File not found");
} catch (JRException e) {
System.out.println("JRException");
}
}
public static void main(String[] args) {
new PDF().genereazaRaport();
}
}
当它保存在文件中时,我得到一个空白页。我认为这与数据源有关,但我不知道是什么。