Thank you so much for your answer. I really appreciate the help.
Unfortunately it is not working for me.

I attached my modified class to the mail. I think I have tried all possible
paths both in my class and in my HTML file ^^

Could it have something to do that I am not using a server but two files on
my computer?
What path(relative/absolute) did you put in your HTML file? I am using
Windows : maybe something wrong with the path to adopt
(C:\...\,C:\\...\\...,file:///C:/...., or a normal Unix path /Users/...)
Maybe some wrong attributes in the link tag(I am using just the supported
ones: type and href)?

/Myriam

ps: Good tip for the CSS fonts!

2012/2/9 Dean McCarthy <dean.mccar...@bcmi.co.nz>

> Hi Myriam****
>
> ** **
>
> It looks like you’re not telling XMLworker about your external CSS file.**
> **
>
> ** **
>
> Here is my working code, in VB…****
>
> ** **
>
>     Protected Sub AddHTML(ByVal HTMLContent As String)****
>
>         Dim HtmlContext As HtmlPipelineContext = New HtmlPipelineContext**
> **
>
>         HtmlContext.SetTagFactory(iTextSharp.tool.xml.html.Tags
> .GetHtmlTagProcessorFactory)****
>
> ****
>
>         Dim CSSResolver As ICSSResolver = XMLWorkerHelper
> .GetInstance().GetDefaultCssResolver(True)****
>
>         ****
>
>         ‘--- The location of the external CSS file****
>
>         Dim BCMiCss As String = HttpContext.Current.Server.MapPath(
> "~/App_Obout/HTMLEditor/CSS/BCMiQuickFormat.css")****
>
>          ****
>
>         ‘--- Add the external CSS file        ****
>
>         CSSResolver.AddCssFile(BCMiCss, True)****
>
> ****
>
>         Dim Pipeline As IPipeline = New CssResolverPipeline(CSSResolver,
> New HtmlPipeline(HtmlContext, New PdfWriterPipeline(Document, PDFWriter)))
> ****
>
>         Dim Worker As XMLWorker = New XMLWorker(Pipeline, True)****
>
>         Dim Parser As XMLParser = New XMLParser(True, Worker)****
>
>         Parser.Parse(New StringReader(HTMLContent))****
>
>         Parser.Flush()****
>
>     End Sub****
>
> ** **
>
> Also, just as something else to be aware of, if you create your CSS in
> Visual Studio and any of your font names have more than one word and are
> enclosed in quotes, such as****
>
> ** **
>
> body****
>
> {****
>
>     font-family: ‘Century Gothic’;****
>
>     font-size: 10pt;****
>
>     color: #000000;****
>
> }****
>
> ****
>
> XMLWorker will NOT render this font. You’ll need to remove the quotes,
> such as ****
>
> ** **
>
> body****
>
> {****
>
>     font-family: Century Gothic;****
>
>     font-size: 10pt;****
>
>     color: #000000;****
>
> }****
>
> ** **
>
> And XMLWorker will render the font correctly.****
>
> ** **
>
> Cheers****
>
> ** **
>
> Dean****
>
> ** **
>
> *From:* Myriam Economou [mailto:myriam.econo...@gmail.com]
> *Sent:* Friday, 10 February 2012 3:45 a.m.
> *To:* itext-questions@lists.sourceforge.net
> *Subject:* [iText-questions] XMLWorker : HTML to PDF problem with
> external css****
>
> ** **
>
> Hi,
>
> For a project I have to parse an HTML page into a pdf using XMLWorker and
> I am encountering a problem since my external css file is not taken into
> consideration.
> I had no problem parsing a simple HTML file, an HTML file with CSS in the
> tags, HTML file with CSS in the <head> but the external CSS file is not
> working.
> I am using Visual studio to develop in C# and both my files (HTML and CSS)
> are included in the project and are located in the same folder as the other
> files of the project so they should find each other easily....or?:)
> I attached my files to this mail.
>
> I thank you in advance for any hints you could gave me. I spent already 2
> days browsing the documentation and internet to find similar issues but in
> their example they all put CSS in the <head> tag.
>
> Have a nice day
>
> Myriam****
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> iText-questions mailing list
> iText-questions@lists.sourceforge.net
> 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
>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.tool.xml;
using iTextSharp.tool.xml.html;
using iTextSharp.tool.xml.parser;
using iTextSharp.tool.xml.css;
using iTextSharp.tool.xml.pipeline.html;
using iTextSharp.tool.xml.pipeline.css;
using iTextSharp.tool.xml.pipeline.end;

    class Class1
    {
        public void createInvoiceFromHtmlUsingXmlWorker()
        {
            //Step 1 : basics
            Document document = new Document(PageSize.A4, 50, 50, 50, 50);
            // Create a writer that listens to the document and direct and 
XML-Stream to a file
            PdfWriter writer = PdfWriter.GetInstance(document, new 
FileStream("C:\\Users\\myreco\\InvoiceFromHtmlXmlWorker.pdf", FileMode.Create));
            document.Open();
            //HtmlPipeline
            HtmlPipelineContext htmlContext = new HtmlPipelineContext();
            htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
            //CSS stuff
            ICSSResolver cssResolver = 
XMLWorkerHelper.GetInstance().GetDefaultCssResolver(true);
            // I have tried both path "file:C..."and "C:\\" and in the css file 
to none works
            //cssFile =  
httpContext.Current.Server.MapPath("file:///C:/Users/myreco/");
            cssResolver.AddCssFile("C:\\Users\\myreco\\style.css", true);
            //Pipeline
            IPipeline pipeline = new CssResolverPipeline(cssResolver, new 
HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));
            //XMLWorker
            XMLWorker worker = new XMLWorker(pipeline, true);
            //and...we parse
            XMLParser p = new XMLParser(worker);
            p.Parse(((Stream)new 
FileStream("C:\\Users\\myreco\\VisualStudio\\PremiereApplication\\ConsoleApplication1\\test.html",
 FileMode.Open)));
            //Close document
            document.Close();
        }

    }

Banana King

body{ color: red; }
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
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