pdf2swf+flexpapers實作類別似百度文庫pdf線上閱讀_java

來源:互聯網
上載者:User

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 常用的API  http://code.google.com/p/flexpaper/wiki/API

如果出現亂碼問題可能是字元集,網上有很多的相關解決方案可以查詢【我沒有碰到字元集堵的問題】。

還有pdf中含有圖片可能轉換成swf後圖片不大清晰。

word,wps,txt等文檔也可以採用該方式轉換,但工具不一定為swftools

上傳的flexpaper附件中已經包含flexpaper中相關檔案不用重新下載,只要下載swftools,並安裝。
flexpaper附件中包含了pdf2swf.jsp與pdf2swf.php兩個檔案及flexpaper相關的組件可以在java或php環境中運行。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.