本文介绍了命名空间使用iTextSharp的CSSResolver类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用iTextSharp的CSSResolver类在vb.net

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

请让我知道的命名空间,使用 XMLWorkerFontProvider CssFilesImpl StyleAttrCSSResolver 类。

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

下面是我的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)

谢谢
拉梅什

ThanksRamesh

昏暗SW作为新的StringWriter()

Dim sw As New StringWriter()

暗淡HW作为新的HtmlTextWriter(SW)

Dim hw As New HtmlTextWriter(sw)

strMonthlyDataHtml = LoadReport(PDF)

strMonthlyDataHtml = LoadReport("PDF")

ltrPDFReport.Text = strMonthlyDataHtml

ltrPDFReport.Text = strMonthlyDataHtml

ltrPDFReport.RenderControl(HW)

ltrPDFReport.RenderControl(hw)

昏暗SR作为新StringReader(sw.ToString())

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

昏暗pdfDoc作为新文档(iTextSharp.text.PageSize.A4,10.0F,10.0F,100.0F,0.0F)

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

暗淡memStream =新的MemoryStream()

Dim memStream = New MemoryStream()

昏暗的作家= PdfWriter.GetInstance(pdfDoc,memStream)

Dim writer = PdfWriter.GetInstance(pdfDoc, memStream)

writer.CloseStream =假

writer.CloseStream = False

pdfDoc.Open()

pdfDoc.Open()

昏暗htmlContext作为新HtmlPipelineContext(没有)

Dim htmlContext As New HtmlPipelineContext(Nothing)

htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory())

htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory())

点心cssResolver = XMLWorkerHelper.GetInstance()。GetDefaultCssResolver(假)

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

cssResolver.AddCssFile(使用Server.Mappath(../资产/ CSS / Efficiency.css),真)

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

cssResolver.AddCssFile(使用Server.Mappath(/资产/ CSS / Efficiency.css),真)

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

昏暗的管道作为IPipeline =新CssResolverPipeline(cssResolver,新结果
     HtmlPipeline(htmlContext,新PdfWriterPipeline(pdfDoc,作家)))

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

昏暗的工人作为XMLWorker =新XMLWorker(管道,真)

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

昏暗数p作为新XMLParser的(工人)

Dim p As New XMLParser(worker)

p.Parse(SR)

p.Parse(sr)

pdfDoc.Close()

pdfDoc.Close()

推荐答案

看来你是混合两种不同的东西。当我看到 iTextSharp.text.html.simpleparser ,我假设你正在使用旧 HTMLWorker ,一类已经停产了。

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.

当我看着你的code,我看你是使用XML工人,这需​​要一个单独的DLL(的)。您使用的类是 iTextSharp.tool.xml ,并有无关 iTextSharp.text.html.simpleparser 。您可以下载rel=\"nofollow\"> ZIP文件并查看源$ C ​​$检查,以 itextsharp-src-xmlworker.zip 。

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.

这篇关于命名空间使用iTextSharp的CSSResolver类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!