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

font mapping works incorrectly


hasch73

Recommended Posts

hi,

I´ve update iReport and JR from 3.0.0 to 3.5.0.

I works with jdk 1.5

I have a simple Report with one Textfield which holds a long description and needs to stretch dynamically.

The user can the font select. I use the FONT_MAP - parameter. I use the parameter to exchange the character font.

 exporter.setParameter(JRPdfExporterParameter.FONT_MAP,              getDefaultPDFFontMap(techMandantBO));protected static Map getDefaultPDFFontMap(   		TechMandantBusinessObject techMandantBO) {...fontMap.put(      		new FontKey("Arial", false, false),            new PdfFont(fontNormal==null?"Helvetica":fontNormal, "Cp1252", true));...}

It runs perfectly, but one user have own fonts and in the PDF the last line is missing.

Why?

What can I do???

Code:
<?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="pscKundensituation" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="495" leftMargin="60" rightMargin="40" topMargin="20" bottomMargin="20" resourceBundle="de.etvice.efp24.report.psc.resources.ReportResources" whenResourceMissingType="Empty">	<property name="ireport.scriptlethandling" value="0"/>	<property name="ireport.encoding" value="UTF-8"/>	<property name="net.sf.jasperreports.export.pdf.force.linebreak.policy" value="true"/>	<property name="net.sf.jasperreports.text.truncate.at.char" value="true"/>	<import value="java.util.*"/>	<import value="net.sf.jasperreports.engine.*"/>	<import value="net.sf.jasperreports.engine.data.*"/>	<reportFont name="Arial" isDefault="false" fontName="Arial" size="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="true"/>	<parameter name="header" class="java.util.Map" isForPrompting="false"/>	<parameter name="footer" class="java.util.Map" isForPrompting="false"/>	<parameter name="kapitel_1" class="java.lang.String"/>	<parameter name="kapitel" class="java.lang.String"/>	<field name="text" class="java.lang.String"/>	<background>		<band/>	</background>	<title>		<band/>	</title>	<pageHeader>		<band/>	</pageHeader>	<columnHeader>		<band isSplitAllowed="false"/>	</columnHeader>	<detail>		<band height="57">			<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">				<reportElement key="text5" positionType="Float" isPrintRepeatedValues="false" mode="Transparent" x="0" y="0" width="495" height="14" isRemoveLineWhenBlank="true"/>				<box>					<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>					<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>					<bottomPen lineWidth="0.0" lineColor="#000000"/>					<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>				</box>				<textElement textAlignment="Justified" verticalAlignment="Middle" markup="styled">					<font fontName="Arial" size="9" isBold="false" isPdfEmbedded="true"/>				</textElement>				<textFieldExpression class="java.lang.String"><![CDATA[$F{text}]]></textFieldExpression>			</textField>		</band>	</detail>	<columnFooter>		<band/>	</columnFooter>	<pageFooter>		<band/>	</pageFooter>	<summary>		<band/>	</summary></jasperReport>

Post Edited by hasch73 at 07/14/2009 10:41
Link to comment
Share on other sites

  • Replies 11
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

Now that you migrated to JR 3.5.0, it is time to make use of the new font extensions support, which very much deprecates the use of the FONT_MAP parameter.

There is no need to use the FONT_MAP anymore, as the mapping can be done in a fonts.xml file that you deploy together with your TTF files inside a JAR that you put in the classpath. You'll only care about setting the fontName attribute in your report templates and don't care about the pdfFontName or isPdfEmbedded attributes anymore.

 

Check the /demo/fonts folder of the JR project package to see the content of such a font extension that is used by almost all the JR samples nowadays. Do a similar package with your Arial font files, or any other TTF files that you might want your users to leverag in their reports.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

Thanks!

But I think my problem is more complex.

The system is a web application and the user can select the font dynamically.

see the screenshot.

All my report have ARIAL as standard character font.

On the basis of the selection in the report the font is replaced.

 

Link to comment
Share on other sites

Hi,

 

I don't understand German, so I'm not sure what fonts you propose with your application.

You should not propose fonts that you do not actually have available in your application as TTF files.

Because if you don't have them, you cannot embed them in the PDF that you deliver. And if you do not embed them in the PDF, there is no way you could make sure they will be available on the machines that view your PDF.

 

There is no point in letting people select the Arial font, which might be listed as present in the Java Virtual Machine, when your Web application runs on a Windows system, because if you do not actually have access to the Arial TTF file on disk, you cannot embed it in the resulting PDFs, and if people are accessing your application with browsers from Linux, wher there is no Arial installed, the PDF will look bad and text will probably be cut off, due to font metrics mismatch.

 

All in all, you should let your end users select only fonts from the JR font extensions that you have deployed in your Web application. This is how iReport does it. When you pick a font in iReport, at the top of the list you see fonts that are coming from font extensions deployed in iReport and only after that you see system fonts, which you should not actually be using, unless you are sure the fonts you pick will always be available to people viewing your reports.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

Hi,

fonts are in a folder on the server.

The TTF files are available and in the pdf embedded (see attachment pdf´s).

