0

how to add country currency symbol using pdfbox in java

I am trying to add country currency symbol in pdf but got below error, please help me to out of this thanks in advance

ERROR:
java.lang.IllegalArgumentException: U+20B9 ('.notdef') is not available in this font Helvetica-Bold encoding: WinAnsiEncoding



CODE:       

contentStream.beginText();
        contentStream.setLeading(14.5f);
        contentStream.newLine();
        contentStream.setFont(PDType1Font.HELVETICA_BOLD, fontSize);
        contentStream.showText("TotalAmount: ₹" + "0.00");
        contentStream.newLine();

Code use with arial.ttf

contentStream.beginText();
            contentStream.setLeading(14.5f);
            contentStream.newLine();
    contentStream.setFont(PDType0Font.load(document, new File("C:/00Project/Sports_v2_workspace/arial.ttf")), 10);
    //  contentStream.setFont(PDType1Font.HELVETICA_BOLD, fontSize);
        contentStream.showText("Total Amount: ₹" + "0.00");

Error:
java.lang.IllegalArgumentException: No glyph for U+20B9 (₹) in font ArialMT

I downloaded arial.tff in GitHub , Coukd you please help me for this case

syedali SD
  • 77
  • 1
  • 9
  • Does this answer your question? [PDFBox U+00A0 is not available in this font's encoding](https://stackoverflow.com/questions/46470158/pdfbox-u00a0-is-not-available-in-this-fonts-encoding) – Tilman Hausherr Jul 04 '20 at 13:57
  • Also https://stackoverflow.com/questions/40045818, https://pdfbox.apache.org/2.0/faq.html#i'm-getting-java.lang.illegalargumentexception%3A-...-is-not-available-in-this-font's-encoding%3A-winansiencoding – Tilman Hausherr Jul 04 '20 at 13:59
  • Actually I tried this all ways but not getting valid one . – syedali SD Jul 04 '20 at 14:29
  • Here I am trying to add the new symbol/special char not replacing the char – syedali SD Jul 04 '20 at 14:30
  • If you tried all that, please edit the question and include the code that you used. – Tilman Hausherr Jul 04 '20 at 15:24
  • I tried with arial.ttf and it worked. (surprisingly, it didn't work with several other fonts I tried, including mangal.ttf but that is from 2010, and I've just learned that the rupee symbol didn't exist before) https://www.fileformat.info/info/unicode/char/20b9/fontsupport.htm – Tilman Hausherr Jul 04 '20 at 16:26
  • Hi Tikman, I tried below code to use arial.ttf and got below error. java.lang.IllegalArgumentException: No glyph for U+20B9 (₹) in font ArialMT – syedali SD Jul 04 '20 at 18:56
  • code which I used: contentStream.setFont(PDType0Font.load(document, new File("C:/00Project/Sports_v2_workspace/arial.ttf")), 10); contentStream.showText("Total Amount: ₹" + "0.00"); – syedali SD Jul 04 '20 at 19:02
  • 1
    could you please share the arial.ttf file and code, which will be helpful for me. Thanks – syedali SD Jul 04 '20 at 19:05
  • Have you tried [this](https://stackoverflow.com/a/49427319/8244632) or [this](https://kb.itextpdf.com/home/it7kb/faq/how-to-display-indian-rupee-symbol) ? – Lalit Fauzdar Jul 04 '20 at 19:27
  • To quote from [another answer](https://stackoverflow.com/a/49427319/8244632): As @Tilman already stressed, one needs to have a new enough font file to make this work: The Indian Rupee Sign ₹ (U+20B9) was introduced to Unicode in version 6.0.0 (October 2010) and it might have taken font developers some time to implement that glyph. E.g. I use ArialMT (arial.ttf) version 6.90 with "(c) 2015 The Monotype Corporation." – mkl Jul 04 '20 at 19:39
  • Have you tried opening the font in a font viewer, or in OpenOffice / whatever, and checked if it actually has a rupee glyph? –  Jul 04 '20 at 20:11
  • @syedalicse I won't share my fonts, for obvious reasons. However the symbol is also available in the dejavu fonts, get them here: https://dejavu-fonts.github.io/Download.html – Tilman Hausherr Jul 05 '20 at 03:46
  • @syedalicse did it work with the dejavu font? – Tilman Hausherr Jul 06 '20 at 07:56
  • sorry for late reply, but dejavu font is not working for me and I moved to jasper. – syedali SD Mar 01 '21 at 03:17

0 Answers0