0

I am trying to convert create and download PDF file using String Builder

using the following code but on "htmlparser.Parse(sr);" i get an error..Saying as:

Input string is not in format.

Thanks in advance.

 using (StringWriter sw = new StringWriter())
            {
                using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<table style='border-collapse:collapse' border='1px solid black;'>");
                    sb.Append("<tr>");
                    sb.Append("<td>Dummy Data</td>");
                    sb.Append("</tr>");
                    sb.Append("</table>");

                    StringReader sr = new StringReader(sb.ToString());
                    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                    PdfWriter writer = PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    HttpContext.Current.Response.ContentType = "application/pdf";
                    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=POReport.pdf");
                    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    HttpContext.Current.Response.Write(pdfDoc);
                    HttpContext.Current.Response.End();

                }
            }
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
  • 1
    You are using a very old iText version and besides that `HTMLWorker` never worked that well. iText 7 has an excellent add-on to convert html that you should try. – Paulo Soares Aug 05 '18 at 14:33
  • can u suggest me some links from where i can understand the process??I need to create PDF file on button click – user7436968 Aug 05 '18 at 14:38
  • 1
    Here you have, example and all: https://itextpdf.com/itext7/pdfHTML. – Paulo Soares Aug 05 '18 at 14:41

0 Answers0