利⽤Aspose.Words将html转成pdf和将html转成word html转成word
///<summary>
/// html转word⽂件需要先创建⼀个模板word,再指定新的word⽂件的地址
///</summary>
///<param name="templatePath">加密采⽤的编码⽅式</param>
///<param name="newFilePath">加密采⽤的编码⽅式</param>
///<param name="html">待加密的明⽂</param>
///<returns></returns>
public static void HtmlToWord(string templatePath, string newFilePath, string html)
html代码转链接{
//加载word模板。
Aspose.Words.Document doc = new Aspose.Words.Document(string.Format(@"{0}", templatePath));
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
builder.InsertHtml(html);
doc.Save(newFilePath, Aspose.Words.SaveFormat.Doc);
}
html转成pdf
///<summary>
/// html转pdf
///</summary>
///<param name="path"></param>
///<param name="newFilePath">加密采⽤的编码⽅式</param>
/
//<returns></returns>
public static void HtmlToPdf(string path, string newFilePath)
{
var dir = newFilePath.Substring(0, newFilePath.LastIndexOf("/") + 1);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
Aspose.Words.Document doc = new Aspose.Words.Document(path);
doc.Save(newFilePath);
}
html⽂本转成pdf
var bytes = System.Text.Encoding.UTF8.GetBytes("<html><body><div>哈哈哈哈哈</div></body></html");
Stream s = new MemoryStream(bytes);
Aspose.Words.Document dc = new Aspose.Words.Document(s);
dc.Save(@"d:\\directory.pdf");
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论