Jump to content
We've recently updated our Privacy Statement, available here ×

Unicode(Maori Macrons) issue with PDF


prashanth.talkad

Recommended Posts

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:

 

Link to comment
Share on other sites

  • Replies 18
  • Created
  • Last Reply

Top Posters In This Topic

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

Link to comment
Share on other sites

yes I did load the "C:windowsfonts" 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 : truenet.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : pdfFontName   : ARIALUNI.TTFpdfEncoding   : Identity-HisPdfEmbedded : 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)
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

1) The jasperserver install has a fonts forlder - c:program filesjasperserver-2.0.1ireportfonts 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-jasperwebapps

3) The WEB-INF in c:tomcal-base-nzls-jasperwebappsjasperserver 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.xsdhttp://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>
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 "iReportFonts" 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 !!!

 

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 11 months later...

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övegTest Turkish characters - AçıklamaTest Spanish characters - DescripciónTest English characters - Description ]]></text>			</staticText>
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...