iTextSharp font tag not working with XMLWorker class

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

iTextSharp font tag not working with XMLWorker class


I’m using itextsharp 5.3.5 and xml worker to generate the PDF from my html page. In my html page I have a rich text editor which generate the html using the div tags and font tags. Please see the below html piece generated by my field.

<html xml:space="preserve" xmlns=""><div>this text is not <strong>working</strong></div>
<div>text in Red now.</div>
<div>a font thoma and size 5.</div>
<div>here is a link to Google.</div></html>

I found that if I use html worker instead then it converts the above html perfectly in pdf. But not the xml worker. It just didn’t work.

I also found that if I change some of the tags and update my html like below, then xml worker converts it in pdf.

<p>this text is not <strong>working</strong></p>
text in Red now.
        <br />
        a font thoma and size 5.
          here is a link to

        <br />

Now obviously I can’t change the html tags on run time, it will be a big mess. My code is as below.

StringReader html = new StringReader(htmlString);
var xmlWorkerFontProvider = new XMLWorkerFontProvider();
var cssAppliers = new CssAppliersImpl(xmlWorkerFontProvider);
CssFilesImpl cssFiles = new CssFilesImpl();
StyleAttrCSSResolver cssRevolver = new StyleAttrCSSResolver();
HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
PdfWriterPipeline pdfWriterPipeline = new PdfWriterPipeline(document, writer);
IPipeline pipeline = new CssResolverPipeline(cssRevolver, new HtmlPipeline(htmlContext, pdfWriterPipeline));
XMLWorker worker = new XMLWorker(pipeline, true);                
XMLParser xmlParser = new XMLParser(worker);

I would really appreciate if you can guide me, how I can convert the above html in pdf using the xml worker.

If you need any further information, please do let me know.