类似百度文库pdf2swf+flexpaper解决pdf在线阅读的效果
1:工具准备swftools.exe 下载
http://www.swftools.org/download.html
安装至D盘
SWFTools提供了一系列将各种文件转成swf的工具:
font2swf.exe
gif2swf.exe
jpeg2swf.exe
pdf2swf.exe
png2swf.exe
wav2swf.exe
这里我们只使用pdf2swf.exe
flexpaper下载
http://code.google.com/p/flexpaper/
这里我们使用已经编译好的FlexPaper的flash版本
2:示例语言,这里我使用的两种开发环境做示例
php示例
由pdf生成swf文件
[*]<?php
[*]/*
[*] * Created on 2010-11-17
[*] *
[*] * To change the template for this generated file go to
[*] * Window - Preferences - PHPeclipse - PHP - Code Templates
[*] */
[*] //获取文件所在目录
[*] $dir=dirname(__FILE__) ;
[*] //删除测试文件
[*] @unlink( $dir."\\test.swf" );
[*] //使用pdf2swf转换命令
[*] $command= "D:/SWFTools/pdf2swf.exe-t \"".$dir."\\test.pdf\" -o\"".$dir."\\test.swf\" -s flashversion=9 ";
[*] //创建shell对象
[*] $WshShell = new COM("WScript.Shell");
[*] //执行cmd命令
[*] $oExec = $WshShell->Run("cmd /C ". $command, 0, true);
[*]?>
java示例
[*]<%
[*]/*
[*] * Created on 2010-11-17
[*] */
[*] //获取文件所在目录
[*]String path=request.getRealPath("/");
[*] //使用pdf2swf转换命令
[*] String command= "D:/SWFTools/pdf2swf.exe-t \""+path+"\\test.pdf\" -o\""+path+"\\test.swf\" -s flashversion=9 ";
[*] //执行cmd命令
[*] Runtime.getRuntime().exec("cmd /c "+command);
[*]%>
以上是php,java将pdf转换成swf方式,那显示呢,这样我们会使用到flexpaper,以下是flexpaper的使用
使用flexpaper展现swf
[*]<script type="text/javascript" src="js/swfobject/swfobject.js"></script>
[*] <script type="text/javascript">
[*] var swfVersionStr = "10.0.0";
[*] var xiSwfUrlStr = "playerProductInstall.swf";
[*] var flashvars = {
[*] SwfFile : escape("test.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,
[*] localeChain: "zh_CN"
[*] };
[*]
[*] var params = {
[*]
[*] }
[*] params.quality = "high";
[*] params.bgcolor = "#ffffff";
[*] params.allowscriptaccess = "sameDomain";
[*] params.allowfullscreen = "true";
[*] var attributes = {};
[*] attributes.id = "FlexPaperViewer";
[*] attributes.name = "FlexPaperViewer";
[*] swfobject.embedSWF(
[*] "FlexPaperViewer.swf", "flashContent",
[*] "650", "500",
[*] swfVersionStr, xiSwfUrlStr,
[*] flashvars, params, attributes);
[*]swfobject.createCSS("#flashContent", "display:block;text-align:left;");
[*] </script>
[*]
[*] <body>
[*]<div style="position:absolute;left:10px;top:10px;">
[*] <div id="flashContent">
[*] </div>
[*] </div>
[*]</body>
通过上述方式我们可以将pdf转换成相应的swf文件,并通过flexpaper显示,防止用户下载,或copy。
pdf2swf的详细参数说明,上网百度或者Google都能查到,但是注意的最好指定flashversion 为9,防止出现一些意外的错误。
pdf2swf 中并不是所有的pdf都能转换,加密的pdf pdf2swf转换不了
flexpaper 的参数详细说明请参考 http://code.google.com/p/flexpaper/wiki/Parameters
flexpaper 常用的APIhttp://code.google.com/p/flexpaper/wiki/API
如果出现乱码问题可能是字符集,网上有很多的相关解决方法可以查询【我没有碰到字符集堵的问题】。
还有pdf中含有图片可能转换成swf后图片不大清晰。
页:
[1]