Friday 15 May 2015

c# - Unity3d iTextSharp arabic text formatting -



c# - Unity3d iTextSharp arabic text formatting -

i using itextsharp pdf generating in unity3d.

edit

here code, getting empty pdf document:

void createpdf() { document doc = new document(itextsharp.text.pagesize.a1, 5, 5, 5, 5); pdfwriter wri = pdfwriter.getinstance(doc, new filestream("testpdf.pdf", filemode.create)); doc.open(); string fontpath = "c:\\windows\\fonts\\arialuni.ttf"; basefont basefont = basefont.createfont(fontpath, basefont.identity_h, basefont.embedded); itextsharp.text.font tahomafont = new itextsharp.text.font(basefont, 10, itextsharp.text.font.normal, basecolor.red); pdfcontentbyte cb = wri.directcontent; columntext ct = new columntext(cb); phrase mytext = new phrase(gameobject.find("textplay").getcomponent<textmesh>().text); ct.setsimplecolumn(mytext, 34, 750, 580, 317, 15, element.align_left); ct.go(); doc.close(); }

the error message tells font arialjezici.ttf can't used encoding identity_h, hence have replace font one, instance arialuni.ttf.

actually, should work:

basefont bf = itextsharp.text.pdf.basefont.createfont("c:\\windows\\fonts\\arialuni.ttf", basefont.identity_h, basefont.embedded);

note need provide right path. don't think you're doing in example.

if above snippet doesn't work, see itextsharp arialuni.ttf re-create on hosting server alternative illustration on how this.

note standard arabic ligatures work in context of pdfpcell , columntext objects, not work in paragraph added document because can not set run direction of paragraph. can set run direction of cell or column.

if not set run direction, standard arabic text written left right , no ligatures made, resulting in not right arabic.

contrary rules on stackoverflow, original question changed, resulting in reply no longer beingness reply new version of question. update anser current question:

with basefont created in first part of answer, create font:

font font = new font(bf, 20);

now create columntext object , provide coordinates fit page:

columntext column = new columntext(writer.directcontent); column.setsimplecolumn(36, 730, 569, 36);

if these coordinates do not fit page, content added file, won't see because content outside visible area of page.

for standard arabic text, of import set run direction (i don't see doing anywhere):

column.rundirection = pdfwriter.run_direction_rtl;

now add together content:

column.addelement(new paragraph(gameobject.find("textplay").getcomponent<textmesh>().text)); column.go();

this works me, see java example or corresponding c# example, resulting in file: ligatures_2.pdf

that file shows standard arabic text "لورانس العرب" 3 times. first time, characters not in right order. sec time, characters in right order, no ligatures beingness made. 3rd time, shown correctly.

c# pdf unity3d itextsharp arabic

No comments:

Post a Comment