0

I want to export in pdf my htmlcode

var document = new Document();
            string filePath = Server.MapPath("~/generatedBook");
            string exceptionPath = Server.MapPath("~/exceptions");
            PdfWriter pdfWriter = PdfWriter.GetInstance(document,
            new FileStream(filePath + "/Book"+_IdSes+".pdf", FileMode.Create));
            pdfWriter.SetFullCompression();
            pdfWriter.StrictImageSequence = true;
            pdfWriter.SetLinearPageMode();


            try
            {
                document.SetPageSize(PageSize.A4.Rotate());
                document.SetPageSize(new Rectangle(792f, 612f)); // 11" x 8.5"

//here it it gives me exception stack is empty

List<iTextSharp.text.IElement> htmlarraylist = 
 iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new 
                                         StringReader(htmlcode.ToString()), st);

//htmlcode is of type StringBuilder

foreach (IElement t in htmlarraylist)
                {
                    document.Add((IElement)t);
                }


                document.Close();

Full Exception

System.InvalidOperationException: Stack empty.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.Stack`1.Pop()
   at iTextSharp.text.html.simpleparser.HTMLWorker.EndElement(String tag)
   at iTextSharp.text.xml.simpleparser.SimpleXMLParser.ProcessTag(Boolean start)
   at iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader)
   at iTextSharp.text.xml.simpleparser.SimpleXMLParser.Parse(ISimpleXMLDocHandler doc,          
   ISimpleXMLDocHandlerComment comment, TextReader r, Boolean html)
   at iTextSharp.text.html.simpleparser.HTMLWorker.Parse(TextReader reader)

Any idea? thanks in advance

1 Answer 1

1

HTMLWorker is deprecated and won't be maintained. it's replaced with xml-worker.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.