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

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

问题描述

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

我试过的是:
工具 - >选项 - >字体



<$ p

步骤1: $ p> 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)字体
2)示例字体



步骤2:irfonts.xml



默认情况下,jasper报告给出了这个文件中的其他字体,我把它改成了。

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



第三步:



我得到的结果是:
હીપ્સ
我真正想要的是:
હિપ્સ



<花了一些时间后,我才知道当你在Jasper报告模板中渲染一个页面时,字体正在按照需要工作,但是当你将它导出到PDF时,它会改变原因所有的字体都会经过itext pdf engine。 >

现在,技巧是itext没有字体我目前正在使用。

有什么办法可以我实现这一点。
$ b 注意:
它不是使用Java创建的。我是一个Oracle数据库开发人员,仅使用工具创建并使用工具边界进行打印。 p>

也跟着这个博客,但它是在java中,所以不知道在哪里做出改变。
Java博客


示例代码:

 < textField> 
< reportElement x =111y =26width =100height =20uuid =5a471a16-de7b-4f55-9c9f-b01d37938b9f/>
< textElement>
< / textElement>
< textFieldExpression><![CDATA [$ F {my_column_values}]]>< / textFieldExpression>



有些类似的问题也是在堆栈溢出,但他们都使用java调用和打印。

所以,我可以更改itext库或任何其他解决方法将罚款。
我是如何创建的:

1)贾斯珀报告 2016/04 / printing-with-jasper-soft-ireport.htmlrel =nofollow> Jasper

我创建了一个新的问题只与itext相关为建议 by @AmedeeVanGasse我会在这个显示如何 Alexey Subach答案可以在jasper报告中实现。


注意:Alexy Subach指出执行真的很差
,而你可能没有期望得到正确的结果




策略1:您只需要导出pdf



添加到classpath中的itext5库(注意最新的jasper报告使用itext2,您将需要两者)并将 GujaratiLigaturizer 类定义为一个变量,然后在每次输出时处理文本。

示例

 <?xml version =1.0encoding =UTF-8?> 
< jasperReport xmlns =http://jasperreports.sourceforge.net/jasperreportsxmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation =http:当无数据类型=AllSectionsNoDetail时, columnWidth =111leftMargin =20rightMargin =20topMargin =20bottomMargin =20uuid =2347c131-1884-430a-b77f-59f08f896c8a>
< variable name =gclass =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 =0y =0width =200height =25uuid =ee49d149-394b-4ac6-a0a2-6d207b0c8d89/>
< textElement>
< / textElement>
< textFieldExpression><![CDATA [$ V {g} .process(\\\હ\\\િ\\\પ\\\્\\\સ)]]>< / textFieldExpression>
< / textField>
< / band>
< / title>
< / jasperReport>




重要提示:只有pdf导出将是正确的!

Pdf结果





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



<$ p $ JasperPrint print = JasperFillManager.fillReport(report,new HashMap< String,Object>(),theDatasource);
IndicLigaturizer g = new GujaratiLigaturizer(); (JRPrintPage页面:print.getPages()){
for(JRPrintElement元素:page.getElements()){
if(元素instanceof JRTemplatePrintText){
JRTemplatePrintText text = (JRTemplatePrintText)元件;
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("\u0ab9\u0abf\u0aaa\u0acd\u0ab8")]]></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天全站免登陆