使用 iReport 创建 pdf 时使用自定义字体 [英] Use custom fonts when creating pdf using iReport

查看:43
本文介绍了使用 iReport 创建 pdf 时使用自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iReport 版本:3.7.1

iReport Version : 3.7.1

我通过两种方式解决了这个问题.

I approached this problem in two ways.

我的第一种方法

我正在 iReport 中创建一个 pdf 页面,并且我将其中一个字段(来自数据库)设置为字体 Gujarati-Salarl(印度地区语言的字体).

I am creating a pdf page in iReport and I have one of the fields (from database) set to a font Gujarati-Salarl (A font for a regional language of India).

该字体在iReport的字体列表中可用.当我点击预览时,我得到了所需的输出,字段采用所需的字体样式.

This font is available in the font list of iReport. When I hit preview I get the desired output , with the field in the required font style.

到这里一切都很好.

但是生成的pdf文件仍然包含相同的英文原始字体.

But the pdf file generated still contains the same original font in English characters.

无论我是从应用程序还是从 JAVA 文件调用报告,结果都是一样的.

The result is same whether i call the report from the application or from a JAVA file.

经过一番研究,我发现了这个,第二种方法

After a bit of study I found this , a second method

JRProperties.setProperty("net.sf.jasperreports.default.pdf.font.name", "C:\Gujrati-Saral-1.ttf");

这会将 pdf 的字体设置为提供的 ttf 字体,但现在整个 pdf 都采用 Guarati-saral 字体不是我要找的..

This sets the font of the pdf to the ttf font provided but now the entire pdf comes in the Guarati-saral font which is not what I am looking for..

有没有一种方法可以将这种字体专门应用于某个特定领域?

Is there a way to specifically apply this font only to that one particular field?

当采用第二种方法时,是否有一种方法可以不将字体 Guarati-saral 应用于除必需字段之外的所有其他字段?

when going by the second method is there a way to not applying the font Guarati-saral to all other fields except the required one ?

推荐答案

您应该使用 Font Extensions 机制.

在创建字体并将其导出为 jar 文件后,您应该将生成的 jar 文件添加到应用程序类路径中.

After creating the font and exporting it as a jar file you should add generated jar file to the application classpath.

a) 在 iReport 中创建新字体(通过选项 -> 字体 -> 安装字体"按钮)

a) Creating new font in iReport (via Options -> Fonts -> "Install Font" Button)

b) 将新字体(或现有字体)导出为 iReport 中的 jar 文件(通过选项 -> 字体 ->导出为扩展"按钮)

a) 在 JasperReports Studio 中创建新字体(通过窗口 -> 首选项 -> JasperStudio -> 字体 -> 添加"按钮)

a) Creating new font in JasperReports Studio (via Window -> Preferences -> JasperStudio -> Fonts -> "Add" Button)

b) 配置您的字体

c) 用你的字体创建 JAR

您可以找到有关使用 Font Extensions 的更多信息 这里.

You can find more information about using Font Extensions here.

这篇关于使用 iReport 创建 pdf 时使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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