Click here to Skip to main content
15,040,743 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
'Stack Empty' error when using iTextSharp for converting HTML to PDF.
My code snippet:
C#
dg1.Columns[11].Visible = false;
            string attachment = "attachment; filename=AllPage.pdf";
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/pdf";
            StringWriter stw = new StringWriter();
            HtmlTextWriter htextw = new HtmlTextWriter(stw);

            form1.RenderControl(htextw);
            Document document = new Document();
            PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            StringReader str = new StringReader(stw.ToString());
            HTMLWorker htmlworker = new HTMLWorker(document);
            htmlworker.Parse(str);//stack empty
            document.Close();
            Response.Write(document);
            Response.End();
Posted
Updated 13-Sep-17 4:49am
v2

Make sure you do not close the table in HTML template and add it via code -
"</table>"
   
Comments
Kats2512 14-Sep-17 10:28am
   
do you think that after 5 years this person would still be looking for an answer?

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