验证服务是否开启,上图
代码如下:
">
Rumah >pembangunan bahagian belakang >tutorial php >将word转化为swf 如同百度文库般阅读实现思路及代码_PHP教程
<?php <BR>class RunTime//页面执行时间类 <br>{ <br>private $starttime;//页面开始执行时间 <br>private $stoptime;//页面结束执行时间 <br>private $spendtime;//页面执行花费时间 <br>function getmicrotime()//获取返回当前微秒数的浮点数 <br>{ <br>list($usec,$sec)=explode(" ",microtime()); <br>return ((float)$usec + (float)$sec); <br>} <br>function start()//页面开始执行函数,返回开始页面执行的时间 <br>{ <br>$this->starttime=$this->getmicrotime(); <br>} <br>function end()//显示页面执行的时间 <br>{ <br>$this->stoptime=$this->getmicrotime(); <br>$this->spendtime=$this->stoptime-$this->starttime; <br>//return round($this->spendtime,10); <br>} <br>function display() <br>{ <br>//$this->end(); <br>echo "<p>运行时间:".round($this->spendtime,10)."秒</p>"; <br>} <br>} <br>/*调用方法 */ <br>$timer=new Runtime(); <br>$timer->start(); <br><br><br>function MakePropertyValue($name,$value,$osm){ <br>$oStruct = $osm->Bridge_GetStruct <br>("com.sun.star.beans.PropertyValue"); <br>$oStruct->Name = $name; <br>$oStruct->Value = $value; <br>return $oStruct; <br>} <br>function word2pdf($doc_url, $output_url){ <br>$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n"); <br>$args = array(MakePropertyValue("Hidden",true,$osm)); <br>$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop"); <br>$oWriterDoc = $oDesktop->loadComponentFromURL <br>($doc_url,"_blank", 0, $args); <br>$export_args = array(MakePropertyValue <br>("FilterName","writer_pdf_Export",$osm)); <br>$oWriterDoc->storeToURL($output_url,$export_args); <br>$oWriterDoc->close(true); <br>} <br>$output_dir = "C:/"; <br>$doc_file = "C:/t.doc"; <br>$pdf_file = "9.pdf"; <br>$output_file = $output_dir . $pdf_file; <br>$doc_file = "file:///" . $doc_file; <br>$output_file = "file:///" . $output_file; <br>word2pdf($doc_file,$output_file); <br><br><br>$timer->end(); <br>$timer->display(); <br><br>?>
将一个大小为1.48M的word文档转化为pdf需要运行时间:1.3652579784秒 自己电脑是这个时间,自己测试
其次将pdf转化为swf,需要运用另外一个软件,swftools 通过代码调用cmd命令,直接上代码
<?php <BR>class RunTime//页面执行时间类 <br>{ <br>private $starttime;//页面开始执行时间 <br>private $stoptime;//页面结束执行时间 <br>private $spendtime;//页面执行花费时间 <br>function getmicrotime()//获取返回当前微秒数的浮点数 <br>{ <br>list($usec,$sec)=explode(" ",microtime()); <br>return ((float)$usec + (float)$sec); <br>} <br>function start()//页面开始执行函数,返回开始页面执行的时间 <br>{ <br>$this->starttime=$this->getmicrotime(); <br>} <br>function end()//显示页面执行的时间 <br>{ <br>$this->stoptime=$this->getmicrotime(); <br>$this->spendtime=$this->stoptime-$this->starttime; <br>//return round($this->spendtime,10); <br>} <br>function display() <br>{ <br>//$this->end(); <br>echo "<p>运行时间:".round($this->spendtime,10)."秒</p>"; <br>} <br>} <br>/*调用方法 */ <br>$timer=new Runtime(); <br>$timer->start(); <br><br><br>//调用系统软件 <br>$command = "\"C:\Program Files\SWFTools\pdf2swf.exe\" -t C:\8.pdf -s flashversion=9 -o C:\m.swf"; <br>echo $command; <br>exec($command); <br>echo 'ok'; <br><br><br>$timer->end(); <br>$timer->display(); <br><br>?>
最后则是将swf文件显示在网页中,这一步需要引入多个js文件和其他文件,代码就不写了,直接下载,在我的上传资料中