Hi Myriam

What is your environment? Is this a WinForm or WebForm application?

Is ANY part of your external CSS working? Colour, Size etc?

From: Myriam Economou [mailto:myriam.econo...@gmail.com]
Sent: Friday, 10 February 2012 9:01 p.m.
To: itext-questions@lists.sourceforge.net
Subject: Re: [iText-questions] XMLWorker : HTML to PDF problem with external css

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<mailto: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<mailto:myriam.econo...@gmail.com>]
Sent: Friday, 10 February 2012 3:45 a.m.
To: 
itext-questions@lists.sourceforge.net<mailto: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<mailto: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

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