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

Unicode codes on PDF


ziden

Recommended Posts

  Hello there. Ive found some topics at this and other forums about this, but im a Jasper begginer and couldnt doit. Ive got a database witch will have a string containing HTML simple tags such as BOLD or ITALIC witch is working perfectly. I also have some Unicodes such as \u2663 , witch in this fact is the "clubs" from card set. The fact is, in Jasper Preview it works perfectly, but when it comes to PDF it doesnt work. Im using jasper 3.7.4 and im not initializing the jasper via Java till now, still only workin at Ireport.

   Is there any simple solution to this ? Thanx alot for any help.

 

  []´s Gabriel Ziden

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Sorry for the double posting.

Ive got a 'half way' solution to this. Ive added the following to my code:

 HashMap fontes = new HashMap();
                HashMap fontMap = new HashMap();
                FontKey key = new FontKey("Arial", false, false);  //(String fontName, Boolean bold, Boolean italic)
                PdfFont font = new PdfFont("C:/windows/Fonts/ARIAL.TTF", com.lowagie.text.pdf.BaseFont.IDENTITY_H ,true); //(String pdfFontName, String pdfEncoding, Boolean isPdfEmbedded)
                fontMap.put(key,font);
                  exporter.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");
                exporter.setParameter(JRPdfExporterParameter.FONT_MAP, fontMap);

 

This way, when i run the PDF throw Java and not thro Ireport, i can see the /u unicode characters. However, i had a simple HTML formatting in strings such as <b> and <br> , witch, dont run anymore if i use those lines.

  Another problem is, im using Arial witch is a Windows Font. I wish to know if is there any font option that includes Linux OS, witch is our server and DB.

 

  Thanx for any help. []´s Gabriel

 

 

Link to comment
Share on other sites

Hi,

 

First of all, you need a TTF file that supports that special character you have.

It seems Arial has that character. Then you need to be aware that for bold and italic to work in PDF, you need special TTF files that are bold and italic. Check your Windows fonts folder again and see that there are several Arial files there, not one.

With your code, you only mapped the normal one, not the bold, italic and the bold/italic TTFs.

 

Finally, you need to be aware the those exporter parameters you are setting from code are now deprecated. JR/iR nowadays have support for what we call font extensions.

These are specially configured JAR files containing fonts that you simply put in your classpath and thus make the fonts available with your application/reports.

iReport has a wizard for creating and installing font extension JARs.

 

If you want to learn more about fonts in JR/iR, check the /demo/samples/fonts sample and the /demo/samples/unicode sample shipped with the JR project. Also check the /demo/fonts folder of the JR project to see how a prepackaged font extension JAR containing the DejaVu open source fonts is made of.

 

I hope this helps.
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...