使用flexpaper实现类似百度文库显示文章
2012-06-12 11:42 海豚座 阅读(837) 评论(0) 编辑 收藏 举报首先下载flexpaper 下载地址:http://code.google.com/p/flexpaper/downloads/list
第一次发博客,欢迎拍砖。。。
下面直接上操作步骤
1、在前台html文件中引用js文件
<script type="text/javascript" language="javascript" src="../Scripts/flexpaper_flash.js"></script>
2、在html页面中给flexpaper添加容器
<a id="viewerPlaceHolder" style="width:688px;height:600px;display:block"></a>
3、编辑JavaScript代码,传入swf文档的路径,并设置显示的默认设置:
function flex(path) { var fp = new FlexPaperViewer( 'FlexPaperViewer', //容器的ID 'viewerPlaceHolder', { config: { SwfFile: escape(path), //关键位置 swf文件的路径 Scale: 1, //初始缩放大小 ZoomTransition: 'easeOut', //缩放样式 ZoomTime: 0.5, //从一个缩放比例到另一个缩放比例花费的时间 ZoomInterval: 0.2, //缩放比例之间的间隔,默认为0.1 FitPageOnLoad: true, //初始化时自适应页面 FitWidthOnLoad: true, //初始化自适应页面宽度 PrintEnabled: true, FullScreenAsMaxWindow: false, //最大化窗口 ProgressiveLoading: false, //设置为true的时,文档加载方式为逐步加载,但是要转换为9以上的版本 MinZoomSize: 0.2, //设置最大的缩放比例 MaxZoomSize: 5, //设置最小缩放比例 SearchMatchAll: false, //设置为true时,单击搜索,符合条件的的高亮显示 InitViewMode: 'Portrait', //设置启动模式 ViewModeToolsVisible: true, //工具栏上是否显示样式选择框 ZoomToolsVisible: true, //工具栏上是否显示缩放工具 NavToolsVisible: true, //工具栏上是否显示导航工具 CursorToolsVisible: true, //工具栏上是否显示光标工具 SearchToolsVisible: true, //工具栏上是否显示搜索工具 localeChain: 'en_US' //设置地区语言 } }); }
4、由于flexpaper是以flash方式显示的,我们需要用SWFTool(下载地址下载地址:http://www.swftools.org/download.html )等工具将PDF、GIF、PNG等文件(注:不能直接将office文档直接转换成SWF格式的文件)。SWFTools将pdf文件转换成swf文件的命令为(首先将SWFTools安装在服务器上),SWFTools可以通过CMD命令将PDF等文件转化成为SWF文件,命令格式为: C:\SWFTools\pdf2swf test .pdf -o test.swf (可以在电脑上运行cmd命令测试一下)
5、在后台代码里面将pdf转化为swf的类代码为(创建进程):
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; namespace Xwsyqpj.Common { public class ToSwf { public void ExecuteCmd(string cmd, string args) { using (Process p = new Process()) { p.StartInfo.FileName = cmd; p.StartInfo.Arguments = args; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = false; p.StartInfo.CreateNoWindow = true; p.Start(); p.PriorityClass = ProcessPriorityClass.Normal; p.WaitForExit(); } } } }
6、在后台代码中调用Javascript函数实现在页面显示显示
ClientScript.RegisterStartupScript(this.GetType(), "", "flex('"+FileUrl+"');", true);
7、欢迎拍砖。。。。