locked
ITextSharp RRS feed

  • Question

  • User-547121016 posted

    hi

    in my document there are some < characters.when i create a pdf using itextsharp it gives a error due to that character.how i fix it

    thanks 

    Monday, December 6, 2010 1:00 AM

All replies

  • User384031199 posted

    Hi,

    Try HTML Encoding.

    http://www.java2s.com/Open-Source/CSharp/PDF/iTextSharp/iTextSharp/text/html/HtmlEncoder.cs.htm

    Hope this helps.

     

    Monday, December 6, 2010 1:07 AM
  • User-547121016 posted

    i push the gridview direcly.cant replace < character

    here my code 

            protected void generatepdfbtn_Click(object sender, EventArgs e)
            {
                if (Session["AgentCode"] != null)
                {
    
                    DateTime dat = Convert.ToDateTime(getTimeZone(Session["AgentCode"].ToString()));
                    string datetime = dat.ToString();
                    datetime = datetime.Replace("/", "-");
                    datetime = datetime.Replace(":", "-");
    
    
                    Response.ContentType = "application/pdf";
                    Response.AddHeader("content-disposition", "attachment;filename=Transactions.pdf");
    
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    StringWriter sw = new StringWriter();
                    HtmlTextWriter hw = new HtmlTextWriter(sw);
                    //transactiongrid.AllowPaging = false;
                    //transactiongrid.DataBind();
                    transactiongrid.RenderControl(hw);
                    StringReader sr = new StringReader(sw.ToString());
                    Document pdfDoc = new Document(PageSize.B0, 10f, 10f, 10f, 0f);
                    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    Response.Write(pdfDoc);
                    Response.End();
                }
            }
    


     

    Monday, December 6, 2010 1:22 AM
  • User-547121016 posted

    hi.

    solved it.when bind the gridview replace the < character with &lt;

    thanks 

    Monday, December 6, 2010 2:45 AM