itextpdf - Rupee symbol is not showing in android -
itextpdf - Rupee symbol is not showing in android -
hi friends using itextpdf-5.3.4.jar creating pdf. showing rupee symbol using custom font .i tried arial.ttf,arialbd.ttf both these font no luck rupee sybol not showing.for showing rupee symbol have followed these links not working me. how display indian rupee symbol in itext pdf in mvc3. code have used.
basefont rupee =basefont.createfont( "assets/arial .ttf", basefont.identity_h,basefont.embedded); createheadings(cb,495,60,": " +edt_total.gettext().tostring(),12,rupee);
private void createheadings(pdfcontentbyte cb, float x, float y, string text, int size,basefont fb){
cb.begintext(); cb.setfontandsize(fb, size); cb.settextmatrix(x,y); cb.showtext(text.trim()); cb.endtext(); }
please help me guys.
in comment section, funkystein wrote problem describe typical when
you using font doesn't have glyph. or you aren't using right encoding.i have written illustration illustrates this: rupeesymbol
public static final string dest = "results/fonts/rupee.pdf"; public static final string font1 = "resources/fonts/playfairdisplay-regular.ttf"; public static final string font2 = "resources/fonts/pt_sans-web-regular.ttf"; public static final string font3 = "resources/fonts/freesans.ttf"; public static final string rupee = "the rupee character \u20b9 , rupee symbol \u20a8"; public void createpdf(string dest) throws ioexception, documentexception { document document = new document(); pdfwriter.getinstance(document, new fileoutputstream(dest)); document.open(); font f1 = fontfactory.getfont(font1, basefont.identity_h, basefont.embedded, 12); font f2 = fontfactory.getfont(font2, basefont.identity_h, basefont.embedded, 12); font f3 = fontfactory.getfont(font3, basefont.identity_h, basefont.embedded, 12); font f4 = fontfactory.getfont(font3, basefont.winansi, basefont.embedded, 12); document.add(new paragraph(rupee, f1)); document.add(new paragraph(rupee, f2)); document.add(new paragraph(rupee, f3)); document.add(new paragraph(rupee, f4)); document.close(); }
the rupee
constant string
contains rupee character rupee symbol: "the rupee character ₹ , rupee symbol ₨"
. characters stored unicode values, because if store characters otherwise, may not rendered correctly. instance: if retrieve values database winansi, end wrong characters.
i test 3 different fonts (playfairdisplay-regular.ttf, pt_sans-web-regular.ttf , freesans.ttf) , utilize identity_h
encoding 3 times. utilize winansi
4th time show goes wrong if do.
the result file named rupee.pdf:
as can see, first 2 fonts know how draw rupee character. 3rd 1 doesn't. first 2 fonts don't know how draw rupee symbol. 3rd 1 does. however, if utilize wrong encoding, none of fonts draw right character or symbol.
in short: need find font knows how draw characters or symbols need, have create sure using right encoding (for string
font
).
you can download total sample code here.
android itextpdf
Comments
Post a Comment