简体   繁体   English

Jasper报告将字体大小问题导出为pdf

[英]Jasper reports font size issue exporting to pdf

I'm using Jaspersoft Studio 5.6. 我正在使用Jaspersoft Studio 5.6。

It displays correctly in Jaspersoft Studio in Design view. 它在“设计”视图中的Jaspersoft Studio中正确显示。 In Preview view it is also correctly displayed (using java or pdf). 在预览视图中,它也正确显示(使用java或pdf)。
When I execute the report from my Java application the three texts are displayed at the same size. 当我从Java应用程序执行报告时,三个文本以相同的大小显示。

I noticed that Bold and Italic works fine but if I change the font (DejaVu, Arial, Times new roman, etc) that is also ignored. 我注意到Bold和Italic工作正常,但是如果我改变字体(DejaVu,Arial,Times new roman等)也会被忽略。 In the report generated by my application I always get the same font. 在我的应用程序生成的报告中,我总是得到相同的字体。

What is failing? 什么失败了? Am I forgetting any configuration option? 我忘记了任何配置选项吗?

The example mixes static fields and text fields just to test. 该示例混合静态字段和文本字段以进行测试。

EDIT: 编辑:

It seems like I found a "solution" (wich has side effects). 似乎我发现了一个“解决方案”(具有副作用)。

I was generating the report like this: 我正在生成这样的报告:

JasperRunManager.runReportToPdfStream(stream, outStream, params, datasource);

Now, generating in this way the size of the texts are correct in the generated pdf: 现在,以这种方式生成文本的大小在生成的pdf中是正确的:

JasperReport jasperReport = JasperCompileManager.compileReport("my/report.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, datasource);
JasperExportManager.exportReportToPdfStream(jasperPrint, outStream);

The font type however is not correct. 但字体类型不正确。

The side effect, I think, is that JasperRunManager.runReportToPdfStream does not load the report into memory while JasperFillManager.fillReport does. 副作用,我想,是JasperRunManager.runReportToPdfStream不报告加载到内存中,而JasperFillManager.fillReport一样。

Any idea about why JasperRunManager.runReportToPdfStream ignores the font size? 有关为什么JasperRunManager.runReportToPdfStream忽略字体大小的任何想法?

Any idea about why the other way is ignoring the font type? 有关为什么另一种方式忽略字体类型的任何想法? Both JSS and my java application are on the same Windows machine (so the fonts must be available to both). JSS和我的java应用程序都在同一台Windows机器上(因此两者都必须使用这些字体)。

Any advise to avoid loading into memory the whole report? 有什么建议避免将整个报告加载到内存中吗?

<?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="subinforme_pag_1" pageWidth="802" pageHeight="552" orientation="Landscape" columnWidth="802" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="c6f5d08f-f28b-4c77-8523-5cf4746cdcf2">
    <queryString language="SQL">
        <![CDATA[]]>
    </queryString>
    <detail>
        <band height="551" splitType="Stretch">
            <textField>
                <reportElement x="0" y="80" width="180" height="40" uuid="50721cba-c082-47de-9abf-effcf1b784dd">
                    <property name="local_mesure_unitheight" value="pixel"/>
                </reportElement>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="4"/>
                </textElement>
                <textFieldExpression><![CDATA["Text Field (size 4)"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="0" width="180" height="40" uuid="05c5129f-f29e-47a1-ad82-4547b51e3d56"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="16"/>
                </textElement>
                <textFieldExpression><![CDATA["Text Field (Size 16)"]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="40" width="180" height="40" uuid="5c69d29b-b168-408d-89aa-c6d527f0cae1">
                    <property name="local_mesure_unitwidth" value="pixel"/>
                    <printWhenExpression><![CDATA[$V{REPORT_COUNT} == 1]]></printWhenExpression>
                </reportElement>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="SansSerif" size="8" isBold="false"/>
                </textElement>
                <text><![CDATA[Static Text (Size 8)]]></text>
            </staticText>
        </band>
    </detail>
</jasperReport>

The problem is when compiled with version 5.6.0. 问题是在使用5.6.0版编译时。

This is solved by compiling with the version 5.5.1 这可以通过使用5.5.1版进行编译来解决

I hope they fix the issue! 我希望他们能解决这个问题!

I've also had this problem. 我也遇到过这个问题。 What you have to do is to upgrade de jasperreport jar in your java web application. 您需要做的是在java Web应用程序中升级de jasperreport jar。 For example, if you use iReport 5.6.0 for designing your report, upgrade your jasperreport.jar to 6.2.1 例如,如果使用iReport 5.6.0设计报表,请将jasperreport.jar升级到6.2.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM