• 大小: 7KB
    文件类型: .cs
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: C#
  • 标签:

资源简介

利用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
            {
            

评论

共有 条评论