"object reference not set to object instance" for HTMLWorker parser

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 on worker.Parse, it throws an error, as indicated in the name.

Recycled HTML is the HTML string of an HTML page.

Does anyone know how to solve this, or what is going wrong?

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
+6
source share
2 answers

I think the problem is the exclusion of the null reference, which is caused due to HTML tags that the parser could not handle. try removing tags although HTMLWorker is no longer supported. This is discontinued in favor of XML Worker

+3
source

It looks like a null reference. Try using sintaxis "using" with all IDisposable elements:

 using (HTMLWorker worker = new HTMLWorker(document)) { (......) } 
+1
source

Source: https://habr.com/ru/post/946041/


All Articles