Problems with the font tags and div tags in xml worker

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

Hi

 

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="http://www.w3.org/1999/xhtml"><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="http://www.google.co.uk/"><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>

        <br/>

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

          <span style="font-family:Arial; font-size:3">here is a link to </span><a href="http://www.google.co.uk/">

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

          </a>.

        </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();

cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS());

StyleAttrCSSResolver cssRevolver = new StyleAttrCSSResolver();

HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);

htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());

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);

xmlParser.Parse(html);

 

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

Salman


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

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: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php