详细链接:https://shop499704308.taobao.com/?spm=a1z38n.10677092.card.11.594c1debsAGeak

VS2010版本以及以上版本源码下载地址:http://download.csdn.net/download/u012949335/10231812
VS2012版本以及以上版本源码下载地址:http://download.csdn.net/download/u012949335/10232057
#region MyRegionprivate bool PdfToHtml(string fileName, string tempFile, string saveDoc){//---------------------读html模板页面到stringbuilder对象里---- StringBuilder htmltext = new StringBuilder();using (StreamReader sr = new StreamReader(tempFile)) //模板页路径{String line;while ((line = sr.ReadLine()) != null){htmltext.Append(line);}sr.Close();}fileName = fileName.Replace("\\", "/");//----------替换htm里的标记为你想加的内容 htmltext.Replace("$PDFFILEPATH", fileName);//----------生成htm文件------------------―― using (StreamWriter sw = new StreamWriter(saveDoc, false,System.Text.Encoding.GetEncoding("utf-8"))) //保存地址{sw.WriteLine(htmltext);sw.Flush();sw.Close();}return true;}private bool OfficeDocumentToHtml(string sourceDoc, string saveDoc){bool result = false;//获取文件扩展名string docExtendName = System.IO.Path.GetExtension(sourceDoc).ToLower();switch (docExtendName){case ".doc":case ".docx":Aspose.Words.Document doc = new Aspose.Words.Document(sourceDoc);doc.Save(saveDoc, Aspose.Words.SaveFormat.Html);result = true;break;case ".xls":case ".xlsx":Workbook workbook = new Workbook(sourceDoc);//workbook.Open(sourceDoc);//workbook.Save(saveDoc, FileFormatType.AsposePdf);workbook.Save(saveDoc, Aspose.Cells.SaveFormat.Html);result = true;break;case ".ppt":case ".pptx"://templateFile = templateFile.Replace("/", "\\");//string templateFile = sourceDoc;//templateFile = templateFile.Replace("/", "\\");PresentationEx pres = new PresentationEx(sourceDoc);pres.Save(saveDoc, Aspose.Slides.Export.SaveFormat.Html);result = true;break;default:break;}return result;}#endregion
[HttpGet]public string CourseViewOnLine(string fileName) {//DataTable dtlist = new DataTable();//dtlist.Columns.Add("TempDocHtml", typeof(string));string json = "";string fileDire = "../Files";string sourceDoc = Path.Combine(fileDire, fileName);string saveDoc = "";string docExtendName = System.IO.Path.GetExtension(sourceDoc).ToLower();bool result = false;if (docExtendName == ".pdf"){//pdf模板文件string tempFile = Path.Combine(fileDire, "temppdf.html");saveDoc = Path.Combine(fileDire, "viewFiles/onlinepdf.html");result = PdfToHtml(sourceDoc,System.Web.HttpContext.Current.Server.MapPath(tempFile),System.Web.HttpContext.Current.Server.MapPath(saveDoc));}else{saveDoc = Path.Combine(fileDire, "viewFiles/onlineview.html");result = OfficeDocumentToHtml(System.Web.HttpContext.Current.Server.MapPath(sourceDoc),System.Web.HttpContext.Current.Server.MapPath(saveDoc));}if (result){json = "{\"TempDocHtml\":\"" + saveDoc.Replace("\\","/") + "\"}";//dtlist.Rows.Add(saveDoc);}return json;}
$(function () {SexyLightbox.initialize({ color: 'white' });
});var viewDoc = function (fileName) {showLoading("body", "正在生成预览");//生成html文件  $.ajax({url: "CourseViewOnLine?fileName=" + fileName,type: "GET",dataType: "json",success: function (data) {closeLoading();//alert(JSON.stringify(data));//alert(data[0].TempDocHtml);var diag = new Dialog();diag.Width = 10000;diag.Height = 6000;diag.Title = "内容页为外部连接的窗口";diag.URL = data.TempDocHtml + "?ver=" + Math.random() * 10;diag.show();//$("#hidePopupDialog").attr('href', '' + data[0].TempDocHtml + '?TB_iframe=true&height=450&width=920');//$("#hidePopupDialog").click();},error: function () {closeLoading();alert('生成失败');}});
}// 加载遮罩
var showLoading = function (elementTag, message) {var msg = message ? message : "加载数据,请稍候...";$("<div class=\"datagrid-mask\"></div>").css({display: "block", width: "100%",height: $(elementTag).height()}).appendTo(elementTag);$("<div class=\"datagrid-mask-msg\"></div>").html(msg).appendTo(elementTag).css({ display: "block", left: "30%", top: ($(elementTag).height() - 45) / 2 });
};//关闭遮罩
var closeLoading = function () {$('.datagrid-mask').remove();$('.datagrid-mask-msg').remove();
};
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %><asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">IndexOnline
</asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"><h2>IndexOnline</h2><script src="../Scripts/jquery-1.8.2.js" type="text/javascript"></script><script src="../Scripts/Js/pdfobject/pdfobject.js" type="text/javascript"></script><script src="../Scripts/Js/index.js" type="text/javascript"></script><script src="../Scripts/Js/PopupDialog/jquery.easing.1.3.js" type="text/javascript"></script><script src="../Scripts/Js/PopupDialog/sexylightbox.v2.3.jquery.min.js" type="text/javascript"></script><script src="../Scripts/Js/zDialog/zDrag.js" type="text/javascript"></script><script src="../Scripts/Js/zDialog/zDialog.js" type="text/javascript"></script><a  class="docViewDownload" onclick="viewDoc('wordtest1.doc');">Word 预 览</a><a  class="docViewDownload" onclick="viewDoc('exceltest.xls');">Excel 预 览</a><a  class="docViewDownload" onclick="viewDoc('ppttest.pptx');">PPT 预 览</a><a  class="docViewDownload" onclick="viewDoc('pdftest.pdf');">PDF 预 览</a>
</asp:Content>

基于ASP.NET MVC 利用(Aspose+Pdfobject.js) 实现在线预览Word、Excel、PPT、PDF文件相关推荐

  1. Vue 预览word,excel,ppt等office文档-内网访问(基于onlyoffice,后端返回文件流)

    Vue 预览word,excel等office 先看效果!! 需求背景:在前端页面中预览office文件且是内网访问,服务器不可访问外网的前提. 因此微软的接口就废掉了,因为他接口的条件是可以访问外网 ...

  2. mvc直接在html页面预览pdf,Asp.net MVC 实现在线预览word、excel、ppt、pdf文件

    在线预览word.excel.ppt 原理:主要是引用第三方Dll使本地word.excel.ppt文件转换成Html 需要引用 : Aspose.Cells.dll Aspose.Slides.dl ...

  3. springboot整合pdf.js实现在线预览pdf文件

    今天在项目中实现pdf在线预览的功能的如图, 通过百度,查询合适的方法,最为简单的的是通过pdf.js的插件在前台展示.本以为是挺容易实现的,但都有莫名其妙的错误. 第一步:下载源码https://g ...

  4. 利用微软的Office Online在线预览播放Office文档,无工具栏

    利用微软的Office Online在线预览播放Office文档 通过微软的在线预览URL链接可以直接打开在线PPT文档如下 https://view.officeapps.live.com/op/v ...

  5. C#编写ASP.NET Core的Web API并部署到IIS上的详细教程(API用于准确获取Word/Excel/PPT/PDF的页数)6 -将项目部署到IIS,及常见错误解决方案

    C#编写ASP.NET Core的Web API并部署到IIS上的详细教程(API用于准确获取Word/Excel/PPT/PDF的页数)6 -将项目部署到IIS,及常见错误解决方案 1.前言 2.安 ...

  6. java word转pdf linux_java实现word转pdf在线预览(前端使用PDF.js;后端使用openoffice、aspose)...

    背景 之前一直是用户点击下载word文件到本地,然后使用office或者wps打开.需求优化,要实现可以直接在线预览,无需下载到本地然后再打开. 随后开始上网找资料,网上资料一大堆,方案也各有不同,大 ...

  7. java word在线预览_java实现word转pdf在线预览(前端使用PDF.js;后端使用openoffice、aspose)...

    背景 之前一直是用户点击下载word文件到本地,然后使用office或者wps打开.需求优化,要实现可以直接在线预览,无需下载到本地然后再打开. 随后开始上网找资料,网上资料一大堆,方案也各有不同,大 ...

  8. nopi word to html,C# 基于NPOI+Office COM组件 实现20行代码在线预览文档(word,excel,pdf,txt,png)...

    由于项目需要,需要一个在线预览office的功能,小编一开始使用的是微软提供的方法,简单快捷,但是不符合小编开发需求, 就另外用了:将文件转换成html文件然后预览html文件的方法.对微软提供的方法 ...

  9. Three.js心脏在线预览(次时代模型)

    心脏在线预览(次时代模型) 本文是Three.js电子书的14.6节 本节课加载一个心脏的次时代模型,模型包含颜色贴图.map.法线贴图.normalMap.高光贴图.specularMap.环境贴图 ...

最新文章

  1. vmware 打开主页 打开所有库中的虚拟机
  2. 软硬件融合加速技术系列文章
  3. shell echo 换行 不换行 打印换行
  4. c++ 低位在前 高位在后_生意社:醋酸市场前三季度区间震荡 四季度一飞冲天
  5. bilibili有电脑版吗_虚充制冷剂、谎称电脑版故障...空调维修的这些套路,你 中招了吗...
  6. Android开源项目发现---ProgressBar 篇(持续更新)
  7. feed流和瀑布流_产品PM必备的Feed流和瀑布流应用场景
  8. SQL Server数据库镜像的FailOver自动连接
  9. R和Tableau平行坐标图
  10. preempt_disable宏
  11. 云桌面优缺点_桌面云优缺点
  12. 编程金融小白学 股票期权 lv.2 期权策略
  13. 熟女给老实木讷男孩的恋爱建议(转帖)
  14. 2021年的4个开源对象存储平台
  15. 【JZOJ100209】【20190705】狂妄之人
  16. C语言---移盘子----Hanoi(汉诺)塔问题,显示移动盘子的步骤
  17. c语言中,从键盘输入一个长方体的长宽高,用函数实现求长方体的体积,由主函数调用该函数,要求长方体的长、宽、高从主函数输入,长方体的体积作为函数返回值。
  18. 在 dhcpd 中配置分配静态路由条目
  19. 解决 Cannot resolve symbol ‘XXXxxx‘问题
  20. 仙剑奇侠传7御灵有什么用?御灵的作用与培养策略

热门文章

  1. 【BZOJ】【P4407】【于神之怒加强版】【题解】【数论】
  2. Vista删除EISA配置分区
  3. ChatGPT API调用python和脚本实现
  4. 小韩谈shell -- 十分好玩的小脚本
  5. 我等到花儿也谢 - 张学友 - 真爱
  6. 介绍兴趣爱好的网页html,关于兴趣爱好的自我介绍
  7. thinkphp实现用户注册时邮箱激活
  8. mit scheme常用命令
  9. 做为应届毕业生,我应该咋找工作?
  10. 电子商务网站开发流程[转]