ItextSharp:Solution use of Align_Justified_All in Persian text

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ItextSharp:Solution use of Align_Justified_All in Persian text

BH67
I want to create Persian PDF using iTextsharp but when set HorizontalAlignment to Element.ALIGN_JUSTIFIED_ALL text displayed with large spaces between words. using spacecharratio property didn't help me. how can i solve this problem with useing HorizontalAlignment=Element.ALIGN_JUSTIFIED_ALL`?

           FontSelector fontSelector = new FontSelector();
            FontFactory.Register(Application.StartupPath + "\\fonts\\BNazanin.ttf");
            Font BNazanin = FontFactory.GetFont("BNazanin",                                               BaseFont.IDENTITY_H,BaseFont.EMBEDDED,10);
            FontFactory.Register(Application.StartupPath + "\\fonts\\Tahoma.ttf");
            Font Tahoma = FontFactory.GetFont("Tahoma",
            BaseFont.IDENTITY_H,BaseFont.EMBEDDED, 10);
            if (BNazanin.Familyname != "unknown")
            {
                fontSelector.AddFont(BNazanin);
            }
            if (Tahoma.Familyname != "unknown")
            {
                fontSelector.AddFont(Tahoma);
            }
                PdfWriter Writer = PdfWriter.GetInstance(Doc, MemoryStream);
                Writer.PageEvent = new pageborder();
                Writer.SpaceCharRatio = PdfWriter.NO_SPACE_CHAR_RATIO;
                Doc.Open();
            PdfPTable Contract_Content = new PdfPTable(1);
            Contract_Content.HorizontalAlignment = Element.ALIGN_CENTER;
            Contract_Content.SpacingBefore = 5f;
            foreach (var item in content)
            {
                 PdfPCell Content  = new PdfPCell();
                Paragraph p_content = new Paragraph(fontSelector.Process(item.Description));
                p_content.Alignment = Element.ALIGN_JUSTIFIED_ALL;
                Content.AddElement(p_content);
                Content.PaddingRight = 40f;
                Content.DisableBorderSide(PdfPCell.BOTTOM_BORDER);
                Content.DisableBorderSide(PdfPCell.LEFT_BORDER);
                Content.DisableBorderSide(PdfPCell.RIGHT_BORDER);
                Content.DisableBorderSide(PdfPCell.TOP_BORDER);
                Content.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
                Content.HorizontalAlignment = Element.ALIGN_JUSTIFIED_ALL;
                Content.PaddingBottom = 10f;
                Contract_Content.AddCell(Content);
}
Doc.Add(Contract_Content);
Loading...