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) { //加載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");