zoukankan      html  css  js  c++  java
  • 利用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)
            {
                //加载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");
  • 相关阅读:
    Python小工具:统计代码行数
    计算机图形学复习(一)
    牛客多校训练第一场 J.Different Integers
    数据校验码概述
    数据库复习第二章
    数据库复习第一章
    自动化AC器(带界面版)
    ZOJ 3747 Attack on Titans
    Codeforces Round #245 (Div. 1) B. Working out
    HDU 6266 Hakase and Nano 【博弈论】
  • 原文地址:https://www.cnblogs.com/jiangqw/p/12124090.html
Copyright © 2011-2022 走看看