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

    }

Northwind Traders Receipt

Thank you for shopping at Northwind Traders. Your order details are below.

Order Information

Items In Your Order

Banana king

Site du Zero

Thank you for your business! If you have any questions about your order, please contact us at 800-555-NORTH.

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