In the first pdf (see the attachement: text_complete_with_helvetica.pdf) with the font HELVETICA the text is completely indicated.

In the second pdf (see the attachement:text_incomplete_with_user_font.pdf) with another font the last line is missing.

The TTF file are available und embedded, but the last line is missing.

Sorry my bad English.

Link to comment
Share on other sites

Hi,

 

The problem you are experiencing is descriebed in more detail in this FAQ here:

http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/faq.html?group_id=252#FAQ25

 

Having the TTF files in a folder on disk is not enough. They have to be available to the Java Virtual Machine, either by being installed into the system or being installed in the JVM at runtime using Java specific techinques.

By looking at the JRXML you sent, I see that you are trying to use the Arial font. You are counting on this font to be available to the JVM. If your server runs on Windows, this font is probably already installed and you don't have to do anything. But if your server runs on Unix/Linux, the Arial font is not present. You do not see any error for the missing JVM font, because the JVM uses some other font instead, most likely Helvetica, which is a common Linux font that looks farily similar to Arial.

But the trouble is that Arial and Helvetica have different font metrics, so the text size calculations are performed with one and will not fit the other. I think what happens is that when you fill the report, Arial is missing and Helvetica gets used instead, resulting in a text height that is too small for Arial to fit. This is why your PDF looks OK when generated with Helvetica and text is cut off when generated with Arial.

 

Please consider mapping all these TTF files you say you have in a font extension file and add the folder to the classpath. You should no longer experience such problems, because by registering them like this you make sure they will be installed in the JVM  when you run your application.

 

I hope this helps.

Teodor

 

Link to comment
Share on other sites

  • 2 weeks later...

Dear Teodor,

 

Thanks for the valuable inputs.

 

I am facing some problem while following your suggestion as:

"You'll only care about setting the fontName attribute in your report templates and don't care about the pdfFontName or isPdfEmbedded attributes anymore."

 

I am setting only the fontName while designing report in iReport but the pdf encoding is set to CP1252 as iReport does not allow it blank.

And when I run my report it gives me below error:

ErrorÂexportingÂprint...Âcom.lowagie.text.DocumentException:ÂFontÂ''ÂwithÂ'Cp1252'ÂisÂnotÂrecognized.

net.sf.jasperreports.engine.JRRuntimeException:Âcom.lowagie.text.DocumentException:ÂFontÂ''ÂwithÂ'Cp1252'ÂisÂnotÂrecognized. ÂÂÂÂatÂnet.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:1845) ÂÂÂÂatÂnet.sf.jasperreports.engine.export.JRPdfExporter.getChunk(JRPdfExporter.java:1666) ÂÂÂÂatÂnet.sf.jasperreports.engine.export.JRPdfExporter.getPhrase(JRPdfExporter.java:1642) ÂÂÂÂatÂnet.sf.jasperreports.engine.export.JRPdfExporter.exportText(JRPdfExporter.java:2038) ÂÂÂÂatÂnet.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:726) ÂÂÂÂatÂnet.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:686) ÂÂÂÂatÂnet.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:575) ÂÂÂÂatÂnet.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:383) ÂÂÂÂatÂcom.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:1159) ÂÂÂÂatÂorg.openide.util.RequestProcessor$Task.run(RequestProcessor.java:561) ÂÂÂÂatÂorg.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:986) CausedÂby:Âcom.lowagie.text.DocumentException:ÂFontÂ''ÂwithÂ'Cp1252'ÂisÂnotÂrecognized. ÂÂÂÂatÂcom.lowagie.text.pdf.BaseFont.createFont(UnknownÂSource) ÂÂÂÂatÂcom.lowagie.text.pdf.BaseFont.createFont(UnknownÂSource) ÂÂÂÂatÂnet.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:1833) ÂÂÂÂ...Â10ÂmoreÂ

 

Link to comment
Share on other sites

  • 3 weeks later...

Hi all,
Excellent forum!!. I am new and I have the following problem:
I am using iReport 3.0.0 and jasper reports 2.0.5. I have a report that has several columns and one column has a large content. The content is cut in the last lines. The column has font name “SansSerif” and pdf font name “Helvetica”.
I prove putting the FORCE_LINEBREAK_POLICY and the FONT_MAP parameters as following but it didn’t work:

Does anyone know what it could be happening?
Thanks in advance!!

Code:
exporter.setParameter(JRPdfExporterParameter.FORCE_LINEBREAK_POLICY, Boolean.TRUE);FontKey keyHelvetica = new FontKey("SansSerif", false, false);PdfFont fontHelvetica = new PdfFont("Helvetica", "Cp1252", false);FontKey keyHelveticaBold = new FontKey("SansSerif", true, false);PdfFont fontHelveticaBold = new PdfFont("Helvetica-Bold", "Cp1252", false);Map<FontKey, PdfFont> fontMap = new HashMap<FontKey, PdfFont>();fontMap.put(keyHelvetica, fontHelvetica);fontMap.put(keyHelveticaBold, fontHelveticaBold);exporter.setParameter(JRPdfExporterParameter.FONT_MAP, fontMap);
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...