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()
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0