Aspose将word,excel,ppt等转为PDF

下载Aspose,稍后会附上百度云盘,或者联系我QQ546170667

项目中引入

using System.IO;
using Aspose.Slides;

得到文件名

/// 
        /// 返回文件扩展名,不含“.”
        /// 
        /// 文件全名称
        /// string
        private static string GetFileExt(string _filepath)
        {
            if (string.IsNullOrEmpty(_filepath))
            {
                return "";
            }
            if (_filepath.LastIndexOf(".") > 0)
            {
                return _filepath.Substring(_filepath.LastIndexOf(".") + 1); //文件扩展名,不含“.”
            }
            return "";
        }
View Code

开始转换

string file_type = GetFileExt(old_path);
            switch (file_type.ToLower( ))
            {
                case "doc":
                case "docx":

                    Aspose.Words.Document doc = new Aspose.Words.Document(old_path);
                    doc.Save(Replace_File(old_path), Aspose.Words.SaveFormat.Pdf);

                    break;

                case "xls":
                case "csv":
                case "xlsx":
                    Aspose.Cells.Workbook excel = new Aspose.Cells.Workbook(old_path);

                    excel.Save(Replace_File(old_path), Aspose.Cells.SaveFormat.Pdf);
                    break;

                case "ppt":
                    Presentation ppt = new Presentation(old_path);
                    ppt.Save(Replace_File(old_path), Aspose.Slides.Export.SaveFormat.Pdf);
                    break;

                case "pptx":
                    Aspose.Slides.Pptx.PresentationEx pptx = new Aspose.Slides.Pptx.PresentationEx(old_path);
                    pptx.Save(Replace_File(old_path), Aspose.Slides.Export.SaveFormat.Pdf);
                    break;
            }
View Code

 

很简单,再结合

pdfobject.min.js

进行在线预览

转载于:https://www.cnblogs.com/c546170667/articles/10303426.html

你可能感兴趣的:(c#)