8

I've hardcoded a Text field with the value

 ":$£Ω€απ⅔:" 

to test if these characters will show in PDF

But it only prints as

:$£€:

I've tried changing the font to "Symbol" but that does not do the trick.

Note: I'm using iReport 5.5

LegionDev
  • 1,391
  • 4
  • 15
  • 29
  • Are you using the [Font Extensions](http://jasperreports.sourceforge.net/sample.reference/fonts/)? – Alex K Nov 26 '15 at 14:01

2 Answers2

21

I tried your characters using font-extensions in iReport, These are the steps that I took

  1. Download (or use one on your pc) your desired ttf font (it need to support the characters), I used dejavu-serif.
  2. Install the font in iReport or in Jasper soft studio (click links to understand how)

    • I used iReport 5.6 and did set the PDF-Encoding: Idenity-H (unicode with horizontal writing) and embedded the font in pdf. This was the code of my textField

      <textField>
          <reportElement x="8" y="15" width="100" height="20" uuid="41dc1200-091f-4799-a1d2-4622f88a0e84"/>
          <textElement>
              <font fontName="DejaVu Serif" size="13"/>
          </textElement>
          <textFieldExpression><![CDATA[":$£Ω€απ⅔:"]]></textFieldExpression>
      </textField>
      
  3. Export the font extension (this creates a .jar)

  4. Add the jar to your classpath.
  5. Export to pdf and enjoy the result.

Result

This is an example of how to use any arbitrary font, if you like to use DejaVu Sans or DejaVu Serif you can just include the jasper report fonts library in classpath, hence these font are already included and mapped in library

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • In my case, I unpacked that jar and placed its content into src/main/resources , otherwise you will have to play with adding JAR to your Maven project what is not trivial. – walv Mar 18 '17 at 04:32
  • Running into the same problem. Before changing my reports to use DejaVu Sans, can anyone explain why this is happening? – Thomas Jul 07 '17 at 00:12
  • @Thomas you can check the comments on this [answer](https://stackoverflow.com/a/35549391/5292302), itext the library that generates the pdf, needs the .ttf and know which encoding you are using to create correctly the pdf. – Petter Friberg Jul 07 '17 at 07:52
  • @Tomas futhermore you can use other fonts as long as they are [supported by itext](https://stackoverflow.com/questions/35127956/how-can-i-test-if-my-font-is-rendered-correctly-in-pdf), you just need to create your own [font-extension](https://stackoverflow.com/documentation/jasper-reports/5773/font-extensions) – Petter Friberg Jul 07 '17 at 07:56
  • Thanks @PetterFriberg. I did some further digging as well (esp on iText) and came to the same conclusion. Next try on will be using Arial as I'd like to have no visible difference in the reports - DejaVu Sans looks a bit too different. – Thomas Jul 09 '17 at 02:49
  • Can you plese be more detailer how to do that? The tutorials are extremely poor. For example https://community.jaspersoft.com/wiki/custom-font-font-extension has only one sentence about deploing the jar on server. Once you have your font.jar file drop this into your application classpath (jasperserver-pro/WEB-INF/lib) and restart jasper reports server. I cannot find where should i drop the file – Laser42 Feb 25 '21 at 11:11
  • @Laser42 are you deploying your report on jasper-reports server or trying to preview in Jasper Report studio? – Petter Friberg Feb 25 '21 at 12:53
  • @PetterFriberg PDF preview in Studio didn't work. So, I had to deploy the file into directory on server. I found in google that the destination path is Jaspersoft/%jasperinstance/apache-tomcat/webapps/jasper server/WEB-INF/lib, and after that - stop & start jasper service using Start menu shortcuts. – Laser42 Feb 25 '21 at 13:11
  • 1
    first one, find a custom font that supports mentioned symbol. second one, PDF Font Name should be null. third one, PDF Encoding should be Identity-H – AhuraMazda Aug 13 '21 at 11:01
2

I had posted a similar question and the above technique solved my problem, until one fine day I restarted the JasperServer context. I was now getting "PDF encoding not found" error when I tried to export the report to pdf.

To solve this problem I had to copy the iText-Asian.jar and Font-extension.jar in the lib folder of the jasperserver context. "jasperserver/WEB-INF/lib". Once done restart the context and problem solved.

Hope it helps someone.

dnaik
  • 1,455
  • 1
  • 10
  • 10