实现word等在线预览(百度文库)

思想:将word之类的文件先用openoffice转为pdf,再将pdf文件通过swftools转为swf文件,最后通过Flexpaper展示在页面上

第一步:

首先需安装OpenOffice,并注册com组件(方法可以百度到),接着可以运行代码:

<?php
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){ 
//Invoke the http://OpenOffice.org service manager 
$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that http://OpenOffice.org is installed.\n"); 
//Set the application to remain hidden to avoid flashing the document onscreen 
$args = array(MakePropertyValue("Hidden",true,$osm)); 
//Launch the desktop 
$top = $osm->createInstance("com.sun.star.frame.Desktop"); 
//Load the .doc file, and pass in the "Hidden" property from above 
$oWriterDoc = $top->loadComponentFromURL($doc_url,"_blank", 0, $args); 
//Set up the arguments for the PDF output 
$export_args = array(MakePropertyValue("FilterName","writer_pdf_Export",$osm)); 
//Write out the PDF 
$oWriterDoc->storeToURL($output_url,$export_args); 
$oWriterDoc->close(true); 

$doc_file = "file:///f:/2.doc";   //此路径比较重要,一般出问题比较多
$output_file = 'file:///f:/3.pdf';  //此路径比较重要,一般出问题比较多
word2pdf($doc_file,$output_file);
?>


第二步:安装swftools,并调用命令行(注意加上-s flashversion=9,否则在flexpaper可能展示不出来)


第三步,下载flexpaper,直接将转过后的swf路径加载进去,即可完美展示。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值