使用iTextSharp CSSResolver类的命名空间

时间:2015-01-29 10:32:54

标签: asp.net vb.net itextsharp

我正在使用iTextSharp CSSResolver类在vb.net中使用外部css

请告诉我使用XMLWorkerFontProviderCssFilesImplStyleAttrCSSResolver类的命名空间。

以下是我的代码:

    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)

由于 拉梅什

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 个答案:

答案 0 :(得分:2)

似乎你正在混合两种不同的东西。当我看到iTextSharp.text.html.simpleparser时,我假设您使用的是旧的HTMLWorker,这是一个已停止使用的类。

当我查看您的代码时,我发现您正在使用XML Worker,它需要一个单独的DLL(itextsharp.xmlworker.dll)。您使用的课​​程位于iTextSharp.tool.xml,与iTextSharp.text.html.simpleparser无关。您可以downloading the ZIP file查看itextsharp-src-xmlworker.zip中的源代码。