Unicode(Maori Macrons) issue with PDF

I have an issue with Maori Macrons - I am running a report with the code below for a field that needs to display Maori Macrons. It displays fine within JRViewer, and its fine when I export it to word or excel, but craps out when I export to PDF. I've pasted my code below for that field. Any suggestions welcome. 

below is the code for the text field:::

Also, iReport documentation conatains a sentence that says that they have a rich set of encoding types, but which one is best to use for Unicode? I see a Identity-H and -V which does not solve the problem. Also, all fields in my report are consistent in terms of the PDF encoding and PDF font and PDF embedded values. 

Code:
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" 
           evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
    <reportElement x="9" y="25" width="523" height="12" key="textField-7"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None"
         leftBorderColor="#000000" leftPadding="2"
         rightBorder="None" rightBorderColor="#000000"
         rightPadding="2" bottomBorder="None"
         bottomBorderColor="#000000"/>
    <textElement>
        <font fontName="Arial" pdfFontName="Helvetica" size="10"
              isPdfEmbedded ="true" pdfEncoding ="Cp1252"/>
    </textElement>
    <textFieldExpression   class="java.lang.String">
        <![CDATA[$F{V_PERSON_ADDRESSING_NAME}]]>
    </textFieldExpression>
</textField>

prashanth.talkad's picture
Joined: Feb 4 2008 - 8:58am
Last seen: 15 years 7 months ago

18 Answers:

The problem is with the PDF font u have selected. Please select a font having a unicode characters. For example Arial_UnicodeMS. You want find this in the normal list of PDF fonts. But you can set the "windows fonts" path in the classpath of iReport. After doinf this you will get this font name. Try one of the Identity-H or Identity-V. it will work wonders. Please see the attachement

shrije's picture
2687
Joined: Apr 5 2008 - 8:59am
Last seen: 9 years 6 months ago
hi thanks for the suggestion. i've set the font path in iReport to contain the windows font dir and can also see the font "Arial.....Uni...." and changed the encoding to Identity-H and V , but this throws an exception when i try export to DF saying "cannot load font ,...." duuno why....any ideas?
prashanth.talkad's picture
Joined: Feb 4 2008 - 8:58am
Last seen: 15 years 7 months ago

You have load the font from the iReport menu Options->ReloadFonts. I hope u have selected the font from the list and not just entered over there.

shrije's picture
2687
Joined: Apr 5 2008 - 8:59am
Last seen: 9 years 6 months ago

yes I did load the "C:\windows\fonts" into the classpath, then I set the Font Path to include the new path and I see the list of fonts in the drop down list for PDF font. Now I chose the "ARIALUNI.TTF" and "Identity-H" for encoding and ran the report in JRViewer. The PDF version still throws an exception,

Looks like the Jasper Engine is looking for the font at a place where its not able to find it.

Is there another place in jasperserver that I need to load this font?

 

Code:
net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : pdfFontName : ARIALUNI.TTF pdfEncoding : Identity-H isPdfEmbedded : true
 
net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : 
pdfFontName   : ARIALUNI.TTF
pdfEncoding   : Identity-H
isPdfEmbedded : true
	at net.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:1551)
	at net.sf.jasperreports.engine.export.JRPdfExporter.getChunk(JRPdfExporter.java:1454)
        at net.sf.jasperreports.engine.export.JRPdfExporter.getPhrase(JRPdfExporter.java:1437)
	at net.sf.jasperreports.engine.export.JRPdfExporter.exportText(JRPdfExporter.java:1794)
	at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:632)
	at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:596)
	at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:539)
	at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:313)
	at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.exportToPdf(EngineServiceImpl.java:275)</td></tr></tbody></table>
prashanth.talkad's picture
Joined: Feb 4 2008 - 8:58am
Last seen: 15 years 7 months ago

That file should be classpath. You are using jasperserver. Pleae check if they have a fonts folder like iReport for the font location and then restart jasperserver. That is the only problem buddy. My solution is the only one which will work.

