实现类似百度文库的文档在线阅读功能

流程:

        文档(doc,xls,ppt,txt)上传后

        用OpenOffice转换成PDF,

        再用pdf2swf将pdf转换成swf,

        用FlexPaper嵌入网页,实现在线浏览

 

需要安装OpenOffice和pdf2swf

需要的下载jodconverter-2.2.2.zip将包都加入到项目中

需要FlexPaper

 

在OpenOffice转换PDF前需要将OpenOffice的服务打开

Runtime.getRuntime().exec("cmd /c D:/oo/OpenOffice/program/soffice.exe -nologo -headless -norestore -accept=/"socket,host=localhost,port=8100;urp/" -nofirststartwizard")

请注意 OpenOffice和pdf2swf的安装路径最好不要有空格,如果有,比如默认路径C:/Program Files/...,在调用的时候必须带上双引号,否则不能调用成功

 
        //文档转换PDF过程
        File doc = new File(path + "/" + name);
        File pdf = new File(path + "/" + pdfName);
        OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
        try {
         connection.connect();
         // convert
         DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
         converter.convert(doc, pdf);
        } catch (ConnectException cex) {
         cex.printStackTrace();
        } finally {
         // close the connection
         if (connection != null) {
          connection.disconnect();
          connection = null;
         }
        }

 

        String pdfPath = path+"/"+pdfName;
        String outSwf = path+"/"+fName+".swf";
        //调用cmd转换成swf过程
        Runtime.getRuntime().exec("cmd /c D:/tools/pdf2swf.exe -t /""+pdfPath+"/" -o /""+outSwf+"/"");

 

这是转换PDF和SWF的代码片段,我很郁闷的是这csdn的代码的插入功能也太不好用了吧。。。

 

 

还有一个问题就是,打开OpenOffice的服务,它的进程会一直存在,而且每当你转换一个文件它所占用的内存就会增加,到最后内存越来越大,服务器反应越来越慢,最终挂掉。。。 这个问题暂时没有好的解决方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值