Jasper Report Engine

Jasper Report Engine is an open-sourced tool. You can define jrxml template by iReport designer.

Java Code:
JasperReport jasperReport = JasperCompileManager.compileReport("D:/test.jrxml");
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("htmlContent", getTestString());
JasperPrint jasperPrint = JasperFillManager.
                     fillReport(jasperReport, parameters,new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint,"D:/test.pdf");



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="TEMIP0006" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="minutesContent" class="java.lang.String"/>
	
	<pageHeader>
		<band height="61" splitType="Stretch">
			<textField isStretchWithOverflow="true" isBlankWhenNull="false">
				<reportElement x="37" y="0" width="383" height="42"/>
				<textElement lineSpacing="Single">
					<font fontName="Arial" size="12"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA["page header"]]></textFieldExpression>
			</textField>			
		</band>
	</pageHeader>
	<columnHeader>
		<band height="61" splitType="Stretch">
			<textField isStretchWithOverflow="true" isBlankWhenNull="false">
				<reportElement x="37" y="0" width="383" height="42"/>
				<textElement lineSpacing="Single">
					<font fontName="Arial" size="12"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA["column header"]]></textFieldExpression>
			</textField>
		</band>
	</columnHeader>
	<detail>
			<band height="540">
				<textField isStretchWithOverflow="true" evaluationTime="Now" pattern="" isBlankWhenNull="true">
					<reportElement key="element-1" mode="Opaque" x="68" y="0" width="487" height="500" isPrintWhenDetailOverflows="true" forecolor="#0FFF00" backcolor="#FFFFFF"/>
					<box>
						<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
						<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
						<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
						<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
					</box>
					<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single" markup="html">
						<font fontName="Arial" size="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
					</textElement>
					<textFieldExpression class="java.lang.String"><![CDATA["<html>" +
"<body>" +
(($P{htmlContent} != null) ? String.valueOf($P{htmlContent}) : "") +
"</body>" +
"</html>"]]></textFieldExpression>
				</textField>
				<staticText>
					<reportElement x="40" y="0" width="11" height="15"/>
					<textElement textAlignment="Right"/>
					<text><![CDATA[:]]></text>
				</staticText>
				<staticText>
					<reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="42" height="15"/>
					<textElement>
						<font fontName="Arial"/>
					</textElement>
					<text><![CDATA[Content]]></text>
				</staticText>
			</band>
		</detail>
	<columnFooter>
		<band height="61" splitType="Stretch">
			<textField isStretchWithOverflow="true" isBlankWhenNull="false">
				<reportElement x="37" y="0" width="383" height="42"/>
				<textElement lineSpacing="Single">
					<font fontName="Arial" size="12"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA["column footer"]]></textFieldExpression>
			</textField>
		</band>
	</columnFooter>
	<pageFooter>
		<band height="61" splitType="Stretch">
			<textField isStretchWithOverflow="true" isBlankWhenNull="false">
				<reportElement x="37" y="0" width="383" height="42"/>
				<textElement lineSpacing="Single">
					<font fontName="Arial" size="12"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA["page footer"]]></textFieldExpression>
			</textField>
		</band>
	</pageFooter>
	<summary>
		<band height="61" splitType="Stretch">
			<textField isStretchWithOverflow="true" isBlankWhenNull="false">
				<reportElement x="37" y="0" width="383" height="42"/>
				<textElement lineSpacing="Single">
					<font fontName="Arial" size="12"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA["summary"]]></textFieldExpression>
			</textField>
		</band>
	</summary>
</jasperReport>


你可能感兴趣的:(Engine)