shrije's picture
2687
Joined: Apr 5 2008 - 8:59am
Last seen: 9 years 6 months ago
thanks mate!! appreciate your help. I looked in the jasperserver install folder, included the ARIALUNI.TTF in the fonts folder and restarted jasperserver. still the same exception :((
prashanth.talkad's picture
Joined: Feb 4 2008 - 8:58am
Last seen: 15 years 7 months ago

Can you send me your Jrxml ? I am not sure if you have attached it earlier. Pickup that ttf file from the windows folder and put it in the jar which needs to be in the classpath.

shrije's picture
2687
Joined: Apr 5 2008 - 8:59am
Last seen: 9 years 6 months ago

hi, i've attached my jrxml. also, when you talk about putting the TTF into the JAR, are you talking about the classpath in iReport? or something else?

cheers !

prashanth.talkad's picture
Joined: Feb 4 2008 - 8:58am
Last seen: 15 years 7 months ago

I'll try to explain our current setup here:::

1) The jasperserver install has a fonts forlder - c:\program files\jasperserver-2.0.1\ireport\fonts and i've added arial.ttf and ARIALUNI.TTF into this folder.

2) I have a Tomcat Base that has the jasperserver.war deployed on it at c:\tomcal-base-nzls-jasper\webapps

3) The WEB-INF in c:\tomcal-base-nzls-jasper\webapps\jasperserver has pdffontbeans.xml, wherein, i've added entries for the fonts as below::::

i've commented out the fonts as I was not sure if this was needed here.

4) when I try to run the report in JRViewer, the Maori Macrons displays - see anapshot attached.

5) when i export this report to PDF by clicking the PDF icon in the snapshot, or through the application that reads the pdf, it throws the following error.


