本文整理匯總了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();
}