將word轉(zhuǎn)化為swf 如同百度文庫般閱讀實(shí)現(xiàn)思路及代碼
更新時(shí)間:2013年08月09日 17:22:00 作者:
一般流程想將word轉(zhuǎn)化為pdf格式,再將pdf格式轉(zhuǎn)化為swf格式。在網(wǎng)頁上顯示其實(shí)都是swf格式內(nèi)容,具體實(shí)現(xiàn)如下,有此需求的朋友可以參考下,希望對(duì)大家有所幫助
復(fù)制代碼 代碼如下:
<SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif">實(shí)現(xiàn)如同百度文庫那樣類似功能需要進(jìn)行一系列轉(zhuǎn)化,一般流程想將word轉(zhuǎn)化為pdf格式,再將pdf格式轉(zhuǎn)化為swf格式。在網(wǎng)頁上顯示其實(shí)都是swf格式內(nèi)容。</SPAN>
首先將word轉(zhuǎn)化為swf,需要調(diào)用com組件,可以通過office 或者wps進(jìn)行轉(zhuǎn)化,但我嘗試都沒有成功,最后通過OpenOffice 4.0.0 進(jìn)行轉(zhuǎn)化才成功,OpenOffice 4.0.0支持windows 和linux操作系統(tǒng),故需要先下載openOffice,官網(wǎng)上應(yīng)該有。將word轉(zhuǎn)化為pdf,好像只是支持英文的標(biāo)題的文檔,不支持漢文名字文檔,可以先將文件重新命名為英文,轉(zhuǎn)化之后再將文件變?yōu)闈h文即可,可能還需要開始o(jì)penoffice 服務(wù),上圖
驗(yàn)證服務(wù)是否開啟,上圖
代碼如下:
復(fù)制代碼 代碼如下:
<PRE class=php name="code"><?php
class RunTime//頁面執(zhí)行時(shí)間類
{
private $starttime;//頁面開始執(zhí)行時(shí)間
private $stoptime;//頁面結(jié)束執(zhí)行時(shí)間
private $spendtime;//頁面執(zhí)行花費(fèi)時(shí)間
function getmicrotime()//獲取返回當(dāng)前微秒數(shù)的浮點(diǎn)數(shù)
{
list($usec,$sec)=explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function start()//頁面開始執(zhí)行函數(shù),返回開始頁面執(zhí)行的時(shí)間
{
$this->starttime=$this->getmicrotime();
}
function end()//顯示頁面執(zhí)行的時(shí)間
{
$this->stoptime=$this->getmicrotime();
$this->spendtime=$this->stoptime-$this->starttime;
//return round($this->spendtime,10);
}
function display()
{
//$this->end();
echo "<p>運(yùn)行時(shí)間:".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>
花費(fèi)時(shí)間進(jìn)行分析:
<P>將一個(gè)大小為1.48M的word文檔轉(zhuǎn)化為pdf需要<SPAN style="FONT-FAMILY: Simsun; FONT-SIZE: 14px">運(yùn)行時(shí)間:1.3652579784秒</SPAN> 自己電腦是這個(gè)時(shí)間,自己測(cè)試</P>
<P><BR>
</P>
<P>其次將pdf轉(zhuǎn)化為swf,需要運(yùn)用另外一個(gè)軟件,swftools 通過代碼調(diào)用cmd命令,直接上代碼</P>
<P><PRE class=php name="code"><?php
class RunTime//頁面執(zhí)行時(shí)間類
{
private $starttime;//頁面開始執(zhí)行時(shí)間
private $stoptime;//頁面結(jié)束執(zhí)行時(shí)間
private $spendtime;//頁面執(zhí)行花費(fèi)時(shí)間
function getmicrotime()//獲取返回當(dāng)前微秒數(shù)的浮點(diǎn)數(shù)
{
list($usec,$sec)=explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function start()//頁面開始執(zhí)行函數(shù),返回開始頁面執(zhí)行的時(shí)間
{
$this->starttime=$this->getmicrotime();
}
function end()//顯示頁面執(zhí)行的時(shí)間
{
$this->stoptime=$this->getmicrotime();
$this->spendtime=$this->stoptime-$this->starttime;
//return round($this->spendtime,10);
}
function display()
{
//$this->end();
echo "<p>運(yùn)行時(shí)間:".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">運(yùn)行時(shí)間:1.3119211197秒時(shí)間</SPAN><P></P>
<P><SPAN style="FONT-FAMILY: Simsun; FONT-SIZE: 14px">最后則是將swf文件顯示在網(wǎng)頁中,這一步需要引入多個(gè)js文件和其他文件,代碼就不寫了,直接下載,在我的上傳資料中</SPAN></P>
<P><BR>
</P>
<P><BR>
<BR>
</P>
<P><BR>
</P>
相關(guān)文章
php解析html類庫simple_html_dom(詳細(xì)介紹)
一直以來使用php解析html文檔樹都是一個(gè)難題。Simple HTML DOM parser 幫我們很好地解決了這個(gè)問題??梢酝ㄟ^這個(gè)php類來解析html文檔,對(duì)其中的html元素進(jìn)行操作 (PHP5+以上版本)2013-07-07
CI框架中通過hook的方式實(shí)現(xiàn)簡(jiǎn)單的權(quán)限控制
這篇文章主要介紹了CI框架中通過hook的方式實(shí)現(xiàn)簡(jiǎn)單的權(quán)限控制,需要的朋友可以參考下2015-01-01
laravel 實(shí)現(xiàn)設(shè)置時(shí)區(qū)的簡(jiǎn)單方法
今天小編就為大家分享一篇laravel 實(shí)現(xiàn)設(shè)置時(shí)區(qū)的簡(jiǎn)單方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10
PHP函數(shù)nl2br()與自定義函數(shù)nl2p()換行用法分析
這篇文章主要介紹了PHP函數(shù)nl2br()與自定義函數(shù)nl2p()換行用法,結(jié)合實(shí)例形式分析PHP函數(shù)nl2br實(shí)現(xiàn)換行功能的優(yōu)缺點(diǎn)及自定義函數(shù)nl2p換行功能的使用技巧,需要的朋友可以參考下2016-04-04
比較時(shí)間段一與時(shí)間段二是否有交集的php函數(shù)
PHP比較時(shí)間段一與時(shí)間段二是否有交集的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-05-05
淺談PHP SHA1withRSA加密生成簽名及驗(yàn)簽
這篇文章主要介紹了PHP SHA1withRSA加密生成簽名及驗(yàn)簽,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
php通過asort()給關(guān)聯(lián)數(shù)組按照值排序的方法
這篇文章主要介紹了php通過asort()給關(guān)聯(lián)數(shù)組按照值排序的方法,實(shí)例分析了php中asort()函數(shù)的功能與使用技巧,需要的朋友可以參考下2015-03-03
php獲取今日開始時(shí)間和結(jié)束時(shí)間的方法
本篇文章實(shí)例講述了php獲取今日開始時(shí)間和結(jié)束時(shí)間的方法,具有很好的參考價(jià)值,下面跟著小編一起來看下吧2017-02-02
php實(shí)現(xiàn)比較兩個(gè)文件夾異同的方法
這篇文章主要介紹了php實(shí)現(xiàn)比較兩個(gè)文件夾異同的方法,涉及php針對(duì)目錄與文件名的遞歸操作技巧,需要的朋友可以參考下2015-06-06

