我只是在做一个测试,我想打印一些静态文本,但它不能保存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();
}
}
当它保存在文件中时,我得到一个空白页面。我认为这与数据源有关,但我无法弄清楚是什么。
答案 0 :(得分:0)
试试这个jrxml。它会对你有用。
<?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" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">
<detail>
<band height="20">
<staticText>
<reportElement x="20" y="0" width="200" height="20"/>
<textElement/>
<text><![CDATA[If you don't see this, it didn't work
]]></text>
</staticText>
</band>
</detail>
</jasperReport>
...享受