/** * Parses the xml data. This method configures the XMLWorker to parse * (X)HTML/CSS and accept unknown tags. Writes the output in the given * PdfWriter with the given document. * * @param writer the PdfWriter * @param doc the Document * @param inp the reader * @throws IOException thrown when something went wrong with the IO */ virtual public void ParseXHtml(PdfWriter writer, Document doc, TextReader inp) { CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add(GetDefaultCSS()); StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles); HtmlPipelineContext hpc = new HtmlPipelineContext(null); hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(GetDefaultTagProcessorFactory()); IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(hpc, new PdfWriterPipeline(doc, writer))); XMLWorker worker = new XMLWorker(pipeline, true); XMLParser p = new XMLParser(); p.AddListener(worker); p.Parse(inp); }
/** * Parses the xml data. This method configures the XMLWorker to parse * (X)HTML/CSS and accept unknown tags. Writes the output in the given * PdfWriter with the given document. * * @param writer the PdfWriter * @param doc the Document * @param in the reader * @throws IOException thrown when something went wrong with the IO */ public PdfTemplate ParseToTemplate(PdfContentByte cb, TextReader input) { CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add(GetDefaultCSS()); ICSSResolver cssResolver = new StyleAttrSvgCSSResolver(cssFiles); SvgPipelineContext hpc = new SvgPipelineContext(); hpc.SetTagFactory(GetDefaultTagProcessorFactory()); PdfTemplatePipeline templatePipeline = new PdfTemplatePipeline(cb); IPipeline pipeline = new CssResolverPipeline(cssResolver, new SvgPipeline(hpc, templatePipeline)); XMLWorker worker = new XMLWorker(pipeline, true); XMLParser p = new XMLParser(); p.AddListener(worker); p.Parse(input); return(templatePipeline.GetTemplate()); }
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)); }
/** * @param html * @param p * @return */ private StringBuilder Init(String html, XMLParser p) { writer = new StringBuilder(html.Length); p.AddListener(new ParserListenerWriter(new CustomAppender(), false)); return(writer); }