資源簡介
利用aspose組件。支持doc\docx、ppt\pptx、xls\xlsx、txt、pdf等在線預覽
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Diagnostics;
using?System.IO;
using?System.Linq;
using?System.Web;
using?Aspose.Cells;
using?Aspose.Pdf.Devices;
using?Aspose.Slides;
using?Aspose.Words;
namespace?Spacebuilder.File
{
????public?class?DocViewService
????{
????????public?string?GetSwfUrl(string?filePath)
????????{
????????????try
????????????{
????????????????string?suffixName?=?filePath.Substring(filePath.LastIndexOf(‘.‘)?+?1);
????????????????string?fileName?=?GetFileName(filePath);
????????????????string?pdfurl?=?HttpContext.Current.Server.MapPath(“~/Uploads/pdfs/“);
????????????????pdfurl?=?string.Format(“{0}{1}.pdf“?pdfurl?fileName);
????????????????string?swfPath?=?“error.swf“;
????????????????if?(suffixName?==?“swf“)
????????????????{
????????????????????return?filePath;
????????????????}
????????????????if?(ExistFile(pdfurl))
????????????????{
????????????????????return?Pdf2Swf(pdfurl);
????????????????}
????????????????switch?(suffixName)
????????????????{
????????????????????case?“rar“:
????????????????????case?“zip“:
????????????????????????break;
????????????????????case?“mp4“:
????????????????????????swfPath?=?“mp4“;
????????????????????????break;
????????????????????case?“xls“:
????????????????????case?“xlsx“:
????????????????????????Workbook?xls?=?new?Workbook(filePath);
????????????????????????xls.Save(pdfurl?Aspose.Cells.SaveFormat.Pdf);
????????????????????????break;
????????????????????case?“txt“:
????????????????????case?“docx“:
????????????????????case?“doc“:
????????????????????????Document?doc?=?new?Document(filePath);
????????????????????????doc.Save(pdfurl);
????????????????????????break;
????????????????????case?“ppt“:
????????????????????case?“pptx“:
????????????????????????Presentation?ppt?=?new?Presentation(filePath);
????????????????????????ppt.Save(pdfurl?Aspose.Slides.Export.SaveFormat.Pdf);
????????????????????????break;
????????????????????case?“pdf“:
????????????????????????pdfurl?=?filePath;
????????????????????????break;
????????????????}
????????????????swfPath?=?Pdf2Swf(pdfurl);
????????????????return?swfPath;
????????????}
????????????catch?(Exception)
????????????{
????????????????return?“error.swf“;
????????????}
????????}
????????///?
????????///?獲取文件的名字不帶后綴名
????????///?
????????///?文件絕對路徑
????????///?
????????private?string?GetFileName(string?filePath)
????????{
????????????int?index0?=?filePath.LastIndexOf(‘\\‘);//文件名的索引開始位置
????????????int?index1?=?filePath.LastIndexOf(‘.‘);//文件的名里點的索引位置
????????????int?fileNameLength?=?index1?-?index0?-?1;//文件名的長度
????????????return?filePath.Substring(index0?+?1?fileNameLength);
????????}
????????private?string?Pdf2Swf(string?pdfurl)
????????{
????????????//自動保存文檔的截圖
????????????Pdf2Jpg(pdfurl);
????????????string?swfpath?=?““;
????????????try
????????????{
????????????
評論
共有 條評論