如何删除使用JasperReports(jrxml)生成的PDF中不必要的包装? [英] How to remove unnecessary wrapping in PDF, generated using JasperReports (jrxml)?

查看:179
本文介绍了如何删除使用JasperReports(jrxml)生成的PDF中不必要的包装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jasper报告生成我的PDF报告。我在 jrxml 文件中使用以下 textField 配置。

 < textField isStretchWithOverflow =trueisBlankWhenNull =true> 
< reportElement uuid =ec0e2f1f-82d6-46fd-ba68-394be7f6b015positionType =FloatstretchType =RelativeToTallestObjectisPrintRepeatedValues =falsemode =Transparentx =0y =0 width =100height =16isPrintInFirstWholeBand =trueisPrintWhenDetailOverflows =true/>
< box topPadding =2leftPadding =5bottomPadding =0rightPadding =0>
< pen lineColor =#757575/>
< topPen lineWidth =0.0/>
< leftPen lineWidth =1.0/>
< bottomPen lineWidth =1.0/>
< rightPen lineWidth =0.0/>
< / box>
< textElement textAlignment =leftverticalAlignment =Topmarkup =none>
< font size =11/>
< paragraph lineSpacing =Single/>
< / textElement>
< textFieldExpression><![CDATA [$ F {firstName}]]>< / textFieldExpression>
< / textField>

导出PDF时,它会显示以下屏幕截图中给出的记录。请参阅第一个记录,第二个中没有单个字符。即使它表现得像文本包装。我认为必须有任何解决方案。如果有人解决了这个问题,请帮助我。

了解详情。



fontName pdfFontName



例如,假设您在Windows环境中工作并具有适当的权限(否则只需调整路径以指向您的字体副本),您可以像这样使用Arial:

 < textField isStretchWithOverflow =trueisBlankWhenNull =true> 
< reportElement positionType =FloatstretchType =RelativeTallTallestObjectisPrintRepeatedValues =falsemode =Transparentx =0y =0width =100height =16isPrintInFirstWholeBand = trueisPrintWhenDetailOverflows =trueuuid =e4335197-b9f6-4d24-9ea0-ef582bcc8393/>
< box topPadding =2leftPadding =5bottomPadding =0rightPadding =0>
< pen lineColor =#757575/>
< topPen lineWidth =1.0/>
< leftPen lineWidth =1.0/>
< bottomPen lineWidth =1.0/>
< rightPen lineWidth =1.0/>
< / box>
< textElement textAlignment =leftverticalAlignment =Topmarkup =none>
< font fontName =Arialsize =11pdfFontName =c:\ Windows\Fonts \ arial.ttfisPdfEmbedded =true/>
< / textElement>
< textFieldExpression><![CDATA [$ F {firstName}]]>< / textFieldExpression>
< / textField>

PDF是JasperReports中的一个特例,因为与大多数其他输出格式(使用系统字体)相比)PDF查看器最重要的是使用每个PDF查看器必须提供的标准14种字体之一或嵌入相应PDF文档中的字体;因此,PDF文件生成略有不同。



字体扩展名



更清洁的方法要求您编写文件使用所有相关信息定义您的字体系列,例如

 <?xml version =1.0encoding =UTF-8 ?> 
< fontFamilies>
< fontFamily name =Verdana>
< normal> admin / plugins / ireport / config / fonts / verdana.ttf< / normal>
< bold> admin / plugins / ireport / config / fonts / verdanab.ttf< / bold>
< italic> admin / plugins / ireport / config / fonts / verdanai.ttf< / italic>
< boldItalic> admin / plugins / ireport / config / fonts / verdanaz.ttf< / boldItalic>
< pdfEncoding> Identity-H< / pdfEncoding>
< pdfEmbedded> true< / pdfEmbedded>
< / fontFamily>
< / fontFamilies>

