【问题标题】:Stack empty Error when using iTextSharp for converting HTML to PDF使用 iTextSharp 将 HTML 转换为 PDF 时出现堆栈空错误
【发布时间】:2012-08-06 06:37:01
【问题描述】:

我想以 pdf 格式导出我的 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"

//这里它给了我异常堆栈是空的

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

//htmlcode是StringBuilder类型

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


                document.Close();

完全异常

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)

有什么想法吗?提前致谢

【问题讨论】:

    标签: c# asp.net itextsharp html-to-pdf


    【解决方案1】:

    HTMLWorker 已被弃用并且不会被维护。它已被 xml-worker 取代。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      相关资源
      最近更新 更多