Jump to content
Changes to the Jaspersoft community edition download ×

Font mapping problem


tinti

Recommended Posts

Well,

I have a project to print reports using jasper.

I need to print various reports with different fonts.

Then, I mapped my project with some fonts and his respective tff files.

I have at the moment this:

In the source package the jasperreports_extensions.properties file with the following items:
net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.fonts.spring.beans.resource=fonts/fonts.xml

And the fonts folder with the tff files and the fonts.xml.

The fonts.xml has the following 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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean id="arial" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
        <property name="name" value="Arial"/>
        <property name="normal" value="arial.ttf"/>
        <property name="bold" value="arialbd.ttf"/>
        <property name="italic" value="ariali.ttf"/>
        <property name="boldItalic" value="arialbi.ttf"/>
        <property name="pdfEncoding" value="Cp1252"/>
        <property name="pdfEmbedded" value="true"/>
    </bean>

    <bean id="times" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
        <property name="name" value="Times New Roman"/>
        <property name="normal" value="times.ttf"/>
        <property name="bold" value="timesbd.ttf"/>
        <property name="italic" value="timesi.ttf"/>
        <property name="boldItalic" value="timesbi.ttf"/>
        <property name="pdfEncoding" value="Cp1252"/>
        <property name="pdfEmbedded" value="true"/>
    </bean>

    <bean id="verdana" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
        <property name="name" value="Verdana"/>
        <property name="normal" value="verdana.ttf"/>
        <property name="bold" value="verdanab.ttf"/>
        <property name="italic" value="verdanai.ttf"/>
        <property name="boldItalic" value="verdanaz.ttf"/>
        <property name="pdfEncoding" value="Cp1252"/>
        <property name="pdfEmbedded" value="true"/>
    </bean>

    <bean id="tahoma" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
        <property name="name" value="Tahoma"/>
        <property name="normal" value="tahoma.ttf"/>
        <property name="bold" value="tahomabd.ttf"/>
        <property name="pdfEncoding" value="Cp1252"/>
        <property name="pdfEmbedded" value="true"/>
    </bean>

    <bean id="Courier New" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
        <property name="name" value="Courier New"/>
        <property name="normal" value="cour.ttf"/>
        <property name="bold" value="courbd.ttf"/>
        <property name="italic" value="couri.ttf"/>
        <property name="boldItalic" value="courbi.ttf"/>
        <property name="pdfEncoding" value="Cp1252"/>
        <property name="pdfEmbedded" value="true"/>
    </bean>
</beans>

And then, I have a report with a textField font property set to "Courier New".
My generated PDF show the text in the textField with Arial, not the "Courier New" font.

That's my problem.



Post Edited by tinti at 12/14/2010 12:45
Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Hi tinti,

I think your problem is that not all of the font types are supported by pdf files. If you open iReport and try to define the "Properties" of a field, you can check that thereare two different properties for the font: 

  • "Font Name"
  • "Pdf Font Name"

The "Courier New" font is not in the possible font types of "Pdf Font Name", so I guess it is setting Arial by default. So, you must first check the font types you can use in Pdf format and then decide which ones are you going to use.

Hope this helps.

Regards,

Aitor

Link to comment
Share on other sites

Code:
Hi,

How did you package up your font extension? In a separate JAR?
If so, can you post here the structure of your JAR, with the files inside it?

Also, can you attach here the JRXML and maybe a copy of the resulting PDF file?

It could be that for some text fields, you have values for the now deprecated pdfFontName attribute.

Thanks,
Teodor
Link to comment
Share on other sites

I tried to use that way.

JRXML
<?xml version="1.0" encoding="ISO-8859-2"?>
<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="ReportBase02" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.callouts" value="##Tue Jan 04 09:23:21 BRST 2011"/>
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[select 1 from dual]]>
    </queryString>
    <detail>
        <band height="134" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="555" height="33"/>
                <textElement>
                    <font size="20" pdfFontName="Base02" isPdfEmbedded="true" pdfEncoding="ISO-8859-1"/>
                </textElement>
                <textFieldExpression class="java.lang.String"><![CDATA["Do or do not, there is no try"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="113" width="555" height="21"/>
                <textElement>
                    <font size="12" pdfFontName="Base02" isPdfEmbedded="true" pdfEncoding="ISO-8859-1"/>
                </textElement>
                <textFieldExpression class="java.lang.String"><![CDATA["A morte de uma pessoa é tragédia, a de milhões é estatística"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>
 

jasperreports.properties
net.sf.jasperreports.export.pdf.font.Base02=/fonts/cour.ttf

I exported to pdf, and the pdf is ok.

But, i'm working with Portuguese/Brazil, and the accentuation don't worked.

What is wrong?

Link to comment
Share on other sites

Hi,

 

I don't see any of the fonts from your font extension being used in this report. You make use of the now deprecated pdfFontName attribute.

 

You should use ONLY the fontName attribute and give it as value one of the font family names you said you've been created such as fontName="Courier New".

Make sure your font extension JAR is in the classpath when you run your reports.

 

What you have done with Base02 in jasperreports.properties is a deprecated technique as well.

 

I hope this helps.

Teodor

 

Link to comment
Share on other sites

OK, so, i need to put the ttf files in a jar, and load to classpath.

And use just the font name?

I do not need to map the font name anywhere?

Like the samples in the jasperreports-3.7.6-project?

Edit:

My last post is a different project from the first post.

I'm not using nothing i showed from the first post.

My project from the first post just not work, so i did another project, from my last post, and then the fonts problem was solved, but the accentuation dont worked.



Post Edited by tinti at 01/06/2011 16:30
Link to comment
Share on other sites

Hi,

 

If you still experience some problems with some characters, you have to give us the exact details of the current situation.

It is no longer clear what you did in the first post and then after the last post and so on...

Do a recap and explain exactly what you are doing now and what does not work.

 

Thanks,

Teodor

 

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