JasperReports直接打印到打印机有不同的字体质量

时间:2016-11-08 15:09:53

标签: java fonts jasper-reports

我编写了Java代码,调用 JRPrintServiceExporter 直接将 JasperReports 报告打印到打印机,我在Fields object上获得了不同的字体质量,如下图所示(红色矩形)。当我将字体更改为另一种字体时,我仍然得到相同的结果。显示字体不应该不同,因为我将数据列表传递给Fields对象,然后它应该以相同的字体显示。有人可以指出我正确的方向吗?

我使用 JasperReports jar版本6.3.0并使用 Jaspersoft Studio 6.3 来构建一个jasper文件。

Print detail

我的代码:

    JRPrintServiceExporter exporter = new JRPrintServiceExporter();

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, selectedPrintService);
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, selectedPrintService.getAttributes());
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);

    exporter.exportReport();

我的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="ReceiptTanapond" pageWidth="648" pageHeight="792" columnWidth="648" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="7f9b54a3-0906-494e-a140-dc9db77eeea1">
    <property name="ireport.scriptlethandling" value="0"/>
    <property name="ireport.encoding" value="UTF-8"/>
    <import value="net.sf.jasperreports.engine.*"/>
    <import value="java.util.*"/>
    <import value="net.sf.jasperreports.engine.data.*"/>
    <parameter name="CustomerName" class="java.lang.String"/>
    <parameter name="Address" class="java.lang.String"/>
    <parameter name="InvoiceNo" class="java.lang.String"/>
    <parameter name="TotalPrice" class="java.math.BigDecimal"/>
    <parameter name="StringDate" class="java.lang.String"/>
    <parameter name="NetPrice" class="java.math.BigDecimal"/>
    <parameter name="TermOfPayment" class="java.lang.String"/>
    <parameter name="DueDate" class="java.lang.String"/>
    <parameter name="ReferenceQuotation" class="java.lang.String"/>
    <parameter name="DeliverDestination" class="java.lang.String"/>
    <parameter name="ReceiptRemark" class="java.lang.String"/>
    <parameter name="NetPriceThai" class="java.lang.String"/>
    <parameter name="AddedTax" class="java.lang.String"/>
    <parameter name="VatPrice" class="java.math.BigDecimal"/>
    <parameter name="ReceiptDate" class="java.lang.String"/>
    <field name="productName" class="java.lang.String"/>
    <field name="quantity" class="java.lang.Integer"/>
    <field name="unitName" class="java.lang.String"/>
    <field name="price" class="java.math.BigDecimal"/>
    <field name="summaryPrice" class="java.math.BigDecimal"/>
    <title>
        <band>
            <textField evaluationTime="Report">
                <reportElement x="0" y="0" width="100" height="0" uuid="c472a425-b05d-4025-845b-2c6f952872b9">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <textFieldExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}.put("PAGE_CURRENT", 0)]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <columnHeader>
        <band height="329" splitType="Stretch">
            <textField evaluationTime="Report">
                <reportElement x="0" y="0" width="100" height="0" uuid="d4d50ef2-07e1-4175-9275-9b9daf130baa"/>
                <textFieldExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}.put("PAGE_CURRENT", Integer.parseInt($P{REPORT_PARAMETERS_MAP}.get("PAGE_CURRENT").toString()) + 1)]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band height="19" splitType="Prevent">
            <textField isBlankWhenNull="true">
                <reportElement key="textField" x="31" y="2" width="30" height="16" uuid="1af42bb2-ebf7-4785-9c9d-654befe1b9d9"/>
                <box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
                    <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="Center" verticalAlignment="Middle" markup="styled">
                    <font fontName="THSarabun" size="14" isBold="false"/>
                    <paragraph lineSpacing="Single" lineSpacingSize="1.0" spacingAfter="0"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" evaluationTime="Auto" pattern="" isBlankWhenNull="true">
                <reportElement key="textField" x="63" y="2" width="284" height="16" uuid="ff6cfca3-367c-4c8a-ae43-9e36a68c3ed4"/>
                <box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
                    <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="Middle" markup="styled">
                    <font fontName="THSarabun" size="14" isBold="false"/>
                    <paragraph lineSpacing="Single" lineSpacingSize="1.0" spacingAfter="0"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{productName}]]></textFieldExpression>
            </textField>
            <textField pattern="#,##0" isBlankWhenNull="true">
                <reportElement key="textField" x="347" y="2" width="46" height="16" uuid="7f94f789-9659-4ada-a470-4479f7cb59d0"/>
                <box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
                    <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="Right" verticalAlignment="Middle" markup="styled">
                    <font fontName="THSarabun" size="14" isBold="false"/>
                    <paragraph lineSpacing="Single" lineSpacingSize="1.0" spacingAfter="0"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{quantity}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement key="textField" x="395" y="2" width="38" height="16" uuid="04e41b32-66b8-4d6b-8ab9-e9db2ae4bb77"/>
                <box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
                    <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="Center" verticalAlignment="Middle" markup="styled">
                    <font fontName="THSarabun" size="14" isBold="false"/>
                    <paragraph lineSpacing="Single" lineSpacingSize="1.0" spacingAfter="0"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{unitName}]]></textFieldExpression>
            </textField>
            <textField pattern="" isBlankWhenNull="true">
                <reportElement key="textField" x="433" y="2" width="53" height="16" uuid="7f47e750-bac3-4af6-9956-99dd7a3f13da"/>
                <box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
                    <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="Right" verticalAlignment="Middle" markup="styled">
                    <font fontName="THSarabun" size="14" isBold="false"/>
                    <paragraph lineSpacing="Single" lineSpacingSize="1.0" spacingAfter="0"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
                <patternExpression><![CDATA[$F{price}.doubleValue() > 99999.99d ? "#,##0" : "#,##0.00"]]></patternExpression>
            </textField>
            <textField pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement key="textField" x="486" y="2" width="82" height="16" uuid="4a2bdf26-c1a7-4815-a8df-b19e8ad01489"/>
                <box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
                    <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="Right" verticalAlignment="Middle" markup="styled">
                    <font fontName="THSarabun" size="14" isBold="false"/>
                    <paragraph lineSpacing="Single" lineSpacingSize="1.0" spacingAfter="0"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{summaryPrice}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

0 个答案:

没有答案
相关问题