将报告导出为 PDF 时更改字体 [英] When export a report to PDF change the font

查看:30
本文介绍了将报告导出为 PDF 时更改字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Jaspersoft Studio 5.2,我使用 Courier New 字体做了一个报告,当我将其导出为 PDF 时,它会将字体更改为 Arial.

I'm using Jaspersoft Studio 5.2, and I did a report with Courier New font, and when I exports this to PDF, it's change the font to Arial.

我只使用 Studio 工具.当我预览报告时没问题,但当我导出时却发生了.

I'm using just the Studio tool. When I preview the report is all right, but when I export it's happens.

我可以用Courier New字体导出的报告做什么?

What can I do with my report to export with Courier New font?

我在报告中使用的 textField 模型:

My textField model that I'm using in report:

<textField pattern="dd/MM/yyyy  HH:mm:ss">
    <reportElement uuid="f50b279a-b480-498f-8af7-be7e23c4b80b" x="415" y="11" width="105" height="10"/>
    <textElement>
        <font fontName="Courier New" size="8"/>
    </textElement>
    <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>

推荐答案

你应该使用字体扩展机制.

您应该使用 Window -> Preferences 对话框创建一个新字体:

You should create a new font with Window -> Preferences dialog:

使用 Font Family 对话框,您可以为您的字体设置 ttf 文件:

With Font Family dialog you can set ttf file for your font:

您应该在上下文菜单的帮助下创建一个新样式:

You should create a new style with help of context menu:

之后,您可以为此样式设置字体:

After that you can set font for this style:

之后你就可以使用这个新样式了:

And after that you can use this new style:

jrxml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="test_courier" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2010b76c-0fe5-4a27-9c86-6846a6f9cc6a">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
    <style name="CustomFont" fontName="Courier New"/>
    <queryString>
        <![CDATA[select task from tasks]]>
    </queryString>
    <field name="TASK" class="java.lang.String"/>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement uuid="9205f787-f3b4-4b21-b2d9-19f52824e187" style="CustomFont" x="280" y="36" width="70" height="20"/>
                <textElement/>
                <text><![CDATA[Title]]></text>
            </staticText>
        </band>
    </title>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement uuid="f23e8674-c45d-4dc7-92f3-93e5d0b41c16" style="CustomFont" x="0" y="0" width="70" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{TASK}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

Studio 中的报告设计:

结果将是(由 Jaspersoft Studion 生成并在 Adobe Reader 中打开的pdf 文件):

And the result will be (pdf file generated by Jaspersoft Studion and opened in Adobe Reader):

注意:

您可以在此处找到有关字体扩展的更多信息

You can find more info about Font Extensions here

这篇关于将报告导出为 PDF 时更改字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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