/** * Create a clone of this HtmlPipelineContext, the clone only contains the * initial values, not the internal values. Beware, the state of the current * Context is not copied to the clone. Only the configurational important * stuff like the LinkProvider (same object), ImageProvider (new * {@link AbstractImageProvider} with same ImageRootPath) , * TagProcessorFactory (same object), acceptUnknown (primitive), charset * (Charset.forName to get a new charset), autobookmark (primitive) are * copied. */ public object Clone() { HtmlPipelineContext newCtx = new HtmlPipelineContext(); if (this.imageProvider != null) { String rootPath = imageProvider.GetImageRootPath(); newCtx.SetImageProvider(new CloneImageProvider(rootPath)); } if (null != this.charset) { newCtx.CharSet(Encoding.GetEncoding(this.charset.CodePage)); } newCtx.SetPageSize(new Rectangle(this.pageSize)).SetLinkProvider(this.linkprovider) .SetRootTags(new List <String>(this.roottags)).AutoBookmark(this.autoBookmark) .SetTagFactory(this.tagFactory).SetAcceptUnknown(this.acceptUnknown); return(newCtx); }
/** * Create a clone of this HtmlPipelineContext, the clone only contains the * initial values, not the internal values. Beware, the state of the current * Context is not copied to the clone. Only the configurational important * stuff like the LinkProvider (same object), ImageProvider (new * {@link AbstractImageProvider} with same ImageRootPath) , * TagProcessorFactory (same object), acceptUnknown (primitive), charset * (Charset.forName to get a new charset), autobookmark (primitive) are * copied. */ virtual public object Clone() { CssAppliers cloneCssApliers = this.cssAppliers.Clone(); HtmlPipelineContext newCtx = new HtmlPipelineContext(cloneCssApliers); if (this.imageProvider != null) { newCtx.SetImageProvider(imageProvider); } if (resourcePath != null) { newCtx.ResourcePath = resourcePath; } if (null != this.charset) { newCtx.CharSet(Encoding.GetEncoding(this.charset.CodePage)); } newCtx.SetPageSize(new Rectangle(this.pageSize)).SetLinkProvider(this.linkprovider) .SetRootTags(new List <String>(this.roottags)).AutoBookmark(this.autoBookmark) .SetTagFactory(this.tagFactory).SetAcceptUnknown(this.acceptUnknown); return(newCtx); }
/** * Create a clone of this HtmlPipelineContext, the clone only contains the * initial values, not the internal values. Beware, the state of the current * Context is not copied to the clone. Only the configurational important * stuff like the LinkProvider (same object), ImageProvider (new * {@link AbstractImageProvider} with same ImageRootPath) , * TagProcessorFactory (same object), acceptUnknown (primitive), charset * (Charset.forName to get a new charset), autobookmark (primitive) are * copied. */ virtual public object Clone() { CssAppliers cloneCssApliers = this.cssAppliers.Clone(); HtmlPipelineContext newCtx = new HtmlPipelineContext(cloneCssApliers); if (this.imageProvider != null) { newCtx.SetImageProvider(imageProvider); } if (null != this.charset) { newCtx.CharSet(Encoding.GetEncoding(this.charset.CodePage)); } newCtx.SetPageSize(new Rectangle(this.pageSize)).SetLinkProvider(this.linkprovider) .SetRootTags(new List<String>(this.roottags)).AutoBookmark(this.autoBookmark) .SetTagFactory(this.tagFactory).SetAcceptUnknown(this.acceptUnknown); return newCtx; }
private void processHtml(IElementHandler elementsHandler) { var cssResolver = new StyleAttrCSSResolver(); if (CssFilesPath != null && CssFilesPath.Any()) { foreach (var cssFile in CssFilesPath) { cssResolver.AddCss(XmlWorkerUtils.GetCssFile(cssFile)); } } if (!string.IsNullOrEmpty(InlineCss)) { cssResolver.AddCss(InlineCss, "utf-8", true); } var htmlContext = new HtmlPipelineContext(new CssAppliersImpl(new UnicodeFontProvider(DefaultFont))); if (!string.IsNullOrEmpty(ImagesPath)) { htmlContext.SetImageProvider(new ImageProvider { ImagesPath = ImagesPath }); } htmlContext.CharSet(Encoding.UTF8); var tagsProcessorFactory = (DefaultTagProcessorFactory)Tags.GetHtmlTagProcessorFactory(); if (PdfElement != null) { tagsProcessorFactory.AddProcessor("totalpagesnumber", new TotalPagesNumberXmlWorkerProcessor(PdfElement)); } htmlContext.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(tagsProcessorFactory); var pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new ElementHandlerPipeline(elementsHandler, null))); var worker = new XMLWorker(pipeline, parseHtml: true); var parser = new XMLParser(); parser.AddListener(worker); parser.Parse(new StringReader(Html)); }