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");
  • 相关阅读:
    上传base64编码图片
    mysql
    当程序员老去 揭秘不为人知背后的辛酸故事
    Java中break的作用
    Random类
    使用dsoframer控件出现"Unable to display the inactive document. Click here to reactivate the document."的问题
    给IT新人的15个建议:苦逼程序员的辛酸反省与总结
    XML开发总结
    解决Office软件冲突问题
    PopupMenu控件的使用
  • 原文地址:https://www.cnblogs.com/jiangqw/p/12124090.html
Copyright © 2011-2022 走看看