將word轉(zhuǎn)化為swf 如同百度文庫般閱讀實現(xiàn)思路及代碼
更新時間:2013年08月09日 17:22:00 作者:
一般流程想將word轉(zhuǎn)化為pdf格式,再將pdf格式轉(zhuǎn)化為swf格式。在網(wǎng)頁上顯示其實都是swf格式內(nèi)容,具體實現(xiàn)如下,有此需求的朋友可以參考下,希望對大家有所幫助
復(fù)制代碼 代碼如下:
<SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif">實現(xiàn)如同百度文庫那樣類似功能需要進行一系列轉(zhuǎn)化,一般流程想將word轉(zhuǎn)化為pdf格式,再將pdf格式轉(zhuǎn)化為swf格式。在網(wǎng)頁上顯示其實都是swf格式內(nèi)容。</SPAN>
首先將word轉(zhuǎn)化為swf,需要調(diào)用com組件,可以通過office 或者wps進行轉(zhuǎn)化,但我嘗試都沒有成功,最后通過OpenOffice 4.0.0 進行轉(zhuǎn)化才成功,OpenOffice 4.0.0支持windows 和linux操作系統(tǒng),故需要先下載openOffice,官網(wǎng)上應(yīng)該有。將word轉(zhuǎn)化為pdf,好像只是支持英文的標題的文檔,不支持漢文名字文檔,可以先將文件重新命名為英文,轉(zhuǎn)化之后再將文件變?yōu)闈h文即可,可能還需要開始openoffice 服務(wù),上圖

驗證服務(wù)是否開啟,上圖

代碼如下:
復(fù)制代碼 代碼如下:
<PRE class=php name="code"><?php
class RunTime//頁面執(zhí)行時間類
{
private $starttime;//頁面開始執(zhí)行時間
private $stoptime;//頁面結(jié)束執(zhí)行時間
private $spendtime;//頁面執(zhí)行花費時間
function getmicrotime()//獲取返回當前微秒數(shù)的浮點數(shù)
{
list($usec,$sec)=explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function start()//頁面開始執(zhí)行函數(shù),返回開始頁面執(zhí)行的時間
{
$this->starttime=$this->getmicrotime();
}
function end()//顯示頁面執(zhí)行的時間
{
$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>";
}
}
/*調(diào)用方法 */
$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();
?></PRE><BR>
<P></P>
<PRE></PRE>
<P></P>
<P><BR>
</P>
花費時間進行分析:
<P>將一個大小為1.48M的word文檔轉(zhuǎn)化為pdf需要<SPAN style="FONT-FAMILY: Simsun; FONT-SIZE: 14px">運行時間:1.3652579784秒</SPAN> 自己電腦是這個時間,自己測試</P>
<P><BR>
</P>
<P>其次將pdf轉(zhuǎn)化為swf,需要運用另外一個軟件,swftools 通過代碼調(diào)用cmd命令,直接上代碼</P>
<P><PRE class=php name="code"><?php
class RunTime//頁面執(zhí)行時間類
{
private $starttime;//頁面開始執(zhí)行時間
private $stoptime;//頁面結(jié)束執(zhí)行時間
private $spendtime;//頁面執(zhí)行花費時間
function getmicrotime()//獲取返回當前微秒數(shù)的浮點數(shù)
{
list($usec,$sec)=explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function start()//頁面開始執(zhí)行函數(shù),返回開始頁面執(zhí)行的時間
{
$this->starttime=$this->getmicrotime();
}
function end()//顯示頁面執(zhí)行的時間
{
$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>";
}
}
/*調(diào)用方法 */
$timer=new Runtime();
$timer->start();
//調(diào)用系統(tǒng)軟件
$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();
?></PRE><BR>
將剛才轉(zhuǎn)化而來的pdf轉(zhuǎn)化為swf文件需要用<SPAN style="FONT-FAMILY: Simsun; FONT-SIZE: 14px">運行時間:1.3119211197秒時間</SPAN><P></P>
<P><SPAN style="FONT-FAMILY: Simsun; FONT-SIZE: 14px">最后則是將swf文件顯示在網(wǎng)頁中,這一步需要引入多個js文件和其他文件,代碼就不寫了,直接下載,在我的上傳資料中</SPAN></P>
<P><BR>
</P>
<P><BR>
<BR>
</P>
<P><BR>
</P>
相關(guān)文章
分享幾種好用的PHP自定義加密函數(shù)(可逆/不可逆)
最近的項目中一直有用到加密函數(shù),今天來給大家推薦幾個好用且我自己常用的加密函數(shù),這幾個都是可逆的加密函數(shù),其中也有針對于ID的加密函數(shù),需要的朋友可以參考下2020-09-09php通過function_exists檢測函數(shù)是否存在的方法
這篇文章主要介紹了php通過function_exists檢測函數(shù)是否存在的方法,實例分析了php使用function_exists檢測函數(shù)是否存在及調(diào)用的相關(guān)技巧,非常具有實用價值,需要的朋友可以參考下2015-03-03phpword插件導(dǎo)出word文件時中文亂碼問題處理方案
PHPWord是一個可以把相關(guān)文件生成word文檔的插件了,但由于是老外開發(fā)的對于gbk支持不好,所以我們在導(dǎo)出帶有中文的word時會出現(xiàn)亂碼問題,下面本文就PHPWord中文亂碼問題介紹一些解決方法。2014-08-08mongo Table類文件 獲取MongoCursor(游標)的實現(xiàn)方法分析
本篇文章是對mongo Table類文件 獲取MongoCursor(游標)的實現(xiàn)方法進行了詳細的分析介紹,需要的朋友參考下2013-07-07WordPress中重置文章循環(huán)的rewind_posts()函數(shù)講解
這篇文章主要介紹了WordPress中的文章循環(huán)重置函數(shù)rewind_posts()講解,附帶不依賴循環(huán)的single_cat_title()函數(shù)的用法介紹,需要的朋友可以參考下2016-01-01關(guān)于WordPress的SEO優(yōu)化相關(guān)的一些PHP頁面腳本技巧
這篇文章主要介紹了關(guān)于WordPress的SEO優(yōu)化相關(guān)的一些PHP頁面腳本技巧,包括區(qū)分顯示頁面標題和關(guān)鍵字等,需要的朋友可以參考下2015-12-12