下载Aspose,稍后会附上百度云盘,或者联系我QQ546170667
项目中引入
using System.IO;
using Aspose.Slides;
得到文件名

/// <summary> /// 返回文件扩展名,不含“.” /// </summary> /// <param name="_filepath">文件全名称</param> /// <returns>string</returns> private static string GetFileExt(string _filepath) { if (string.IsNullOrEmpty(_filepath)) { return ""; } if (_filepath.LastIndexOf(".") > 0) { return _filepath.Substring(_filepath.LastIndexOf(".") + 1); //文件扩展名,不含“.” } return ""; }
开始转换

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; }
很简单,再结合
pdfobject.min.js
进行在线预览