world转pdf

        /// <summary>
        /// 将word文档转换成pdf
        /// </summary>
        /// <param name="paths">文档路径</param>
        /// <param name="outputPath">输出路径</param>
        public void AddDoc2pdf(string path, string outputFileName)
        {
            if (File.Exists(outputFileName))
            {
                File.Delete(outputFileName);
            }

            //读取doc文档
            Document doc = new Document(path);
            //保存为PDF文件,此处的SaveFormat支持很多种格式,如图片,epub,rtf 等等
            doc.Save(outputFileName, Aspose.Words.SaveFormat.Pdf);

            System.IO.FileInfo file = new System.IO.FileInfo(outputFileName);
            Response.Clear();
            Response.Charset = "utf-8";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode("demo.pdf"));
            Response.AddHeader("Conten-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();

        }

 

需要引用:Aspose.Words

posted @ 2018-12-24 16:40  没有狐狸的南墙  阅读(183)  评论(0编辑  收藏  举报