pdf2swf+flexpaper解決pdf線上閱讀(類百度文庫)
阿新 • • 發佈:2019-01-23
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
2:示例語言,這裡我使用的兩種開發環境做示例
php示例
由pdf生成swf檔案
java示例<?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); ?>
<%
/*
* 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轉換不了
如果出現亂碼問題可能是字符集,網上有很多的相關解決方法可以查詢【我沒有碰到字符集堵的問題】。
還有pdf中含有圖片可能轉換成swf後圖片不大清晰。
word,wps,txt等文件也可以採用該方式轉換,但工具不一定為swftools
上傳的flexpaper附件中已經包含flexpaper中相關檔案不用重新下載,只要下載swftools,並安裝。
flexpaper附件中包含了pdf2swf.jsp與pdf2swf.php兩個檔案及flexpaper相關的元件可以在java或php環境中執行。
缺少字符集產生亂碼問題請參考該篇文章