protected override void MakePdf(string outPdf) { Document doc = new Document(PageSize.A4.Rotate()); PdfWriter pdfWriter = PdfWriter.GetInstance(doc, new FileStream(outPdf, FileMode.Create)); doc.SetMargins(45, 45, 0, 100); doc.Open(); CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add( XMLWorkerHelper.GetCSS( File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName + Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar + "main.css"))); cssFiles.Add( XMLWorkerHelper.GetCSS( File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName + Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar + "widget082.css"))); StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles); HtmlPipelineContext hpc = new HtmlPipelineContext( new CssAppliersImpl(new XMLWorkerFontProvider(RESOURCES + @"\tool\xml\examples\fonts"))); hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(Tags.GetHtmlTagProcessorFactory()); hpc.SetImageProvider(new SampleTestImageProvider()); hpc.SetPageSize(doc.PageSize); HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, pdfWriter)); IPipeline pipeline = new CssResolverPipeline(cssResolver, htmlPipeline); XMLWorker worker = new XMLWorker(pipeline, true); XMLParser p = new XMLParser(true, worker, Encoding.GetEncoding("UTF-8")); p.Parse(File.OpenRead(inputHtml), Encoding.GetEncoding("UTF-8")); doc.Close(); }
/** * 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); }
protected override void MakePdf(string outPdf) { Document doc = new Document(PageSize.A3.Rotate()); PdfWriter pdfWriter = PdfWriter.GetInstance(doc, new FileStream(outPdf, FileMode.Create)); pdfWriter.CreateXmpMetadata(); doc.SetMargins(200, 200, 0, 0); doc.Open(); CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add( XMLWorkerHelper.GetCSS( File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName + Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar + "main.css"))); cssFiles.Add( XMLWorkerHelper.GetCSS( File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName + Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar + "widget082.css"))); StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles); HtmlPipelineContext hpc = new HtmlPipelineContext( new CssAppliersImpl(new XMLWorkerFontProvider(RESOURCES + @"\tool\xml\examples\fonts"))); hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(Tags.GetHtmlTagProcessorFactory()); hpc.SetImageProvider(new SampleTestImageProvider()); hpc.SetPageSize(doc.PageSize); HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, pdfWriter)); IPipeline pipeline = new CssResolverPipeline(cssResolver, htmlPipeline); XMLWorker worker = new XMLWorker(pipeline, true); XMLParser p = new XMLParser(true, worker, Encoding.GetEncoding("UTF-8")); p.Parse(File.OpenRead(inputHtml), Encoding.GetEncoding("UTF-8")); //ICC_Profile icc = ICC_Profile.getInstance(ComplexDiv01Test.class.getResourceAsStream("sRGB Color Space Profile.icm")); //pdfWriter.setOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc); doc.Close(); }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.pipeline.AbstractPipeline#close(com.itextpdf.tool * .xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject) */ public override IPipeline Close(IWorkerContext context, Tag t, ProcessObject po) { String tagName = t.Name; if (tag.Equals(tagName)) { MapContext cc; try { cc = (MapContext)context.Get(typeof(PdfWriterPipeline).FullName); Document d = (Document)cc[PdfWriterPipeline.DOCUMENT]; d.Close(); } catch (NoCustomContextException e) { throw new PipelineException("AutoDocPipeline depends on PdfWriterPipeline.", e); } try { HtmlPipelineContext hpc = (HtmlPipelineContext)context.Get(typeof(HtmlPipeline).FullName); HtmlPipelineContext clone = (HtmlPipelineContext)hpc.Clone(); clone.SetPageSize(pagesize); ((WorkerContextImpl)context).Put(typeof(HtmlPipeline).FullName, clone); } catch (NoCustomContextException) { } } return(GetNext()); }
/** * 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; }
static protected void TransformHtml2Pdf(FileStream inputHtml, Document doc, PdfWriter pdfWriter) { CssFilesImpl cssFiles = new CssFilesImpl(); cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS()); StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles); String Css1 = "https://specialtyonlinestg.cardinalhealth.com/CardinalHealthSpecialty/themes/html/SS_SPDCardinalHealth/css/globalStyles.css?version=RI_20121023"; String Css2 = "https://specialtyonlinestg.cardinalhealth.com/CardinalHealthSpecialty/themes/html/SS_SPDCardinalHealth/css/SPDCSS/CAHPHReconciliationPortletView.css?version=AC_20120717"; try { cssResolver.AddCssFile(Css1, true); cssResolver.AddCssFile(Css2, true); } catch (CssResolverException e) { // TODO Auto-generated catch block } HtmlPipelineContext htmlContext = new HtmlPipelineContext(new CssAppliersImpl(new XMLWorkerFontProvider())); htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory()); htmlContext.SetPageSize(new Rectangle(doc.Left, doc.Bottom, doc.Right, doc.Top)); // Pipelines PdfWriterPipeline pdf = new PdfWriterPipeline(doc, pdfWriter); HtmlPipeline html = new HtmlPipeline(htmlContext, pdf); CssResolverPipeline css = new CssResolverPipeline(cssResolver, html); XMLWorker worker = new XMLWorker(css, true); XMLParser parser = new XMLParser(worker, Encoding.UTF8); parser.Parse(inputHtml, Encoding.UTF8); }