6

I have using itextsharp dll(v5.5.9.0) for generating a PDF from Html in Asp.net Mvc. In this, I am using a class HTMLWorker. I get a result that matches my requirement. It's working fine now. But it shows as [deprecated]. In the future, will it be working/supported or not? (or can I move to xmlworker?)

Noam Hacker
  • 4,671
  • 7
  • 34
  • 55

1 Answers1

11

The HTMLWorker class is deprecated. It was started as a personal project to parse small HTML snippets. It was written without a clear design. It needed to serve the purpose of an individual in one specific project.

However, it got into the main release somehow and people started to use it for purposes for which it wasn't built. People complained about bugs without knowing that HTMLWorker was never meant to do any heavy lifting.

Other developers started improving HTMLWorker but soon hit the limitations of the flawed design (and the spaghetti code).

XML worker is a project that was done by developers paid for by iText Group. It is used in different projects. It wasn't meant as an URL2PDF tool, in the sense that it can't convert a complex web page to PDF, but it allows you to create templates using straight-forward HTML and CSS, populate those templates, and convert them to PDF.

XML Worker suffers from the fact that iText initially wasn't meant to render HTML. For instance: in iText 5 (and previous versions), properties such as fonts, colors,... aren't inherited. These flaws are fixed in iText 7. XML Worker hasn't been ported to iText 7 yet, but it's next on our technical road map.

To summarize: you shouldn't use HTMLWorker. It won't be supported in the future.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Thank You @Bruno Lowagie :) – U M A M A H E S H Aug 10 '16 at 13:39
  • You said "you shouldn't use HTMLWorker". But I "inherited" a project that uses it, and the developers (contractors) are gone so I can't ask them. Now what should I do? Is there a replacement for HTMLWorker? In that project it is used to render some HTML into a PDF document. – Matt Feb 10 '17 at 14:27
  • @Matt So you inherited a project that dates at least from 2009. You can either use XML Worker (iText 5.5.10) or you can wait for a week to get the all new iText 7 pdf2data tool. I've already seen demos of the new pdf2data and they are amazing. – Bruno Lowagie Feb 10 '17 at 18:07
  • Yes indeed, it is an old application. Thanks for the hint, I'll check both alternatives. – Matt Feb 13 '17 at 13:13
  • @BrunoLowagie: how can I replace `HTMLWorker` here `List htmlarraylist = HTMLWorker.ParseToList(new StringReader(page), null);` ? – Nad Jul 07 '20 at 05:40
  • Which class should be used instead of `HtmlWorker`? – Anders Lindén Feb 01 '22 at 17:24
  • @Nad did you got any replacement of List htmlarraylist = HTMLWorker.ParseToList(new StringReader(page), null); – Mr.Paul Apr 11 '22 at 09:50