Skip to content Skip to sidebar Skip to footer

Itextsharp Htmlworker.parsetolist() Throws Nullreferenceexception

I am using iTextSharp v.4 to merge a whole bunch of html files. It was working fine until I needed to upgrade to v.5 of iTextSharp. The problem comes when I pass a streamreader (r

Solution 1:

It looks like HTMLWorker is choking on the two <hr width="100%" />. Since you said you're ugrading to V5.XX, it might also be good to start using XMLWorker to start parsing your HTML - the development team is recommending it. (the latest HTMLWorker source code even has a small reference pointing this out)

Tested with your extended HTML, it works, and isn't too bad to implement :)

using (Documentdocument = newDocument()) {
  PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);
  document.Open();
  try {
    StringReader sr = newStringReader(htmlString);
    XMLWorkerHelper.GetInstance().ParseXHtml(
      writer, document, sr
    );          
  }
  catch (Exception e) {
    throw;
  }
}

Tested in a web environment, so replace Response.OutputStream with the Stream of your choice.

Post a Comment for "Itextsharp Htmlworker.parsetolist() Throws Nullreferenceexception"