[转]ASP.NET使用flexpaper做在线文档浏览

本文转自:http://www.cnblogs.com/qiuwuyu/archive/2011/08/26/2154153.html

 

最近有个项目需要用到类似百度文库以及豆丁的在线浏览组件,网上转悠半天就找到了个flexpaper,需要从这里下载http://code.google.com/p/flexpaper/downloads/list flexpaper 支持的文档类型为swf格式。于是乎,就想着把pdf文件转换成swf,因为装了adobe reader软件的电脑ms word之类的文档可以直接保存为pdf格式。网上都说pdf2swf这个工具不错,需要从这里下载http://www.swftools.org/download.html 。只需要用命令行操作即可,小试一下果然牛的不得了啊。

PDF转换成SWF需要用命令行操作pdf2swf.exe,代码如下

        public static 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();

            }

        }

调用代码如下,给pdf2swf.exe所传的参数简单说描述下,-t后面跟的就是目标文件路径,-o是输出文件的具体路径,

            string cmdStr = HttpContext.Current.Server.MapPath("FlexPaper/pdf2swf.exe");

            string savePath = HttpContext.Current.Server.MapPath("Test");

            string filePath = HttpContext.Current.Server.MapPath("PDF/Amazon隐藏的帝国.pdf");

            string args = " -t " + filePath + " -o " + savePath + "\\Amazon隐藏的帝国.swf";

            //分页

 

            //string args = " -t " + filePath + " -o " + savePath + "\\Amazon隐藏的帝国%.swf -f -T 9 -t -s storeallcharacters";

 

            PDF2SWFCmd.ExecuteCmd(cmdStr, args);

前台展示文档页面代码如下,都是从官网demo直接粘贴的,呵呵

    <script language="javascript" type="text/javascript" src="FlexPaper/js/jquery.js"></script>

    <script language="javascript" type="text/javascript" src="FlexPaper/js/flexpaper_flash_debug.js"></script>

    <div style="position:absolute;left:10px;top:10px;">

                 <a id="viewerPlaceHolder" style="width:660px;height:480px;display:block"></a>

                 <script type="text/javascript">

                     var fp = new FlexPaperViewer(

                                                         'FlexPaper/FlexPaperViewer',

                                                         'viewerPlaceHolder', { config: {

                                                             SwfFile: 'Test/Amazon隐藏的帝国.swf',

                                                             Scale: 0.6,

                                                             ZoomTransition: 'easeOut',

                                                             ZoomTime: 0.5,

                                                             ZoomInterval: 0.2,

                                                             FitPageOnLoad: false,

                                                             FitWidthOnLoad: false,

                                                             PrintEnabled: true,

                                                             FullScreenAsMaxWindow: false,

                                                             ProgressiveLoading: false,

                                                             MinZoomSize: 0.2,

                                                             MaxZoomSize: 5,

                                                             SearchMatchAll: false,

                                                             InitViewMode: 'Portrait',

                                                             ViewModeToolsVisible: true,

                                                             ZoomToolsVisible: true,

                                                             NavToolsVisible: true,

                                                             CursorToolsVisible: true,

                                                             SearchToolsVisible: true,

                                                             localeChain: 'en_US'

                                                         }

                                                         });

                 </script> 

        </div>

一切操作正常后的运行界面应该类似如下界面,

如果打开页面后想定位到某一页,需要修改配置文件

 

ProgressiveLoading: true

而后调用api接口,假如想跳到第10页,可以这样写

 function onDocumentLoaded(totalPages) {

 

                getDocViewer().gotoPage(10);

 

            }

但是这种方法可以明显看到从第一页转到第10页的加载过程,木想到好方法啊。

 

转载于:https://www.cnblogs.com/freeliver54/archive/2012/03/31/2427132.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值