【原创】FlexPaper 实现百度文库式应用

最近有个项目,需要实现类似百度文库的东西。在参照了博客园几个文章之后实现了这个效果。

【准备工作】  

先下载FlexPaper,这个东西在网上搜下吧,版本变化快,还是现用现搜比较好。

 把FlexPaper里的两个文件添加到项目中。 1:FlexPaperViewer.swf;   2:viewer.swf;

 还有两个JS文件,可以放到你项目对应的JS目录中。  2:swfobject.js;  2:flexpaper_flash.js;

 我是把这个功能放到了用户控件当中。控件中代码如下:


 1       < script  type ="text/javascript"  src ="../script/swfobject/swfobject.js" ></ script >
 2 
 3       < script  type ="text/javascript"  src ="../script/flexpaper_flash.js" ></ script >
 4 
 5       < script  type ="text/javascript"  src ="../script/jquery.js" ></ script >
 6 
 7       < script  type ="text/javascript" >
 8                   var  swfVersionStr  =   " 9.0.124 " ;
 9                   var  xiSwfUrlStr  =   " ${expressInstallSwf} " ;
10                   var  flashvars  =  {
11                  SwfFile:  " ../UploadFiles/<%=getVal()%> " ,
12                      Scale:  1 ,
13                      ZoomTransition:  " linear " ,
14                      ZoomTime:  " greater " ,
15                      ZoomInterval:  0.1 ,
16                      FitPageOnLoad:  false ,
17                      FitWidthOnLoad:  false ,
18                      PrintEnabled:  true ,
19                      FullScreenAsMaxWindow:  false ,
20                      ProgressiveLoading:  false ,
21 
22                      PrintToolsVisible:  true ,
23                      ViewModeToolsVisible:  true ,
24                      ZoomToolsVisible:  true ,
25                      FullScreenVisible:  true ,
26                      NavToolsVisible:  true ,
27                      CursorToolsVisible:  true ,
28                      SearchToolsVisible:  false ,
29 
30                      localeChain:  " zh_CN "
31                  };
32                   var  params  =  {
33 
34              }
35              params.quality  =   " high " ;
36              params.bgcolor  =   " #ffffff " ;
37              params.allowscriptaccess  =   " sameDomain " ;
38              params.allowfullscreen  =   " true " ;
39               var  attributes  =  {};
40              attributes.id  =   " FlexPaperViewer " ;
41              attributes.name  =   " FlexPaperViewer " ;
42              swfobject.embedSWF(
43                   " FlexPaperViewer.swf " " flashContent " ,
44                   " 680 " " 505 " ,
45                  swfVersionStr, xiSwfUrlStr,
46                  flashvars, params, attributes);
47              swfobject.createCSS( " #flashContent " " display:none;text-align:left; " );
48       </ script >
49 
50       < div  id ="flashContent" >
51 
52           < script  type ="text/javascript" >
53                           var  pageHost  =  ((document.location.protocol  ==   " https: " ?   " https:// "  :  " http:// " );
54                           <%-- document.write( " <a href='http://www.adobe.com/go/getflashplayer'> " );  --%>
55           </ script >
56 

57     </div>  

上面代码基本无需改动,可能你需要调整大小或者相关的界面设置,查看该插件的文档即可找到。

唯一需要改动的地方可能就是你使用的版本号,还有第11行:SwfFile: "../UploadFiles/<%=getVal()%>"

 这行代码指明你要读取的文件所在位置,这个文件必须是SWF结尾的文件。

 效果如图:


=================================================================

现在说说怎么把WORD,PPT,EXCEL变成这个swf文件。

 还需要一个辅助工具,SWFTools。下载这个文件,并安装。需要用到里面的pdf2swf.exe进行PDF到SWF的转换。

 先上代码。

 1  ///   <summary>
 2           ///  上传按钮
 3           ///   </summary>
 4           ///   <param name="sender"></param>
 5           ///   <param name="e"></param>
 6           protected   void  Button1_Click( object  sender, EventArgs e)
 7          {
 8               /// /获取文件信息 
 9               string  FileName  =  FileUpload1.FileName;
10               string  file_str  =   " 文件名称: "   +  FileName  +   " <br> " ;
11              file_str  =   " 文件类型: "   +  FileUpload1.PostedFile.ContentType  +   " <br> " ;
12              file_str  =   " 文件长度: "   +  FileUpload1.PostedFile.ContentLength.ToString()  +   " KB<br> " ;
13               // 上传文件到服务器 
14               // string _FileName = FileUpload1.PostedFile.FileName.Substring(FileName.LastIndexOf("\\") + 1); //  取出文件名的路径(不包括文件的名称) 
15 
16               string  upload_file  =  Server.MapPath( " ./upload/ " +  FileName; // 取出服务器虚拟路径,存储上传文件 
17 
18              FileUpload1.PostedFile.SaveAs(upload_file); // 开始上传文件 
19 
20               string  sWebPath  =  Request.MapPath( "" );
21               string  sFile  =  sWebPath  +   " \\upload\\56.pdf " ;
22               string  dFile  =  sFile.Replace( " .pdf " " .swf " );
23 
24               if  ( ! File.Exists(dFile))
25              {
26                   if  ( ! Doc2Swf( @" C:\SWFTools\pdf2swf.exe " , sFile, dFile,FileName))
27                  {
28                      Response.Write( " 该文档被加密,不能转换! " );
29                  }
30              }
31          }
32 
33           private  Boolean Doc2Swf( string  appPath,  string  Source,  string  Des, string  filename)
34          {
35              Process pc  =   new  Process();
36              ProcessStartInfo psi  =   new  ProcessStartInfo(appPath, Source  +   "   "   +  Des);
37               try
38              {
39                  pc.StartInfo  =  psi;
40                  pc.Start();
41                  pc.WaitForExit();
42                  val  =  filename.Replace( " .pdf " " .swf " );
43                   // getVal(val);
44              }
45               catch
46              {
47                   return   false ;
48                   throw ;
49              }
50               finally
51              {
52                  pc.Close();
53              }
54               return File.Exists(Des);

55         }  


 上传的文件必须是PDF格式的文件。先把后缀Replace成swf.

 再通过这行代码 执行文件的实质转换 Doc2Swf(@"C:\SWFTools\pdf2swf.exe", sFile, dFile,FileName)

 其中需要改的也就是第一个参数,刚才装的软件路径。 

 以上出现的代码,是项目和我写测试时候代码结合。因为项目中有些东西又封装了,看起来没有这样清晰。

基本这样就算完成。下面还有一个情况就是,这个文件必须是PDF,那WORD,PPT,EXCEL又如何转PDF呢。

因为项目没有那么强烈说,需要直接上传WORD,PPT这样的要求,所以我也没研究用程序转换的方法。

这里我再提供一个工具,微软提供,免费使用。 

SaveAsPDFandXPS  这个软件装完后,你的WORD,PPT,EXCEL就可以直接保存成PDF。

 

感谢大家。这篇博文,我只是留作保存,并非一个教学文章,也是希望对有需要的朋友有些帮助。

另外这个插件里面的LOGO部分,应该需要破解去除,因为我也不太懂FLASH,所以没有去除LOGO版的,如果哪位朋友有,可以留言给我。 

转载于:https://www.cnblogs.com/compass/articles/2046311.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值