Document document = new Document(PageSize.LETTER, 10, 10, 10, 10);
StringReader reader = new StringReader(edittedHTML);
HTMLWorker worker = new HTMLWorker(document);
string fileName = "test.pdf";
PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
document.Open();
worker.Parse(reader);
worker.EndDocument();
worker.Close();
document.Close();
当程序运行到worker.Parse时,它会抛出错误,就像标题所说的那样。
edtted HTML是HTML页面的HTML字符串。
任何人都知道如何解决这个问题,或者出了什么问题?
堆栈跟踪:
at iTextSharp.text.html.simpleparser.HTMLWorker.StartElement(String tag, IDictionary`2 attrs) 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) at TestPdfApplication.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\TLiu\Documents\Visual Studio 2010\Projects\TestPdfApplication\TestPdfApplication\Form1.cs:line 68
答案 0 :(得分:3)
我认为问题是由于解析器无法处理的HTML tags
引发的空引用异常。尝试删除标签
虽然不再支持HTMLWorker。
It's discontinued in favor of XML Worker
答案 1 :(得分:1)
它看起来像一个空引用。尝试将sintaxis“using”与所有IDisposable项目一起使用:
using (HTMLWorker worker = new HTMLWorker(document))
{ (......) }