FlexPaper插件可以实现在浏览器中在线预览pdf,word,excel等。

在网上看到很多关于这个插件实现预览的技术,但是很难做到word和excel在线预览。

pdf很好实现。

首先下载相关的插件信息,这里不多说了。

其中这个插件主要需要配合Aspose来实现将上传的excel和word来转换为pdf。再通过pdf2swf来将pdf转换为swf格式。才能在前段在线预览。

1.所以这里还需要下载Aspose.dll  和Aspose.Cells.dll(处理Excel)还有Aspose.Words.dll(处理word)

有了dll之后,需要写一个cs类,专门处理word和excel转换为pdf,以及pdf转换为swf的方法。

直接推荐这篇文章里面已经实现的方法。

http://www.bkjia.com/Asp_Netjc/890896.html

通过这个类实现的方法

2.结合我们上传的文件路径,来实现将上传的文件格式转换以及在线预览。

首先配置前段页面信息

  <input type="hidden" id="_filename" value="/./../../@Model" />
<div style="margin:0 auto;width:100%;">
<div id="flashContent" style="display:none;">
<p>
To view this page ensure that Adobe Flash Player version
10.0.0 or greater is installed.
</p> </div> <script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/swfupload/flexpaper_flash.js"></script>
<script src="~/Scripts/swfupload/swfobject.js"></script> <script type="text/javascript">
var _filename = $("#_filename").val(); // alert(_filename)
//alert(_filename);
var swfVersionStr = "9.0.0";
var xiSwfUrlStr = "playerProductInstall.swf";
var flashvars = {
SwfFile: escape(_filename),
SwfFile: _filename,
// SwfFile: "/./../../UpDir/expressInstall.swf",
Scale: 0.6,
ZoomTransition: "easeOut",
ZoomTime: 0.5,
ZoomInterval: 0.1,
FitPageOnLoad: false,
FitWidthOnLoad: true,
PrintEnabled: true,
FullScreenAsMaxWindow: false,
ProgressiveLoading: true,
PrintToolsVisible: true,
ViewModeToolsVisible: true,
ZoomToolsVisible: true,
FullScreenVisible: true,
NavToolsVisible: true,
CursorToolsVisible: true,
SearchToolsVisible: true,
SearchMatchAll: true,
localeChain: "zh_CN"
};
var params = {
quality: "high",
bgcolor: "#ffffff",
allowscriptaccess: "sameDomain",
allowfullscreen: "true",
wmode: "direct" }
var attributes = { id: "FlexPaperViewer", name: "FlexPaperViewer" };
54 swfobject.embedSWF("../../../../Scripts/FlexPaper/FlexPaperViewer.swf", "flashContent", "100%", "1000", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
55
56 swfobject.createCSS("#flashContent", "display:block;text-align:left;");
</script>
</div>

一些主要的配置信息我已经标红,至于插件配置信息的属性功能,自行参考网上很多文档介绍,我用的就是一般上传。

3.接下来就是controller中实现的转换方法,我直接将路径传给了model返回给页面显示了。

                        //swf文件路径
string path = Server.MapPath("~\\UpDir") + node.FilePath.Substring().Replace('\\', '/') + ".swf";
//SIO是system.io 我重命名了
SIO.FileInfo fileinfo = new SIO.FileInfo(path);
if (fileinfo.Exists)
{
return View((object)(node.FilePath + ".swf"));
}
else
{
try
{
//上传的源文件地址
string sourcefile = Server.MapPath("~\\UpDir") + node.FilePath.Substring();
string FileName = node.name;
string ext = node.FilePath.Substring(node.FilePath.LastIndexOf(".") + ); if (ext.ToLower() == "doc" || ext.ToLower() == "docx")
{
string pdffile = sourcefile;
string swffile = Server.MapPath("~\\UpDir") + node.FilePath.Substring().Replace('\\', '/');
string path1 = Server.MapPath("~\\UpDir") + node.FilePath.Substring().Replace('\\', '/') + ".swf";
Aspose.Words.Document doc = new Aspose.Words.Document(pdffile);
25 doc.Save(swffile, Aspose.Words.SaveFormat.Pdf); AsposeUtils.ConvertDocToPdF(swffile, path1);
AsposeUtils.PDFConvertToSwf(swffile, path1, AsposeUtils.GetPageCountByPDF(swffile));
}
else if (ext.ToLower() == "xls" || ext.ToLower() == "xlsx")
{
string pdffile = sourcefile;
string swffile = Server.MapPath("~\\UpDir") + node.FilePath.Substring().Replace('\\', '/') + ".pdf";
string path1 = Server.MapPath("~\\UpDir") + node.FilePath.Substring().Replace('\\', '/') + ".swf"; Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(pdffile); workbook.Save(swffile, Aspose.Cells.SaveFormat.Pdf); //AsposeUtils.ConvertExcelToHtml(swffile, swffile);
42 AsposeUtils.PDFConvertToSwf(swffile, path1, AsposeUtils.GetPageCountByPDF(swffile));
}
else if (ext.ToLower() == "pdf")
{ try
{
string pdffile = sourcefile;
string swffile = path; SIO.File.Copy(pdffile, swffile, true);
AsposeUtils.PDFConvertToSwf(pdffile, swffile, AsposeUtils.GetPageCountByPDF(pdffile)); }
catch (Exception ex)
{
string str = ex.Message;
}
}
else if (ext.ToLower() == "ppt" || ext.ToLower() == "pptx")
{
string pdffile = sourcefile;
string swffile = path; AsposeUtils.ConvertPowerPointToPdf(sourcefile, swffile);
AsposeUtils.PDFConvertToSwf(pdffile, swffile, AsposeUtils.GetPageCountByPDF(pdffile));
}
else if (ext.ToLower() == "txt")
{
string pdffile = sourcefile;
string swffile = path; Txt2Pdf.zscsc(sourcefile, swffile);
AsposeUtils.PDFConvertToSwf(pdffile, swffile, AsposeUtils.GetPageCountByPDF(pdffile));
}
else if (ext.ToLower() == "jpg" || ext.ToLower() == "jpeg" || ext.ToLower() == "png")
{
return View((object)node.FilePath);
}
else
{
// ViewBag.FileName = @"/./../../UpDir/"+ project.ProjectCode + "/" + contract.ContractType + "/" + contract.Id + ".swf"; ;
}

4.我用的上传插件师swfupload,个人觉得不怎么好用,后面用uploadfiy插件了。上传不说了,controller中对word和excel的转换方法和我连接中文章使用的不一样。因为用文章中的总不能在前段使用flexpapaer预览成功。所以标黄的代码是我自己加上的。绿色代码是原先的代码。可以自己参考,两种方法哪个可行用哪个。

.net mvc使用FlexPaper插件实现在线预览PDF,EXCEL,WORD的方法的更多相关文章

  1. 前端实现在线预览pdf、word、xls、ppt等文件

    最近在做一个公司的资源管理系统,一些知识小记一下. 1.前端实现pdf文件在线预览功能 方式一.pdf文件理论上可以在浏览器直接打开预览但是需要打开新页面.在仅仅是预览pdf文件且UI要求不高的情况下 ...

  2. pc或者微信上用pdf.js在线预览pdf和word

    最近项目要求pdf和word可以在线预览功能,pc端还好解决,但是微信端就有点坑了,pc端原来的思路是将文件转成base64,然后用html格式显示 ,但是微信端不支持, 这种方式就pass掉了,谷歌 ...

  3. 前端实现在线预览pdf、docx、xls、ppt等文件

    思路:前台将各种格式的附件上传到服务器----后台通过方法将这些格式的文件转化成图片,前台通过放映ppt的方式将其展示在页面上. 关键点:reveal.js 参考文章:https://www.awes ...

  4. FlexPaper+SWFTool+操作类=在线预览PDF

    引言 由于客户有在线预览PDF格式的需求,在网上找了一下解决方案,觉得FlexPaper用起来还是挺方便的,flexpaper是将pdf转换为swf格式的文件预览的,所以flexpaper一般和swf ...

  5. FlexPaper+SWFTool+操作类=在线预览PDF(转)

    引言 由于客户有在线预览PDF格式的需求,在网上找了一下解决方案,觉得FlexPaper用起来还是挺方便的,flexpaper是将pdf转换为swf格式的文件预览的,所以flexpaper一般和swf ...

  6. 网页嵌入pdf、在线预览pdf工具及插件(转)

    摘要:在web开发时我们有时会需要在线预览PDF内容,在线嵌入pdf文件: 问题1:如何网页中嵌入PDF: 在网页中: 常用的几种PDF预览代码片段如下: 代码片段1: 1 <object ty ...

  7. 使用pdfjs插件在线预览PDF文件

    前言 本文介绍在html中使用 pdfjs插件在线预览PDF文件的方法. 实现步骤 下载 pdfjs 并引入项目中 到PDFJS官网 http://mozilla.github.io/pdf.js/g ...

  8. 在线预览PDF

    FlexPaper+SWFTool+操作类=在线预览PDF   引言 由于客户有在线预览PDF格式的需求,在网上找了一下解决方案,觉得FlexPaper用起来还是挺方便的,flexpaper是将pdf ...

  9. 网页中动态嵌入PDF文件/在线预览PDF内容https://www.cnblogs.com/xgyy/p/6119459.html

    #网页中动态嵌入PDF文件/在线预览PDF内容# 摘要:在web开发时我们有时会需要在线预览PDF内容,在线嵌入pdf文件: 问题1:如何网页中嵌入PDF: 在网页中: 常用的几种PDF预览代码片段如 ...

随机推荐

  1. centos7 源码编译安装TensorFlow CPU 版本

    一.前言 我们都知道,普通使用pip安装的TensorFlow是万金油版本,当你运行的时候,会提示你不是当前电脑中最优的版本,特别是CPU版本,没有使用指令集优化会让TensorFlow用起来更慢. ...

  2. Excel日期格式调整

    3-Aug-2008   自定义格式: [$-809]d-mmm-yyyy;@ Aug-2008   自定义格式: [$-809]mmm-yyyy;@

  3. 4-js 函数

    总是有些奇奇怪怪的问题: <div> <p class="productStatus"> <span>成交量 <em>${goods ...

  4. JFinal开发框架简介

    JFinal 中的Controller Controller是JFinal核心类之一,该类作为MVC模式中的控制器.基于JFinal的Web应用的控制器需要继承该类.Controller是定义Acti ...

  5. MVC扩展HtmlHelper,加入RadioButtonList、CheckBoxList、DropdownList

    代码: using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions ...

  6. firebug chrome debug[z]

    http://www.cnblogs.com/rubylouvre/p/3613042.html

  7. windows下用tcc编译Lua

    脚本来源:Demon's Blog,http://demon.tw/software/compile-lua-with-tcc.html 版权归原作者所有 使用方法: 1.下载tcc编译器,本文解压目 ...

  8. yaf框架安装配置

    YAF中文文档:http://www.laruence.com/manual/index.html 1 YAF框架是用C开发的,属于PHP的扩展框架: 2 YAF的性能相对于源生PHP,性能只降低不到 ...

  9. PAT 1048 数字加密(20)(代码+思路)

    1048 数字加密(20)(20 分) 本题要求实现一种数字加密方法.首先固定一个加密用正整数A,对任一正整数B,将其每1位数字与A的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对13取 ...

  10. Laravel框架中实现supervisor执行异步进程

    问题描述:在使用Laravel框架实现动态网页时,若有些操作计算量较大,为了不影响用户体验,往往需要使用异步方式去处理.这里使用supervisor和laravel自带的queues实现. Super ...