Error Trace:  
net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : pdfFontName : ARIALUNI.TTF pdfEncoding : Identity-H isPdfEmbedded : true
net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font :
pdfFontName   : ARIALUNI.TTF
pdfEncoding   : Identity-H
isPdfEmbedded : true
    at net.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:1551)
    at net.sf.jasperreports.engine.export.JRPdfExporter.getChunk(JRPdfExporter.java:1454)
    at net.sf.jasperreports.engine.export.JRPdfExporter.getPhrase(JRPdfExporter.java:1437)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportText(JRPdfExporter.java:1794)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:632)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:596)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:539)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:313)
    at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.exportToPdf(EngineServiceImpl.java:275)
    at com.jaspersoft.jasperserver.war.action.ReportPdfExporter.export(ReportPdfExporter.java:63)

 
 

Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
 
    <!-- parent map -->
    <!--
        This is the map containing localized font maps.
        Keys are Strings representing the language hold by the session context's Locale object.
        Values are font maps.
        Please feel free to uncomment, add simmilar elements, or modify the commented entries below.
     -->
 
    <util:map id="localePdfFontMap">
     <!--
        <entry key="en" value-ref="enPdfFontMap"/>
        <entry key="ja_JP" value-ref="jaJpPdfFontMap"/>
    -->
    </util:map>
 
    <!-- end parent map -->
 
    <!-- localized font maps -->
    <!--
        Font maps are maps with specific structure:
        Keys are FontKey objects; values are PdfFont objects.
     -->
 
    <!--
    <util:map id="enPdfFontMap">
        <entry key-ref="enArialFontKey" value-ref="enArialPdfFont"/>
        <entry key-ref="enArialUniFontKey" value-ref="enArialUniPdfFont"/>
    </util:map>   
 
    <util:map id="jaJpPdfFontMap">
        <entry key-ref="jaJpArialFontKey" value-ref="jaJpArialPdfFont"/>
        <entry key-ref="jaJpArialUniFontKey" value-ref="jaJpArialUniPdfFont"/>
    </util:map>   
    -->
    <!-- end localized font maps -->
 
    <!-- localized font keys -->
    <!--
    <bean id="enArialFontKey" class="net.sf.jasperreports.engine.export.FontKey">
        <constructor-arg index="0" value="Arial"/>
        <constructor-arg index="1" value="false"/>
        <constructor-arg index="2" value="false"/>
    </bean>
 
    <bean id="enArialUniFontKey" class="net.sf.jasperreports.engine.export.FontKey">
        <constructor-arg index="0" value="Arial Unicode MS"/>
        <constructor-arg index="1" value="false"/>
        <constructor-arg index="2" value="false"/>
    </bean>
    <bean id="jaJpArialFontKey" class="net.sf.jasperreports.engine.export.FontKey">
        <constructor-arg index="0" value="Arial"/>
        <constructor-arg index="1" value="false"/>
        <constructor-arg index="2" value="false"/>
    </bean>
 
    <bean id="jaJpArialUniFontKey" class="net.sf.jasperreports.engine.export.FontKey">
        <constructor-arg index="0" value="Arial Unicode MS"/>
        <constructor-arg index="1" value="false"/>
        <constructor-arg index="2" value="false"/>
    </bean>
    -->
    <!-- end localized font keys -->
 
    <!-- localized pdf fonts -->
    <!--
        The best practice is to save first the desired pdfFont in the repository,
        and then to reference it in the 0-index constructor argument.
        Another way, less safer is to save the .TTF object on your disk, and store its
        absolute path in the 0-index constructor argument.
     -->
    <!--     
    <bean id="enArialPdfFont" class="net.sf.jasperreports.engine.export.PdfFont">
        <constructor-arg index="0" value="repo:/fonts/arial.ttf"/>
        <constructor-arg index="1" value="Identity-H"/>
        <constructor-arg index="2" value="false"/>
        <constructor-arg index="3" value="false"/>
        <constructor-arg index="4" value="false"/>
    </bean>
 
    <bean id="enArialUniPdfFont" class="net.sf.jasperreports.engine.export.PdfFont">
        <constructor-arg index="0" value="repo:/fonts/ARIALUNI.TTF"/>
        <constructor-arg index="1" value="Identity-H"/>
        <constructor-arg index="2" value="true"/>
        <constructor-arg index="3" value="false"/>
        <constructor-arg index="4" value="false"/>
    </bean>
 
    <bean id="jaJpArialPdfFont" class="net.sf.jasperreports.engine.export.PdfFont">
        <constructor-arg index="0" value="../fonts/ARIAL.TTF"/>
        <constructor-arg index="1" value="Identity-H"/>
        <constructor-arg index="2" value="false"/>
        <constructor-arg index="3" value="false"/>
        <constructor-arg index="4" value="false"/>
    </bean>
 
    <bean id="jaJpArialUniPdfFont" class="net.sf.jasperreports.engine.export.PdfFont">
        <constructor-arg index="0" value="repo:/fonts/ARIALUNI.TTF"/>
        <constructor-arg index="1" value="Identity-H"/>
        <constructor-arg index="2" value="true"/>
    </bean>
    -->
    <!-- end localized pdf fonts -->
 
</beans></td></tr></tbody></table>
prashanth.talkad's picture
Joined: Feb 4 2008 - 8:58am
Last seen: 15 years 7 months ago
I am not sure why the beans in the xml file are commented. It may not have any effect at all. Secondly the index 0 of the Arial Unicode MS should be a valid path. You have added repo: in front of that. That may be wrong. Try removing the xml comments too.
shrije's picture
2687
Joined: Apr 5 2008 - 8:59am
Last seen: 9 years 6 months ago

as i've stated in my previous post, I had it uncommented but it did not work and hence I commented it.  but in any case, will try again and I had tried with the absolute path as well for the font TTF files in the XML.

there is something else missing here....dunno what though....

Project owner???? can you help?

p

prashanth.talkad's picture
Joined: Feb 4 2008 - 8:58am
Last seen: 15 years 7 months ago
Try putting the TTF file in the war file.
shrije's picture
2687
Joined: Apr 5 2008 - 8:59am
Last seen: 9 years 6 months ago

I've got it to export into PDF(from the Web Interface of JasperServer) - that is, from the JRViewer. I can run the report in JRViewer and then export to PDF using the "PDF link".

Now, I try to run the same report via my application - this throws a similar exception now -

Could not load the following font :

pdfFontName   : ARIALUNI.TTF
pdfEncoding   : Identity-H
isPdfEmbedded : true

