Jump to content

How to match pdfFontName with fontName?


wjones14

Recommended Posts

We still have an issue with a report cell, where the line breaking / word wrapping is not always working right in our PDF report, and the report sometimes is missing data.  Teodor replied, saying the issue might be font related.  He suggested reading this section of the FAQ for ideas:

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

 

And actually, after reading that, we tried changing the net.sf.jasperreports.export.pdf.force.linebreak.policy property to true.  This fixed the problem of missing data, but introduced a new problem where the data was no longer lined up in neat columns, and the line breaks were happening in the middle of words.

 

So by trial and error, we also started changing the fontName and pdfFontName values for the textField from the iReport default of San Serif and Helvetica.  We changed them to this:

 

<textElement>
      <font fontName="Times New Roman" pdfFontName="Times-Roman"/>
 </textElement>

 

This seems to fix the problem, although we can't test it with every possible data configuration we might have.  Are the PDF font metrics equal to the Java/AWT font metrics with these two fonts?

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Hello !Yes, this is frequent, and I've already been confronted to that issue.For your question, yes, I think these two fonts are equals, and have the same metrics...But one question, by the way, if someone's reading that : how do you get asian fonts to match (fontName & pdfFontName) ?!Does the STSong-Light, for instance, have a metrics-like font in java awt ?!

 

Regards,

Morgan

Link to comment
Share on other sites

The safest way to ensure that the AWT and PDF metrics match is to use the same physical font for both Java/AWT and PDF.

Recent JR versions introduce font extensions which make font configuration easier.  See the demo/samples/font sample report for details.

Regards,

Lucian

Link to comment
Share on other sites

Hi Lucian. Thank you for your response !I understood that I had to map my font with a similar physic font, but which font do I have to set in the fontName attribute when I'm writing in one of the asian languages included by iTextAsian ? I really don't know how to choose a system font which has the same metrics as a font like STSong-Light, or whatever...Thank you :)

 

Regards,

Morgan

Link to comment
Share on other sites

Hello everybody !Does someone know which fontName you have to choose when you specify an asian font in the pdfFontName field, being sure they have the exact same metrics ?And with the new extension properties, when you build font families in the XML file (spring), how do you specify an existing font known by Jasper via iText, and not a TTF file you embbed in your jar ?Thank you :)

 

Regards,

Morgan

Link to comment
Share on other sites

Morgan,

 

What you are trying to do is not correct.

If you use pdfFontName from the iTextAsian.jar, it means you are relying on the Asian Font pack to be installed in the Acrobat Reader on the client machine. This means the font is not embedded into the PDF file and has to be available in the PDF reader.

If you open up the iTextAsian.jar, you'll find all this explained in the cmap_info.txt file there. I copied the following paragraphs for your convenience here:

---------------------------

"Note that whatever value you pass for the 'embedded' parameter
with the method BaseFont.createFont, the font WILL NOT BE embedded.
To understand why, please read the following information.

The fonts that are used in Acrobat Reader when viewing a PDF file
that uses CJK fonts will be downloaded in one or more font packs.
You can download these fontpacks yourself from this URL:
http://www.adobe.com/products/acrobat/acrrasianfontpack.html"

-----------------------------

So, not only that we do not know which TTF files Acrobat Reader uses in its Asian Font pack, but there also must be some licensing issue trying to use them with your Java application.

The correct way to do it is to download open source Chinese fonts or purchase commercial ones and package them as a JR font Extension. When exporting to PDF you would have to embed the fonts in the resulting PDF files.

If you still want to rely on the iTextAsian.jar and the Adobe Asian font pack, then you still need to download or purchase some Chinese TTF files to use within Java. I'm not sure, but maybe you could use the Adobe ones, if they are available for such a purpose. You have to check that though, as I have not.

 

I hope this helps.

Teodor

 

 

Link to comment
Share on other sites

Hello Teodor ! Thank you very much for your response, it is very nice of you. I understood there was no other solution than embbeding my font in the PDF file... I just wanted to save some space on my server, but I think it's the only solution left :) Thanks a lot again.

Regards,

Morgan



Post Edited by blaguman at 06/30/2009 13:11
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...