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