将word转化为swf 如同百度文库般阅读实现思路及代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif">实现如同百度文库那样类似功能需要进行一系列转化,一般流程想将word转化为pdf格式,再将pdf格式转化为swf格式。在网页上显示其实都是swf格式内容。</SPAN>

首先将word转化为swf,需要调用com组件,可以通过office 或者wps进行转化,但我尝试都没有成功,最后通过OpenOffice 4.0.0 进行转化才成功,OpenOffice 4.0.0支持windows 和linux操作系统,故需要先下载openOffice,官网上应该有。将word转化为pdf,好像只是支持英文的标题的文档,不支持汉文名字文档,可以先将文件重新命名为英文,转化之后再将文件变为汉文即可,可能还需要开始openoffice 服务,上图
 
验证服务是否开启,上图
 
代码如下:
复制代码 代码如下:

<PRE class=php name="code"><?php
class 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();

?></PRE><BR>
<P></P>
<PRE></PRE>
<P></P>
<P><BR>
</P>
花费时间进行分析:
<P>将一个大小为1.48M的word文档转化为pdf需要<SPAN style="FONT-FAMILY: Simsun; FONT-SIZE: 14px">运行时间:1.3652579784秒</SPAN> 自己电脑是这个时间,自己测试</P>
<P><BR>
</P>
<P>其次将pdf转化为swf,需要运用另外一个软件,swftools  通过代码调用cmd命令,直接上代码</P>
<P><PRE class=php name="code"><?php
class 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();

?></PRE><BR>
将刚才转化而来的pdf转化为swf文件需要用<SPAN style="FONT-FAMILY: Simsun; FONT-SIZE: 14px">运行时间:1.3119211197秒时间</SPAN><P></P>
<P><SPAN style="FONT-FAMILY: Simsun; FONT-SIZE: 14px">最后则是将swf文件显示在网页中,这一步需要引入多个js文件和其他文件,代码就不写了,直接下载,在我的上传资料中</SPAN></P>
<P><BR>
</P>
<P><BR>
<BR>
</P>
<P><BR>
</P>

相关文章

PHP文件操作实现代码分享

PHP文件操作实现代码分享

将数据写或读入文件,基本上分为三个步骤: 1. 打开一个文件(如果存在) 2. 写/读文件 3. 关闭这个文件 l打开文件 在打开文件文件之前,我们需要知道这个文件的路径,以及此文件是否...

全面解读PHP的Yii框架中的日志功能

Yii页面级日志开启 在 Main.php中 log段添加、 下面显示页面日志 array( 'class'=>'CWebLogRoute', 'levels'=>'tra...

PHP函数func_num_args用法实例分析

本文实例讲述了PHP函数func_num_args用法。分享给大家供大家参考,具体如下: function foo() { $numargs = func_num_args()...

PHP中引用类型和值类型功能与用法示例

本文实例讲述了PHP中引用类型和值类型功能与用法。分享给大家供大家参考,具体如下: PHP中的四种简单类型和复杂类型array都是值类型。同类型间赋值传递的是值,即创建一个副本给新变量。...

PHP源代码数组统计count分析

zend给php的所有变量都用结构的方式去保存,而字符串的保存和数组的保存也是不同的,数组采用的是hash表的方式去保存(大家知道hash保存的地址有效的减少冲突-hash散列表的概念你...