iTextSharp HTMLWorker.ParseToList() throws NullReferenceException

前端 未结 1 1260
情歌与酒
情歌与酒 2020-12-19 02:22

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

相关标签:
1条回答
  • 2020-12-19 02:54

    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 (Document document = new Document()) {
      PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);
      document.Open();
      try {
        StringReader sr = new StringReader(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.

    0 讨论(0)
提交回复
热议问题