(从该文件引用的字体(verdana * .ttf)是MicrosoftTrueType核心的一部分用于Web集合的字体。可以在eula.html中找到它们使用的许可协议,目前可以在 http://www.microsoft.com/typography/fontpack/eula.htm 。)



然后你需要告诉JasperReports字体扩展从该文件中检索其信息,如 JasperReports字体扩展示例,即在根软件包中提供 jasperreports_extension.properties 文件,其中包含

  net.sf.jasperreports.extension.registry.factory.simple.font.families = net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory 
net.sf. jasperreports.extensio n.simple.font.families.dejavu = my_path / fonts.xml

(指向字体) .xml是上面提到的文件。)


I am using jasper report for generating my PDF report. I use following textField configuration in jrxml file.

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement uuid="ec0e2f1f-82d6-46fd-ba68-394be7f6b015" positionType="Float" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" mode="Transparent" x="0" y="0" width="100" height="16" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/>
                    <box topPadding="2" leftPadding="5" bottomPadding="0" rightPadding="0">
                        <pen lineColor="#757575"/>
                        <topPen lineWidth="0.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="0.0"/>
                    </box>
                    <textElement textAlignment="Left" verticalAlignment="Top" markup="none">
                        <font size="11"/>
                        <paragraph lineSpacing="Single"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
                </textField>

When export PDF, It will show me records like given in below screen-shot. See in first record, there is no single character in second row. Even though it is behaving like text wrapping. I think there must be any solution. Please help me if anybody resolved this issue.
Here I am giving link for whole PDF file.

解决方案

The sample PDF uses the font Helvetica (supplied by the PDF viewer) which surely is not used by JasperReports when generically pre-compiling the Report.

If different fonts (having different font metrics) are used like this, fields in the output may turn out to be too big or too small. Thus, I'd advice to explicitly set the font, and to do so using both the fontName and the pdfFontName attributes indicating the same TTF font. Alternatively this can be done more cleanly using JasperReports font extensions. Cf. JasperReports - Fonts Sample for details.

fontName and pdfFontName

E.g., assuming that you are working in a Windows environment and have the appropriate permissions (otherwise simply adapt the path to point to your copy of the font), you can use Arial like this:

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
    <reportElement positionType="Float" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" mode="Transparent" x="0" y="0" width="100" height="16" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true" uuid="e4335197-b9f6-4d24-9ea0-ef582bcc8393"/>
    <box topPadding="2" leftPadding="5" bottomPadding="0" rightPadding="0">
        <pen lineColor="#757575"/>
        <topPen lineWidth="1.0"/>
        <leftPen lineWidth="1.0"/>
        <bottomPen lineWidth="1.0"/>
        <rightPen lineWidth="1.0"/>
    </box>
    <textElement textAlignment="Left" verticalAlignment="Top" markup="none">
        <font fontName="Arial" size="11" pdfFontName="c:\Windows\Fonts\arial.ttf" isPdfEmbedded="true"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
</textField>

PDF is a special case in JasperReports because in contrast to most other output formats (which use the system fonts) PDF viewers foremost use one of the standard 14 fonts every PDF viewer must supply or fonts embedded in the respective PDF document; therefore, PDF file generation differs a bit.

font extensions

The cleaner approach requires you to write a file defining your font families with all relevant information, e.g.

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
    <fontFamily name="Verdana">
        <normal>admin/plugins/ireport/config/fonts/verdana.ttf</normal>
        <bold>admin/plugins/ireport/config/fonts/verdanab.ttf</bold>
        <italic>admin/plugins/ireport/config/fonts/verdanai.ttf</italic>
        <boldItalic>admin/plugins/ireport/config/fonts/verdanaz.ttf</boldItalic>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
    </fontFamily>
</fontFamilies>

(The fonts referenced from that file (verdana*.ttf) are part of the Microsoft "TrueType core fonts for the Web" collection. The license agreement for their use can be found in eula.html which can currently (as of 2011-04-01) be found at http://www.microsoft.com/typography/fontpack/eula.htm.)

Then you need to tell JasperReports font extensions to retrieve its information from that file as described in the JasperReports font extension sample, i.e. by providing a jasperreports_extension.properties file in the root package containing

net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory 
net.sf.jasperreports.extension.simple.font.families.dejavu=my_path/fonts.xml 

(the pointed-to fonts.xml is the file mentioned above.)

这篇关于如何删除使用JasperReports(jrxml)生成的PDF中不必要的包装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