Jump to content
Changes to the Jaspersoft community edition download ×

Unicode support and PDF


jambalaya

Recommended Posts

Hi. As I am new, first of all I would like to thank the creators of JasperReports for this wonderful and powerful reporting engine. You guys rock!

Now, the problem. I have a report that uses some letter one cannot find in Latin alphabet (I using polish and german letters in the tests). The output is ok in most export formats, but PDF. I set the isPdfEmbedded to true (not sure at all if this is required), pdfFontName is the default (Helvetica for me), and pdfEncoding is UTF-8. Now, UTF-8 is not on the list of allowed encodings, I put it there the hard way editing the list. When I export it to PDF (using iReport PDF preview) I can only see standard latin characters the special one simply do not appear on the PDF output. When I change the encoding to Identity-H (Unicode with horizontal writing) the internal preview looks fine, but PDF prints nothing for this field. When I change it to cp1250 (central europe) it works fine, but it is not the ideal solution as I expect that our system might be used in French or Spain, and their character would not be displayed.

What can I do to fix this? Please see the file attached.

Thank you.

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

I have the same problem ( see my posting about FontSelector support in this forum. I have no solution for this for now. Here is what I think what our problem is:

The builtin PDF fonts like Helvetica in your sample have all the characters we need ( i.e. all western and central european characters ) but they do not have a unicode encoding. There is a CP1252 encoding for western characters and CP1250 for central european characters. So you have to specify the matching encoding to get your characters printed.

The itext package, which is used in jasperreports to provide PDF support, has a solution for this called FONTSelector. You create a FONTSelector and add all required encodings. Then you pass your text to this FontSelector and it will return a decorated text phrase with the required encoding specifications. This phrase is then added to the document and the output is ok. I tried this with a simple java program calling itext directly.

I have no idea yet how I could do this in JasperReport or even iReport

There is a alternative way to tackle the problem: Buy or otherwise get a font with UTF encoding. With this we should be able to print all european characters in a single string using the Identity-H encoding. But you have to embed your font if you want others to read your document (, if your font license allows embedding ).

I will try this the next days and post my results here, if you are interested.

 

Regards

Christoph

 

OK, I tried TrueType fonts with pdf exporter and it worked ok.

Using iReport 3.1.3-nb:

Include the path to your font directory ( for me it was  c:windowsfonts )  in classpath ( Menu bar: tools->options->classpath tab  ). After doing so, in the fontpath tab in the same option window  this path shows up too and must by checked to be searched for fonts by the iReport.

Now all  TTF fonts show up in the pull down list of PDFFont property sheet. I selected arial.ttf. I also chose IDENTITY-H as PDFencoding .

After doing so the PDF displays characters like the czech 'R caron' ( Unicode u0158 ) or the spanish ' n tilde' ( Unicode u00f1 ) in a single field.

The exporter automatically embedded a subset of the arial TrueType within the pdf document.

This solves the problem if you have a suitable ttf fonts available and accept these fonts to be embedded within your documents.

Personally I would prefer the FontSelector method mentioned above, but I still have no idea how to do this with iReport/JasperReports.

 

 

 



Post Edited by ChristophLeser at 07/25/2009 17:52
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

 

JasperReports now has support for what we call "font extensions". A font extension is a way to package up TTF files and make sure they are available to the JVM for all the font metrics required and to the reporting engine at PDF export time.

Check the /demo/fonts folder of the JR project to see the content of a font extension adding to font families that are used by almost all JR samples.

When you use properly configured font extensions, you'll be taking care only of the fontName attribute and no other attributes would be required, as they are already configured in the font extension file.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

  • 11 months later...

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Mangal" size="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="C:\Windows\Fonts\Mangal.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/></textElement>

 

just see the above tag and do the neccesory changes. It work for me for HINDI UTF-8 data. Thanx

 

 

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