將word轉化為swf 進行如同百度文庫的般閱讀

來源:互聯網
上載者:User

實現如同百度文庫那樣類似功能需要進行一系列轉化,一般流程想將word轉化為pdf格式,再將pdf格式轉化為swf格式。在網頁上顯示其實都是swf格式內容。

首先將word轉化為swf,需要調用com組件,可以通過office 或者wps進行轉化,但我嘗試都沒有成功,最後通過OpenOffice 4.0.0 進行轉化才成功,OpenOffice 4.0.0支援windows 和linux作業系統,故需要先下載openOffice,官網上應該有。將word轉化為pdf,好像只是支援英文的標題的文檔,不支援漢文名字文檔,可以先將檔案重新命名為英文,轉化之後再將檔案變為漢文即可,可能還需要開始openoffice 服務,

需要開啟php中com元件服務

修改php設定檔

先到PHP.INI中開啟COM選項,com.allow_dcom = true 

注意: PHP 5.4.5後,com/dotnet 

模組已經成了單獨的擴充,所以需要在PHP.ini中配置extension=php_com_dotnet.dll ,

如果PHP VERSION<5.4.5 則不需要

驗證服務是否開啟,  開啟8100連接埠

代碼如下:

<?phpclass RunTime//頁面執行時間類 {     private $starttime;//頁面開始執行時間     private $stoptime;//頁面結束執行時間     private $spendtime;//頁面執行花費時間     function getmicrotime()//擷取返回當前微秒數的浮點數     {     list($usec,$sec)=explode(" ",microtime());     return ((float)$usec + (float)$sec);     }     function start()//頁面開始執行函數,返回開始頁面執行的時間     {     $this->starttime=$this->getmicrotime();     }     function end()//顯示頁面執行的時間     {     $this->stoptime=$this->getmicrotime();     $this->spendtime=$this->stoptime-$this->starttime;     //return round($this->spendtime,10);     }     function display()     {     //$this->end();     echo "<p>已耗用時間:".round($this->spendtime,10)."秒</p>";     } } /*調用方法 */$timer=new Runtime(); $timer->start();  function MakePropertyValue($name,$value,$osm){   $oStruct = $osm->Bridge_GetStruct   ("com.sun.star.beans.PropertyValue");   $oStruct->Name = $name;   $oStruct->Value = $value;   return $oStruct;   }   function word2pdf($doc_url, $output_url){   $osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");   $args = array(MakePropertyValue("Hidden",true,$osm));   $oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");   $oWriterDoc = $oDesktop->loadComponentFromURL   ($doc_url,"_blank", 0, $args);   $export_args = array(MakePropertyValue   ("FilterName","writer_pdf_Export",$osm));   $oWriterDoc->storeToURL($output_url,$export_args);   $oWriterDoc->close(true);   }   $output_dir = "C:/";   $doc_file = "C:/t.doc";   $pdf_file = "9.pdf";   $output_file = $output_dir . $pdf_file;   $doc_file = "file:///" . $doc_file;   $output_file = "file:///" . $output_file;   word2pdf($doc_file,$output_file);  $timer->end();$timer->display();?>

花費時間進行分析:
將一個大小為1.48M的word文檔轉化為pdf需要已耗用時間:1.3652579784秒 自己電腦是這個時間,自己測試

其次將pdf轉化為swf,需要運用另外一個軟體,swftools  通過代碼調用cmd命令,直接上代碼

<?phpclass RunTime//頁面執行時間類 {     private $starttime;//頁面開始執行時間     private $stoptime;//頁面結束執行時間     private $spendtime;//頁面執行花費時間     function getmicrotime()//擷取返回當前微秒數的浮點數     {     list($usec,$sec)=explode(" ",microtime());     return ((float)$usec + (float)$sec);     }     function start()//頁面開始執行函數,返回開始頁面執行的時間     {     $this->starttime=$this->getmicrotime();     }     function end()//顯示頁面執行的時間     {     $this->stoptime=$this->getmicrotime();     $this->spendtime=$this->stoptime-$this->starttime;     //return round($this->spendtime,10);     }     function display()     {     //$this->end();     echo "<p>已耗用時間:".round($this->spendtime,10)."秒</p>";     } } /*調用方法 */$timer=new Runtime(); $timer->start();   //調用系統軟體$command = "\"C:\Program Files\SWFTools\pdf2swf.exe\"  -t  C:\8.pdf -s flashversion=9 -o C:\m.swf"; echo $command;exec($command);echo 'ok';  $timer->end();$timer->display();?>

將剛才轉化而來的pdf轉化為swf檔案需要用已耗用時間:1.3119211197秒時間

最後則是將swf檔案顯示在網頁中,這一步需要引入多個js檔案和其他檔案,代碼就不寫了,直接下載,在我的上傳資料中

地址:http://download.csdn.net/detail/buyingfei888/5896109

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.