如何将古吉拉特-印度语字体导出为 pdf? [英] How to export fonts in Gujarati-Indian Language to pdf?

查看:27
本文介绍了如何将古吉拉特-印度语字体导出为 pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在从 jasper 报告 5.1 版导出的 PDF 报告中显示不同的字体(古吉拉特-印度语).

我尝试过的:运行工具后打开以下位置第 1 步:

工具 -> 选项 -> 字体

net.sf.jasperreports.default.font.name=Arial Unicode MS - 默认字体名称.net.sf.jasperreports.default.font.size=10 - 默认字体大小.net.sf.jasperreports.default.pdf.font.name=Identity-H - 默认的 PDF 字体.net.sf.jasperreports.default.pdf.encoding=UTF-8 - 默认的 PDF 字符编码.net.sf.jasperreports.default.pdf.embedded=true - 默认情况下不嵌入 PDF 字体

安装了字体Arial Unicode MS"并创建了它的jar文件.jar文件存在于jasper报告的类路径中.

链接如下:1)

策略二:导出pdf时切换文本

在通过java导出前如果需要生成pdf,在导出前切换JasperPrint对象中的文本

JasperPrint print = JasperFillManager.fillReport(report, new HashMap(), theDatasource);IndicLigaturizer g = new GujaratiLigaturizer();for (JRPrintPage 页面:print.getPages()) {for (JRPrintElement 元素:page.getElements()) {如果(JRTemplatePrintText 的元素实例){JRTemplatePrintText text = (JRTemplatePrintText)element;text.setText(g.process(text.getText()));}}}

I wanted to show different fonts(Gujarati-Indian Language) in Exported report of PDF from jasper report version 5.1.

What i have tried : After Running Tool open below location Step 1:

Tools -> Option -> Fonts

net.sf.jasperreports.default.font.name=Arial Unicode MS - the default     font name.
net.sf.jasperreports.default.font.size=10 - the default font size.
net.sf.jasperreports.default.pdf.font.name=Identity-H - the default PDF font.
net.sf.jasperreports.default.pdf.encoding=UTF-8 - the default PDF character encoding.
net.sf.jasperreports.default.pdf.embedded=true - by default PDF fonts are not embedded

Fonts "Arial Unicode MS" installed and its jar file also created.Jar files exits in class path of jasper report.

Link Followed :1) Fonts 2) Sample fonts

Step 2 : irfonts.xml

By default jasper report gives other fonts in this file i changed it to.

<fontFamily name="Arial Unicode MS">
<normal>net/sf/jasperreports/fonts/dejavu/ArialUnicodeMS.ttf</normal>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>

Step 3:

What result i am getting: હીપ્સ What i actually wanted: હિપ્સ

After Spending some time i came to know when you render a page in Template of Jasper report Fonts are working as per need but when you export it to pdf it changes Reason all the fonts goes through "itext pdf engine".

Now, trick is itext do not have fonts what I am currently using.

Is there any way by which I can achieve this.

Notes: It's not created using Java.I'm a Oracle Database Developer so created using tool only and printing withing tools boundaries.

Followed this blog also but it is in java so don't know where make changes. Blog of java

Sample Code:

<textField>
<reportElement x="111" y="26" width="100" height="20" uuid="5a471a16-de7b-4f55-9c9f-b01d37938b9f"/>
 <textElement>
    <font fontName="Arial Unicode MS" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{my_column_values}]]></textFieldExpression>

Some the similar questions are also in stack overflow but all of them uses java to call and print.

So, can I change itext library or any other workaround will be fine. How i created :

1) Jasper report

2) Jasper

解决方案

I create a new question only related to itext as suggested by @AmedeeVanGasse I will show in this anwer how Alexey Subach answer could be implement in jasper reports.

NOTE: Alexy Subach states that "the implementation is really poor and you cannot expect to get correct results with it"

Strategy 1: You only need to export pdf

Add to classpath itext5 library (note latest jasper report use itext2, you will need both) and define the GujaratiLigaturizer class as an variable, then process your text every time you need to output.

Example

<?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="FontTest" columnCount="5" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="111" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2347c131-1884-430a-b77f-59f08f896c8a">
    <variable name="g" class="com.itextpdf.text.pdf.languages.GujaratiLigaturizer">
        <initialValueExpression><![CDATA[new com.itextpdf.text.pdf.languages.GujaratiLigaturizer()]]></initialValueExpression>
    </variable>
    <title>
        <band height="25">
            <textField pattern="">
                <reportElement x="0" y="0" width="200" height="25" uuid="ee49d149-394b-4ac6-a0a2-6d207b0c8d89"/>
                <textElement>
                    <font fontName="Arial Unicode MS" size="14"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{g}.process("u0ab9u0abfu0aaau0acdu0ab8")]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

Important notice: only the pdf export will be correct!

Pdf result

Strategy 2: Switch the text if you export to pdf

Before exporting via java if you need to generate pdf, switch the text in the JasperPrint object before exporting

JasperPrint print = JasperFillManager.fillReport(report, new HashMap<String, Object>(), theDatasource);
IndicLigaturizer g = new GujaratiLigaturizer();
for (JRPrintPage page : print.getPages()) {
    for (JRPrintElement element : page.getElements()) {
        if (element instanceof JRTemplatePrintText){
            JRTemplatePrintText text = (JRTemplatePrintText)element;
            text.setText(g.process(text.getText()));
        }
    }
}

这篇关于如何将古吉拉特-印度语字体导出为 pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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