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

php中文网
发布: 2016-07-21 14:59:52
原创
1166人浏览过

复制代码 代码如下:

实现如同百度文库那样类似功能需要进行一系列转化,一般流程想将word转化为pdf格式,再将pdf格式转化为swf格式。在网页上显示其实都是swf格式内容。

首先将word转化为swf,需要调用com组件,可以通过office 或者wps进行转化,但我尝试都没有成功,最后通过OpenOffice 4.0.0 进行转化才成功,OpenOffice 4.0.0支持windows 和linux操作系统,故需要先下载openOffice,官网上应该有。将word转化为pdf,好像只是支持英文的标题的文档,不支持汉文名字文档,可以先将文件重新命名为英文,转化之后再将文件变为汉文即可,可能还需要开始openoffice 服务,上图
将word转化为swf 如同百度文库般阅读实现思路及代码_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>
                    <div class="aritcle_card">
                        <a class="aritcle_card_img" href="/ai/2186">
                            <img src="https://img.php.cn/upload/ai_manual/000/000/000/175680010816574.png" alt="小绿鲸英文文献阅读器">
                        </a>
                        <div class="aritcle_card_info">
                            <a href="/ai/2186">小绿鲸英文文献阅读器</a>
                            <p>英文文献阅读器,专注提高SCI阅读效率</p>
                            <div class="">
                                <img src="/static/images/card_xiazai.png" alt="小绿鲸英文文献阅读器">
                                <span>199</span>
                            </div>
                        </div>
                        <a href="/ai/2186" class="aritcle_card_btn">
                            <span>查看详情</span>
                            <img src="/static/images/cardxiayige-3.png" alt="小绿鲸英文文献阅读器">
                        </a>
                    </div>
                "; <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>?>
登录后复制


将刚才转化而来的pdf转化为swf文件需要用运行时间:1.3119211197秒时间


最后则是将swf文件显示在网页中,这一步需要引入多个js文件和其他文件,代码就不写了,直接下载,在我的上传资料中













www.bkjia.comtruehttp://www.bkjia.com/PHPjc/328115.htmlTechArticle复制代码 代码如下: SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif"实现如同百度文库那样类似功能需要进行一系列转化,一般流程想将word转化为...
相关标签:
WPS零基础入门到精通全套教程!
WPS零基础入门到精通全套教程!

全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号