Problems with the font tags and div tags in xml worker

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

Problems with the font tags and div tags in xml worker

Salman Ghani



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><font color="#ff0000">text in Red now</font>.</div>

<div><font face="Tahoma" size="5">a font thoma and size 5.</font></div>

<div><font face="Tahoma" size="5"><font face="Arial" size="3">here is a link to </font><a href=""><font face="Arial" size="3">Google</font></a>.</font></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>

<span style="color:#ff0000">text in Red now</span>.

        <br />

        <span style="font-family:Tahoma; font-size:5">a font thoma and size 5.</span>


        <span style="font-family:Tahoma; font-size:5">

          <span style="font-family:Arial; font-size:3">here is a link to </span><a href="">

            <span style="font-family:Arial; font-size:3">Google</span>



        <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.


Kind Regards


Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
iText-questions mailing list
[hidden email]

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book:
Please check the keywords list before you ask for examples: