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. asp.net 关于Response.Redirect重定向前无法弹出alert对话框的问题

    要实现的功能:某项操作后,使用alert()提示框提示"操作成功"之类的提示,然后使用response.Redirect()来进行页面重定向. 出现的问题:运行代码,操作完成后,直 ...

  2. 修改UITextView光标高度

    自定义UITextView文字字体时,经常出现光标与字体的高度不匹配,可以通过下面代码修改默认的光标高度, //创建子类重写UITextView方法 - (CGRect)caretRectForPos ...

  3. db2 创建用户及授权

    1.创建系统用户dbuser/ehong隶属于db2users 2.C:\Program Files\IBM\SQLLIB\BIN>db2 connect to AKZXTEST数据库连接信息  ...

  4. 全基因组测序 从头测序(de novo sequencing) 重测序(re-sequencing)

    全基因组测序 全基因组测序分为从头测序(de novo sequencing)和重测序(re-sequencing). 从头测序(de novo)不需要任何参考基因组信息即可对某个物种的基因组进行测序 ...

  5. 还不好好读书吗?清华3D录取通知书出炉,还能动!

    近日,清华大学2018录取通知书“亮相”!看完后,网友直呼:哪里可以买到? 打开录取通知书 3D“二校门”跃然纸上 由清华师生共同打造.手工定制.独一无二的2018新版录取通知书来了!在新版录取通知书 ...

  6. WCF TOOL CODE

    .HTML <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WCFTool. ...

  7. pyspider示例代码七:自动登陆并获得PDF文件下载地址

    自动登陆并获得PDF文件下载地址 #!/usr/bin/env python # -*- encoding: utf- -*- # Created on -- :: # Project: pdf_sp ...

  8. Django(3)

    https://www.cnblogs.com/yuanchenqi/articles/7429279.html

  9. Part 6 - Class-Based Views(21-26)

    https://github.com/sibtc/django-beginners-guide/tree/v0.6-lw urlpatterns = [ views.PostUpdateView.as ...

  10. [MySQL]变更数据库字符集

    my.cnf [mysqld] character-set-server=utf8 [mysqld_safe] default-character-set=utf8 -- 创建数据库时,设置数据库的编 ...