Stack empty使用iTextSharp将HTML转换为PDF时出错 [英] Stack empty Error when using iTextSharp for converting HTML to PDF
本文介绍了Stack empty使用iTextSharp将HTML转换为PDF时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以PDF格式导出我的htmlcode
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的类型为StringBuilder
//htmlcode is of type 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)
有什么想法吗?提前谢谢
Any idea? thanks in advance
推荐答案
HTMLWorker已弃用,不会被维护。它被xml-worker取代。
HTMLWorker is deprecated and won't be maintained. it's replaced with xml-worker.
这篇关于Stack empty使用iTextSharp将HTML转换为PDF时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文