2
votes

I am using iTextSharp CSSResolver classes for using external css in vb.net

Please let me know the namespaces for using XMLWorkerFontProvider, CssFilesImpl, StyleAttrCSSResolver classes.

Below is my code:

    Dim fontProvider As XMLWorkerFontProvider = New XMLWorkerFontProvider()

    Dim cssFiles As CssFilesImpl = New CssFilesImpl(fontProvider)

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

    Dim cssRevolver As StyleAttrCSSResolver = New StyleAttrCSSResolver()

    Dim htmlContext As HtmlPipelineContext = New HtmlPipelineContext()

    htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory())

    htmlContext.SetImageProvider(New MyImageProvider(imagePath))

    Dim pipeline As IPipeline = New CssResolverPipeline(cssRevolver, New HtmlPipeline(htmlContext, New PdfWriterPipeline(Document, writer)))

    Dim worker As XMLWorker = New XMLWorker(pipeline, True)

    Dim p As XMLParser = New XMLParser(worker)

    p.Parse(xmlString)

Thanks Ramesh

Dim sw As New StringWriter()

Dim hw As New HtmlTextWriter(sw)

strMonthlyDataHtml = LoadReport("PDF")

ltrPDFReport.Text = strMonthlyDataHtml

ltrPDFReport.RenderControl(hw)

Dim sr As New StringReader(sw.ToString())

Dim pdfDoc As New Document(iTextSharp.text.PageSize.A4, 10.0F, 10.0F, 100.0F, 0.0F)

Dim memStream = New MemoryStream()

Dim writer = PdfWriter.GetInstance(pdfDoc, memStream)

writer.CloseStream = False

pdfDoc.Open()

Dim htmlContext As New HtmlPipelineContext(Nothing)

htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory())

Dim cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(False)

cssResolver.AddCssFile(Server.MapPath("../Assets/css/Efficiency.css"), True)

cssResolver.AddCssFile(Server.MapPath("/Assets/css/Efficiency.css"), True)

Dim pipeline As IPipeline = New CssResolverPipeline(cssResolver, New
HtmlPipeline(htmlContext, New PdfWriterPipeline(pdfDoc, writer)))

Dim worker As XMLWorker = New XMLWorker(pipeline, True)

Dim p As New XMLParser(worker)

p.Parse(sr)

pdfDoc.Close()

1

1 Answers

2
votes

It seems that you are mixing two different things. When I see iTextSharp.text.html.simpleparser, I assume that you are using the old HTMLWorker, a class that has been discontinued.

When I look at your code, I see that you are using XML Worker, which requires a separate DLL (itextsharp.xmlworker.dll). The classes you use are in iTextSharp.tool.xml, and have nothing to do with iTextSharp.text.html.simpleparser. You can check this, by downloading the ZIP file and looking at the source code in itextsharp-src-xmlworker.zip.