Я настраиваю сервлет для генерации PDF из студии jaspersoft. Как я могу создать заполненный PDF?
Я уже пробовал много решений для генерации PDF, но PDF генерирует с пустым результатом.
Вот код для моего сервлета:
@WebServlet("/JasperServlet")
public class JasperServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public JasperServlet() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
InputStream jrxmlInput = this.getClass().getClassLoader().getResource("payment_receipt_ar_new.jrxml").openStream();
JasperDesign design = JRXmlLoader.load(jrxmlInput);
JasperReport jasperReport = JasperCompileManager.compileReport(design);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap());
JRPdfExporter pdfExporter = new JRPdfExporter();
pdfExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
ByteArrayOutputStream pdfReportStream = new ByteArrayOutputStream();
pdfExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(pdfReportStream));
pdfExporter.exportReport();
System.out.println("size: " + String.valueOf(pdfReportStream.size()) );
response.setContentType("application/pdf");
response.setHeader("Content-Length", String.valueOf(pdfReportStream.size()));
response.addHeader("Content-Disposition", "inline; filename=jasper.pdf;");
OutputStream responseOutputStream = response.getOutputStream();
responseOutputStream.write(pdfReportStream.toByteArray());
responseOutputStream.close();
pdfReportStream.close();
} catch (JRException e) { // TODO Auto-generated
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
и вот здесь payment_receipt_ar_new.jrxml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.10.0.final using
JasperReports Library version 6.10.0-unknown -->
<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="payment_receipt_ar_new" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ace94295-a399-4efe-bad7-5bf5d0e0b3d6">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="logoURL" class="java.lang.String"/>
<parameter name="paymentConfirmationNumberValue" class="java.lang.String"/>
<parameter name="civilIdValue" class="java.lang.String"/>
<parameter name="nameValue" class="java.lang.String"/>
<parameter name="mobileNumberValue" class="java.lang.String"/>
<parameter name="dateOfPaymentValue" class="java.lang.String"/>
<parameter name="paymentTransferValue" class="java.lang.String"/>
<parameter name="totalAmountPaidValue" class="java.lang.String"/>
<parameter name="documentNumberValue" class="java.lang.String"/>
<parameter name="copyrightsYearPeriodAndYear" class="java.lang.String"/>
<parameter name="companyName" class="java.lang.String"/>
<parameter name="footerArabicLine" class="java.lang.String"/>
<parameter name="footerEnglishLine" class="java.lang.String"/>
<parameter name="footerLink1Middle" class="java.lang.String"/>
<parameter name="footerLink2Right" class="java.lang.String"/>
<parameter name="memberCompanyNameFooter" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="136" splitType="Stretch">
<image>
<reportElement x="455" y="0" width="100" height="103" uuid="6e4a551a-60b2-4eb8-91b6-9e7d22520cce"/>
<imageExpression><![CDATA[$P{logoURL}]]></imageExpression>
</image>
<staticText>
<reportElement x="190" y="103" width="165" height="32" uuid="c1897c62-e37e-4009-a0e9-27559519e4e9"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="gss two light" size="14" isBold="true" isUnderline="true"/>
</textElement>
<text><![CDATA[إﻳﺼﺎل اﻟﺪﻓﻊ
]]></text>
</staticText>
</band>
</title>
<detail>
<band height="445" splitType="Stretch">
<staticText>
<reportElement x="436" y="12" width="100" height="20" forecolor="#000000" uuid="3b15c799-76c2-4896-9c48-40e4b261bf65"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="gss two light" size="14"/>
</textElement>
<text><![CDATA[رﻗﻢ ﺗﺄﻛﻴﺪ اﻟﺪﻓﻊ:
]]></text>
</staticText>
<staticText>
<reportElement x="436" y="45" width="100" height="20" uuid="09200ee0-1c47-4c28-9f9e-fabc013363b6"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="gss two light" size="14"/>
</textElement>
<text><![CDATA[رﻗﻢ اﻟﺒﻄﺎﻗﺔ اﻟﻤﺪﻧﻴﺔ:
]]></text>
</staticText>
<staticText>
<reportElement x="436" y="79" width="100" height="20" uuid="7261f6bf-aab1-4492-9823-69e265a6e395"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="gss two light" size="14"/>
</textElement>
<text><![CDATA[اﻻﺳﻢ:]]></text>
</staticText>
<staticText>
<reportElement x="436" y="113" width="100" height="20" uuid="f2bd6cf8-0c9d-4872-aca5-049e3335af79"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="gss two light" size="14"/>
</textElement>
<text><![CDATA[رﻗﻢ اﻟﻤﺤﻤﻮل:
]]></text>
</staticText>
<staticText>
<reportElement x="436" y="148" width="100" height="20" uuid="43bf8d62-2683-4fcb-a51e-8543ade937ce"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="gss two light" size="14"/>
</textElement>
<text><![CDATA[ﺗﺎرﻳﺦ اﻟﺪﻓﻊ:
]]></text>
</staticText>
<staticText>
<reportElement x="436" y="183" width="100" height="20" uuid="24437f8d-abce-4d11-9b72-11daca325dc4"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="gss two light" size="14"/>
</textElement>
<text><![CDATA[رﻗﻢ ﺗﺤﻮﻳﻞ اﻟﺪﻓﻊ:
]]></text>
</staticText>
<staticText>
<reportElement x="409" y="218" width="127" height="20" uuid="f1691a8d-8f9d-4263-975d-36dfb9b8aacd"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="gss two light" size="14"/>
</textElement>
<text><![CDATA[إﺟﻤﺎﻟﻲ اﻟﻤﺒﻠﻎ اﻟﻤﺪﻓﻮع:
]]></text>
</staticText>
<staticText>
<reportElement x="436" y="255" width="100" height="20" uuid="1fe7b546-c1f3-4ef9-a912-14a9fd8a17b4"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="gss two light" size="14" isBold="false"/>
</textElement>
<text><![CDATA[رﻗﻢ اﻟﻮﺛﻴﻘﺔ:
]]></text>
</staticText>
<textField>
<reportElement x="175" y="12" width="180" height="20" uuid="1471f822-9142-4510-9913-b662bc8cd5d5"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="FrieghtSansMedium" size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{paymentConfirmationNumberValue}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="175" y="45" width="180" height="20" uuid="f12577d5-1206-4296-9ca3-b3dd935ad0f6"/>
<textElement textAlignment="Right">
<font fontName="FrieghtSansMedium" size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{civilIdValue}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="175" y="79" width="180" height="20" uuid="13e14a71-57a7-4d4d-a0c2-3ccb192f7cdc"/>
<textElement textAlignment="Right">
<font fontName="gss two light" size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{nameValue}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="175" y="113" width="180" height="20" uuid="6c034d11-ad89-4e5d-883f-573fd316bb7f"/>
<textElement textAlignment="Right">
<font fontName="FrieghtSansMedium" size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{mobileNumberValue}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="175" y="148" width="180" height="20" uuid="0834469d-0336-4b9f-9046-bbfd5d90bbaf"/>
<textElement textAlignment="Right">
<font fontName="FrieghtSansMedium" size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{dateOfPaymentValue}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="175" y="183" width="180" height="20" uuid="789c5215-1ade-4571-9f97-535e8ec56652"/>
<textElement textAlignment="Right">
<font fontName="FrieghtSansMedium" size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{paymentTransferValue}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="175" y="218" width="180" height="20" uuid="2a4590fd-623d-464e-bc8e-9ac6afead097"/>
<textElement textAlignment="Right">
<font fontName="FrieghtSansMedium" size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{totalAmountPaidValue}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="175" y="255" width="180" height="35" uuid="e04d44a7-e628-43c4-b33d-21b28a065323"/>
<textElement textAlignment="Right" markup="html">
<font fontName="FrieghtSansMedium" size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{documentNumberValue}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="126" y="405" width="283" height="20" uuid="eb66e88c-45ad-4ab7-bb8c-10d581410293"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="gss two light" size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{copyrightsYearPeriodAndYear}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="114" y="425" width="311" height="20" uuid="aafa90a1-86a2-4281-95c6-d09b696adb29"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="gss two light" size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{companyName}]]></textFieldExpression>
</textField>
</band>
</detail>
<pageFooter>
<band height="65" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="555" height="20" uuid="ee1bd043-02d8-406a-8cd7-9f14349fec45"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="gss two light"/>
</textElement>
<textFieldExpression><![CDATA[$P{footerArabicLine}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="20" width="555" height="20" uuid="d5fb4ff4-6f94-4161-a3ab-0e35b8702fe9"/>
<textElement verticalAlignment="Middle">
<font fontName="FrieghtSansMedium"/>
</textElement>
<textFieldExpression><![CDATA[$P{footerEnglishLine}]]></textFieldExpression>
</textField>
<line>
<reportElement x="0" y="40" width="555" height="1" uuid="012d5907-5d65-4b3c-926f-5bf08a05b3a1"/>
</line>
<textField>
<reportElement x="0" y="41" width="263" height="20" uuid="05943f07-7173-449b-a658-8f14476097c4"/>
<textElement verticalAlignment="Top" markup="html">
<font fontName="FrieghtSansMedium"/>
</textElement>
<textFieldExpression><![CDATA[$P{memberCompanyNameFooter}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="209" y="41" width="184" height="20" uuid="6b234eeb-bd9c-46db-aa3a-4f242fd0b286"/>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="FrieghtSansMedium"/>
</textElement>
<textFieldExpression><![CDATA[$P{footerLink1Middle}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="393" y="41" width="162" height="20" uuid="482ba13a-d3c8-44fd-87e6-590bd8b2b1b6"/>
<textElement textAlignment="Right" verticalAlignment="Top">
<font fontName="FrieghtSansMedium"/>
</textElement>
<textFieldExpression><![CDATA[$P{footerLink2Right}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
</jasperReport>
Пожалуйста, помогите мне, он генерирует пустой pdf.
Я ожидаю, что вывод покажет заполненный pdf с некоторыми статическими и параметрическими данными. Но сейчас он генерирует пустой PDF.