As Bruno said, upgrade it to XMLWorker.
What you need to do is implement the no longer supported IHTMLTagProcessor interface for the HTML tag that interests you. in the img tag, so you just want to use basically what iText already does, but with your own logic. Unfortunately, their class is private, so you cannot just subclass it, but see its contents here . Basically you get a class like this:
public class MyImageTagProcessor : IHTMLTagProcessor { void IHTMLTagProcessor.EndElement(HTMLWorker worker, string tag) { //No used } void IHTMLTagProcessor.StartElement(HTMLWorker worker, string tag, IDictionary<string, string> attrs) { if (!attrs.ContainsKey(HtmlTags.WIDTH)) { //Do something special here attrs.Add(HtmlTags.WIDTH, "400px"); } if (!attrs.ContainsKey(HtmlTags.HEIGHT)) { //Do something special here attrs.Add(HtmlTags.HEIGHT, "400px"); } worker.UpdateChain(tag, attrs); worker.ProcessImage(worker.CreateImage(attrs), attrs); worker.UpdateChain(tag); } }
Then, in your code, create a Dictionary by holding the tag you are targeting and an instance of this class:
var processors = new Dictionary<string, IHTMLTagProcessor>(); processors.Add(HtmlTags.IMG, new MyImageTagProcessor());
Finally, change your syntax call to use one of the overloads. We do not need the fourth parameter (providers), so we pass it a zero.
var elements = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(sr, styles, processors, null);
Chris Haas Jul 01 '14 at 14:10 2014-07-01 14:10
source share