Hi Andrew

You are not putting the CssFiles in the cssResolver, without the default css file the XMLWorker does not know how to style a lot of tags.
replace

StyleAttrCSSResolver cssRevolver = new StyleAttrCSSResolver();

with

StyleAttrCSSResolver cssRevolver = new StyleAttrCSSResolver(cssFiles);



( Note I compared with Java code, I don't know Sharp code; i don't have an environment to run it either, I would most likely understand it though )
Please subscribe to the mailing list for decent follow ups.



On 20/12/2011 17:20, Andrew E wrote:
Hi,

I'm using iTextSharp to build a PDF from XHTML data, and I'm having trouble
getting some of the default HTML tags to render properly.  I originally used
the ParseXHtml method to build the PDF, and that works fine.  I needed to
set a relative URL location for my images, so I created a custom pipeline to
do it.  While the images render correctly, some tags, such as b and i, do
not.  Am I doing something wrong setting the tag factory?  Here's the code
I'm currently using.

MemoryStream memStream = new MemoryStream();

StringReader xmlString = new StringReader(outXml);

using (Document document = new Document())
{
    PdfWriter writer = PdfWriter.GetInstance(document, memStream);
    document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
    document.Open();

    CssFilesImpl cssFiles = new CssFilesImpl();
    cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS());
    StyleAttrCSSResolver cssRevolver = new StyleAttrCSSResolver();

    HtmlPipelineContext htmlContext = new HtmlPipelineContext();
    htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());

    htmlContext.SetImageProvider(new MyImageProvider(imagePath));

    IPipeline pipeline = new CssResolverPipeline(cssRevolver, new
HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));
    XMLWorker worker = new XMLWorker(pipeline, true);
    XMLParser p = new XMLParser(worker);
    p.Parse(xmlString);

    document.Close();
}




Kind regards

Balder
--
twitter <http://twitter.com/redlabbe>
redlab-log <http://www.redlab.be/blog/>
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
iText-questions mailing list
[email protected]
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

Reply via email to