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();
When the program runs to worker.Parse, it throws out an error just like the title said.
The edtted HTML is the HTML string of an HTML page.
Anyone know how to solve this, or what is going wrong?
The stack trace:
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
I think the problem is a null reference exception being thrown due to HTML tags
that the parser was unable to handle. try to remove the tags
although HTMLWorker is no longer supported.
It's discontinued in favor of XML Worker
It looks like a null reference. Try to use the sintaxis "using" with all the IDisposable items:
using (HTMLWorker worker = new HTMLWorker(document))
{ (......) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With