Click here to Skip to main content
15,885,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have html string, which has Arabic text.
I'm using stringreader and htmlworker to generate PDF.
But, its not working.
Please, help me.

Following is code:

C#
protected void Button1_Click(object sender, EventArgs e)
    {
          string myString;
          myString =Page_ARABIC();
            
          string attachment = "attachment; filename=Simple.pdf";
          Response.ClearContent();
          Response.AddHeader("content-disposition", attachment);
          Response.ContentType = "application/pdf";

          iTextSharp.text.Document document = new iTextSharp.text.Document();
          PdfWriter.GetInstance(document, Response.OutputStream);
          document.Open();

          StringReader str = new StringReader(myString);
          HTMLWorker htmlworker = new HTMLWorker(document);
          htmlworker.Parse(str);
            
          document.Close();
          Response.Write(document);
          Response.End();
}


    public String Page_ARABIC()
    {

       

        String strTable = "";
        strTable = strTable + " <table width="100%" charset="Windows-1256" dir="rtl"> ";
        strTable = strTable + " <tr> ";
        strTable = strTable + "  <td align="center" colspan="4"> ";
        strTable = strTable + "  <table border="0" cellpadding="0" cellspacing="0" width="100%"> ";
        strTable = strTable + "  <tr> ";
        strTable = strTable + "  <td width="20%"> ";
        strTable = strTable + "  </td> ";
        strTable = strTable + "  <td width="60%"> ";
        strTable = strTable + "  <img height='100' src='" + Path + "' ";
        strTable = strTable + "  width='300' /></td> ";
        strTable = strTable + "  <td width="20%"> ";
        strTable = strTable + "  </td> ";
        strTable = strTable + "  </tr> ";
        strTable = strTable + "  </table> ";
        strTable = strTable + "  </td> ";
        strTable = strTable + "  </tr> ";
        strTable = strTable + "  <tr> ";
        strTable = strTable + "  <td align="center" colspan="4"> ";
        strTable = strTable + "  <span style="color: #1f497d; font-family: Garamond; font-size: 16pt;">  منتصف السنة نموذج تقييم الأداء</span> ";
        strTable = strTable + "  </td> ";
        strTable = strTable + "  </tr> ";
        strTable = strTable + "  <tr> ";
        strTable = strTable + "  <td align="center" colspan="4" style="height: 21px"> ";
        strTable = strTable + "  <span style="text-align: center; text-decoration: underline">    <span style="font-size: 14pt"> ";
        strTable = strTable + "  <span style="color: #1f497d"><span style="font-family: Garamond">المادة 1: تفاصيل مهمة<o:p xmlns:o="#unknown"></o:p></span></span></span></span></td> ";
        strTable = strTable + " </tr></table> ";

        return strTable;
    }
Posted
Updated 19-Jul-12 21:36pm
v2
Comments
Krunal Rohit 2-Oct-15 6:20am    
If the text is Arabic and then you need to set the .RunDirection of the PdfpTable or PdfPCell accordingly.
Ensure that PdfPCell.NoWrap is set to false on the default cell of the table and any cells that you may create manually, if wrapping is turned off the right to left text will not be displayed.

-KR

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