asp.net mvc 3 - Arabic font in Web UI and itextsharp -
i'm not able find reason why mvc 3 web site shows arabic font correctly , pdf not.
i use bliss font in web site;
@font-face { font-family: 'blissregular'; src: url('/fonts/blissregular-webfont.eot'); src: url('/fonts/blissregular-webfont.eot?#iefix') format('embedded-opentype'), url('/fonts/blissregular-webfont.ttf') format('truetype'); font-weight: normal; font-style: normal;}
all working fine. after want create pdf of output arabic fonts not appears.
i've googled , understand font must have arabic character show correctly. i've changed arial font (that contains arabic character) and... pdf worked.
so... how possible bliss font (that not have arabic characters) see arabic font in web site?
i'm confused....
thanks lot everybody!
for every character browser encounters looks matching glyph in current font. if font doesn't have glyph looks fallback fonts see if have glyph. every browser has core set of default fonts ultimate fallback. when specify font bliss use arabic characters seeing browser's fallback fonts.
pdfs don't work way. if using font xyz
try render using font or fail.
the easiest way add font css supports characters.
.myclass{font-family: blissregular, arial}
if doesn't work might need inject fonts manually. (actually, i'm not 100% itext support @font-face, either.) itext has helper class can figure things out bruno talks here unfortunately c# link isn't working anymore. it's simple, create instance of fontselector
class, call addfont
in order want characters looked up in , pass string process()
method spits phrase
can add. below basic sample code shows off. apologize sample text, i'm english-native searched use, hope didn't mangle or backwards.
you'll need jump through couple of hoops when processing html should able work out, hopefully.
//sample string. apologize, google search hope isn't backward var teststring = "يوم الاثنين \"monday\" in arabic"; var outputfile = path.combine(environment.getfolderpath(environment.specialfolder.desktop), "test.pdf"); //standard pdf setup using (var fs = new filestream(outputfile, filemode.create, fileaccess.write, fileshare.none)) { using (var doc = new document()) { using (var writer = pdfwriter.getinstance(doc, fs)) { doc.open(); //this font know *does not* support arabic characters, substitute own font if don't have var gishafontpath = path.combine(environment.getfolderpath(environment.specialfolder.fonts), "gisha.ttf"); var gishabasefont = basefont.createfont(gishafontpath, basefont.identity_h, basefont.embedded); var gishafont = new itextsharp.text.font(gishabasefont, 20); //add our test string using normal font, *will not* display arabic characters doc.add(new phrase(teststring, gishafont)); //this font know *does* support arabic characters var arialfontpath = path.combine(environment.getfolderpath(environment.specialfolder.fonts), "arialuni.ttf"); var arialbasefont = basefont.createfont(arialfontpath, basefont.identity_h, basefont.embedded); var arialfont = new itextsharp.text.font(arialbasefont, 20); //create our font selector specifying our specific font first var sel = new fontselector(); sel.addfont(gishafont); sel.addfont(arialfont); //have font selector process our text series of chunks wrapped in phrase var newphrase = sel.process(teststring); //add phrase, display both characters doc.add(newphrase); //clean doc.close(); } } }
Comments
Post a Comment