Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
dear all

now the arabic string does not displayed at all in the PDF

i tried the following :

 string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\times.ttf";
BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
Font arabicFont = new iTextSharp.text.Font(basefont, 24, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLUE);

table.RunDirection =PdfWriter.RUN_DIRECTION_RTL;


i tried many other fonts
the arabic letters appeared but in reverse order from left to right and every letter is alone not connected to the adjacent one

please help
thanks
bye
Posted
Updated 5-Jul-11 22:26pm
v2

C#
public void PersianSupport(string sFilePDF)
        {
            Document document = new Document();
            try
            {
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(sFilePDF, FileMode.Create));
                document.Open();
                string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\times.ttf";
                BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
                iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 24, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLUE);


                var el = new Chunk();
                iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                                                el.Font.Style, el.Font.Color);
                el.Font = f2;
                PdfPTable table = new PdfPTable(1);
                
                table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
                
                var str = "نام : " ;
                PdfPCell cell = new PdfPCell(new Phrase(10, str, el.Font));
                table.AddCell(cell);

                document.Add(table);
                document.Close();

            }
            catch (DocumentException de)
            {
  //              this.Message = de.Message;
            }
            catch (IOException ioe)
            {
//                this.Message = ioe.Message;
            }

            // step 5: we close the document
            document.Close();


        }
 
Share this answer
 
v2
Comments
Adnan Siddiqi 25-Mar-13 3:41am    
Your code does print my text in Urdu format but it does not when I use custom Urdu TTF font. Any idea about this?
Sunasara Imdadhusen 31-Mar-20 23:06pm    
Great Answer...! +1
Design Plus 27-Feb-22 1:20am    
Thank You for this code It works for most of the texts but not for all of the values I mean it doesn't work for some special arabic charachters
Hi,

for multilingual support you can check sample codes given at the links below
Display Chinese Characters in PDF created by iTextSharp[^]
http://stackoverflow.com/questions/4930800/create-pdf-from-persian-html-file-by-itextsharp[^]
and regarding reverse order character appearance did you mean left to right? because arabic character starts from right to left unlike English
 
Share this answer
 
Comments
AhmedOsamaMoh 6-Jul-11 4:25am    
did not worked

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900