我有一个这样的模板:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.3.final using JasperReports Library version 6.4.3 -->
<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="Invoice" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4eedbb89-b4f6-4469-9ab6-f642a1688cf7">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="localdb"/>
<style name="Title" forecolor="#FFFFFF" fontName="Times New Roman" fontSize="50" isBold="false" pdfFontName="Times-Bold"/>
<style name="SubTitle" forecolor="#CCCCCC" fontName="Times New Roman" fontSize="18" isBold="false" pdfFontName="Times-Roman"/>
<style name="Column header" forecolor="#666666" fontName="Times New Roman" fontSize="14" isBold="true"/>
<style name="Detail" mode="Transparent" fontName="Times New Roman"/>
<style name="Row" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
<style mode="Opaque" backcolor="#EEEFF0"/>
</conditionalStyle>
</style>
.....
<queryString language="SQL">
<![CDATA[SELECT * from test]]>
</queryString>
此代码用于生成:
@Autowired
private DataSource datasource;
@RequestMapping(value = "invoice", produces = MediaType.APPLICATION_PDF_VALUE)
public ResponseEntity createInvoice() throws JRException, SQLException, IOException {
InputStream resourceAsStream = PDFReporter.class.getResourceAsStream(BILL_JRXML);
assert resourceAsStream != null : "No " + BILL_JRXML + " found!";
JasperReport r = JasperCompileManager.compileReport(resourceAsStream);
Map<String, Object> parameters = new HashMap();
Connection connection = datasource.getConnection();
JasperPrint print = JasperFillManager.fillReport(r, parameters, connection);
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(print));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(bos));
exporter.exportReport();
connection.close();
return new ResponseEntity(bos.toByteArray(), HttpStatus.OK);
}
但结果是PDF只有一页空白。
我下载PDF并检查错误,但PDF有引导%PDF-1.4
和引出%%EOF
。
如果我在Jaspersoft Studio中这样做,那就很好。
有什么问题?
答案 0 :(得分:0)
哦,表test
是空的。我从没想过会有空页!