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

流程:

        文档(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的服务,它的进程会一直存在,而且每当你转换一个文件它所占用的内存就会增加,到最后内存越来越大,服务器反应越来越慢,最终挂掉。。。 这个问题暂时没有好的解决方法

你可能感兴趣的:(File,cmd,百度,null,文档,Path)