To get this to work in JRViewer, I had loaded the fonts ARIALUNI.TTF, arial.ttf in to the "iReport\Fonts" folder under the JasperServer install folder. This means that the Jasper Server now packages the font into the PDF export. Are there any other settings I need to do for this to work with my application. Since my application is just using the JasperServer API to get JasperPrint pbjects, I thought that it should work on its own if it wokrd on JasperServer. But thats not the case.

I'm lost !!!

 

prashanth.talkad's picture
Joined: Feb 4 2008 - 8:58am
Last seen: 15 years 7 months ago
It means the solution is correct the only issue is with finding the ttf file in the environment. You can find in one way. Get the jasperserver source code and look for the exception. You will surely get some clue. I had this similar experience some time back when i looked through the source code it gave me a striong clue. I havent used jasperserver so i dont have the source code. Not sure if I can download it since it is a GPL license.
shrije's picture
2687
Joined: Apr 5 2008 - 8:59am
Last seen: 9 years 6 months ago

in my application, i use jasperreports2.0.1.jar, JasperReports API, and this JAR needs to have the font in it somewhere for it to export the file to PDF from the raw stream that it recieves from the JasperServer webservice call.

I was looking into the API and found the following - JRProperties point to net.sf.jasperreports.export.pdf.font for PDF fonts, but i'm unable to find that path in the jar. I'll try and add these folder manually into the exploded jar and see if it works.

cheers

prashanth.talkad's picture
Joined: Feb 4 2008 - 8:58am
Last seen: 15 years 7 months ago

Hi I've also face the same promblem. and the workaround for it is to hard code the pdfFont name in jrxml.

This may help you.

Code:
<textElement>
    <font fontName="Arial Unicode MS" isUnderline="false" isStrikeThrough="false" pdfFontName="c:/windows/fonts/ARIALUNI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Test Chinese characters - 甲 骨 文 章 草 新 隸 體 書
Test Arabic characters - ﺀ ﻻ للها لله ﻼ ﷲ گ ﭪﭖ
Test Hindi characters - अ आ इ ई उ ऊ ऋ ऌ ऍ ऎ ए ऐ
Test Russian characters - И з м е н и т ь з а д а ч и
Test Farsi characters - ماموریت نگهداری نرخ تبدیل ارز
Test Hungarian characters - Üzenet szöveg
Test Turkish characters - Açıklama
Test Spanish characters - Descripción
Test English characters - Description ]]></text>			</staticText></td></tr></tbody></table>
yogeshmkumbhar's picture
Joined: Jul 30 2007 - 7:42pm
Last seen: 9 years 2 months ago

Hi,

 

I would only point out that Arian Unicode MS is a font that comes only with Windows East Asia font pack.

People running the reports on Linux could not use the settings you provided. The would have to take the ARIANUNI.TTF from the web or a windows installation and wrap it inside a JasperReports font extension JAR file that they would then add to their application classpath, basically shipping the font with their reports.

You can see how to create a JasperReports font extension by looking at the contents of the /demo/fonts folder of the JR project.

 

I hope this helps.
Teodor

 

teodord's picture
53381
Joined: Jun 30 2006 - 9:00am
Last seen: 19 min 44 sec ago

Hello teodord,

At present, I design an web application using JSF, Spring, Hibernate and JasperReport to generate report to PDF file format.
When I using iReport version 3.6 to design a report after set Windows's font folder to classpath of iReport, it generate PDF
ok, but when I run my web application to export report to PDF file I got exception:

.................
Caused by: net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font :
pdfFontName   : ARIALUNI.TTF
pdfEncoding   : Identity-H
isPdfEmbedded : true
    at net.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:1819)
........................

Even though copied Unicode font file (ARIALUNI.TTF) to WEB-INF\\lib folder and do the following code:

HashMap fontMap = new HashMap();
FontKey key = new FontKey("Arial Unicode", true, false);
PdfFont font = new PdfFont("ARIALUNI.TTF", "Identity-H", true);
fontMap.put(key, font);

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap);

exporter.exportReport();

Could you please give me the solution to solve this problem.

Thank in advance
Bui Quy Duc

buiquyduc's picture
260
Joined: Oct 8 2009 - 4:10am
Last seen: 13 years 11 months ago
Feedback
randomness