本文整理汇总了C#中iTextSharp.tool.xml.pipeline.html.HtmlPipelineContext.SetLinkProvider方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlPipelineContext.SetLinkProvider方法的具体用法?C# HtmlPipelineContext.SetLinkProvider怎么用?C# HtmlPipelineContext.SetLinkProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.tool.xml.pipeline.html.HtmlPipelineContext
的用法示例。
在下文中一共展示了HtmlPipelineContext.SetLinkProvider方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HtmlToPdf
public void HtmlToPdf(string htmlFile, string pdfFile, string htmlImageDirectory)
{
using (FileStream pdfStream = new FileStream(pdfFile, FileMode.OpenOrCreate))
{
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, pdfStream);
doc.Open();
//TODO: apply external css
ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(true);
//HTML
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
htmlContext.SetImageProvider(new ImageProvider(htmlImageDirectory));
htmlContext.SetLinkProvider(new LinkProvider("/"));
//pipelines
PdfWriterPipeline pdf = new PdfWriterPipeline(doc, writer);
HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
XMLWorker worker = new XMLWorker(css, true);
XMLParser p = new XMLParser(true, worker, Encoding.UTF8);
using (TextReader reader = File.OpenText(htmlFile))
{
p.Parse(reader);
}
doc.Close();
}
}
示例2: AddingALinkProvider
virtual public void AddingALinkProvider() {
Document doc = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(TARGET + "columbus3.pdf", FileMode.Create));
doc.Open();
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.SetLinkProvider(new CustomLinkProvider()).SetTagFactory(Tags.GetHtmlTagProcessorFactory());
ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(true);
IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext,
new PdfWriterPipeline(doc, writer)));
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(worker);
p.Parse(File.OpenRead(RESOURCES + @"\examples\columbus.html"));
doc.Close();
}