码迷,mamicode.com
首页 > Web开发 > 详细

html 导出pdf

时间:2018-07-25 23:53:26      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:cep   css   bytes   nbsp   already   stream   develop   var   bsp   

地址: https://developers.itextpdf.com/examples/xml-worker/html-lists 

主方法:

public string Generate(string filePath)
{
if (DeleteOldFile(filePath))
{
throw new Exception("the destination path already existed and unable to repleace it");
}

var fs = new FileStream(filePath, FileMode.Create);
var doc = new Document(PageSize.B4);
var pdfWriter = PdfWriter.GetInstance(doc, fs);
doc.Open();
var html = this.GetTemplate();
var css = this.GetCSS();
using (var msCss = new MemoryStream(Encoding.UTF8.GetBytes(css)))
{
using (var msHtml = new MemoryStream(Encoding.UTF8.GetBytes(html)))
{
XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, doc, msHtml, msCss);
}
}
doc.Close();
fs.Close();
pdfWriter.Close();
return filePath;
}

html 导出pdf

标签:cep   css   bytes   nbsp   already   stream   develop   var   bsp   

原文地址:https://www.cnblogs.com/zxhome/p/9368890.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!