周通德

个人信息Personal Information

工程师(工程、实验)

性别:男

毕业院校:四川师范大学

学历:硕士研究生毕业

学位:教育硕士专业学位

在职信息:在职人员

所在单位:信息中心

办公地点:主楼A2 307室

扫描关注

教师博客

当前位置 中文主页 >> 教师博客

类似幻灯片的JSP网页播放文档

发布时间:2017-07-26   点击次数:

播放器及组件下载地址:
http://code.google.com/p/flexpaper/downloads/list
源码下载 需要使用svn 地址:
http://flexpaper.googlecode.com/svn/trunk/
用 JodConverter(Openoffice)可以在命令行下把

1. OpenDocument Text

2. (*.odt)

3. OpenOffice.org 1.0 Text (*.sxw)

4. Rich Text Format (*.rtf)

5. Microsoft

6. Word (*.doc)

7. WordPerfect (*.wpd)

8. Plain Text (*.txt)

9. HTML1

10.  (*.html)

复制代码
转换成pdf
而swftools 可以把 pdf转成swf
然后用flexpager播放器就可以了

通过调用JODConverter将格式为WORD的DOC文件转换成PDF格式文件很容易,核心代码只有几句:
File inputFile = new File(“C:\\Documents and Settings\\ccnustone\\桌面\\新建文件夹\\数据挖掘技术简介.doc”);
File outputFile = new File(“C:\\Documents and Settings\\ccnustone\\桌面\\新建文件夹\\数据挖掘技术简介.pdf”);
// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();
// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// close the connection
connection.disconnect();
先到http://sourceforge.net/project/showfiles.php?group_id=91849下载jodconverter-2.2.1.zip,接压缩后,找到LIB文件夹,将里面的包配置到Build Path中,启动OPEN OFFICE的服务就OK了。至于要实现其他格式转换,可以参看里面的API。

这里主要是借助 OpenOffice3.2,不需要安装版,USB版也可以
jodconverter

http://struts.javaeye.com/?show_full=true

官方網站:

http://www.artofsolving.com/opensource/jodconverter

下載地點:

http://www.artofsolving.com/opensource/jodconverter

http://zh.openoffice.org/new/zh_tw/downloads.html

目前版本: JODConverter v2.2.1, OpenOffice v3.0.0
使用需求: JDK1.4以上, 安裝OpenOffice v2.0.3以上
基本簡介:
JODConverter主要的功能是用來做各種檔案的轉換. 目前測試過, Word,Excel,PowerPoint轉PDF都是沒問題的.
因為JODConverter是透過OpenOffice來做轉換, 所以使用前需要先安裝OpenOffice, 並且將OpenOffice的Service啟動, 才可以使用.
使用教學:
Step1: 安裝OpenOffice
Step2: 啟動OpenOffice Service
1 cd C:\Program Files\OpenOffice.org 3\program
2 soffice -headless -accept=”socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard
Step3:將JODConverter的Jar檔放進專案中的Library, 請檢查你的專案是否包含以下的Jar檔:
jodconverter-2.2.1.jar
jurt-2.3.0.jar
xstream-1.2.2.jar
ridl-2.3.0.jar
commons-io-1.3.1.jar
juh-2.3.0.jar
slf4j-api-1.4.3.jar
unoil-2.3.0.jar
slf4j-jdk14-1.4.3.jar
Step4: 準備一個word檔放在c:/document.doc
Step5: 執行以下程式
import java.io.File;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
public class JodDemo {
public static void main(String[] args) throws Exception{
File inputFile = new File(“c:/document.doc”);
File outputFile = new File(“c:/document.pdf”);
// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();
// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// close the connection
connection.disconnect();
}
}
程式說明:
程式的部份相當簡潔, 特別要注意的地方是第12行連線的port必須與你啟動OpenOffice的Port相同,
另外JODConverter預設是用副檔名作文件種類的判斷, 所以副檔名必須要正確才行.
如果副檔名比較特別的話, 就必須在convert()的時候強制指定Document Type.
心得:
JODConverter使用起來相當方便, 官網也提供War檔讓JODConverter變成Web Service提供給不同的語言來呼叫.
特別要注意的是, OpenOffice Service並不是ThreadSafe的, 多個Web AP在使用的時候必須要注意.
參考資料:

http://www.artofsolving.com/opensource/jodconverter

那我也來補充一些好了
之前也在試這個檔案轉換的程式
程式最好加上 try-catch
因為之前發現有些檔案 format 不能轉,發生 Exception 後,connection 不會自動切斷,程式會 hand 住
所以改成如下方式:
1234567891011121314
public void convert(String input, String output){
        File inputFile = new File(input);
        File outputFile = new File(output);
        OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
        try {
            connection.connect();
            DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
            converter.convert(inputFile, outputFile);
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            try{ if(connection != null){connection.disconnect(); connection = null;}}catch(Exception e){}
        }
    }
再來,明明就是 open office 的檔案,卻生不能轉換的問題。例如:*.STW, *.SXD, *.ODF 等,後來才知道可以自行指定來源檔和輸出檔的 mime-type,程式如下:
1234567891011121314151617
public void convertSTW(String input, String output){
        DocumentFormat stw = new DocumentFormat(“OpenOffice.org 1.0 Template”, DocumentFamily.TEXT, “application/vnd.sun.xml.writer”, “stw”);
        DefaultDocumentFormatRegistry formatReg = new DefaultDocumentFormatRegistry();
        DocumentFormat pdf = formatReg.getFormatByFileExtension(“pdf”);
        File inputFile = new File(input);
        File outputFile = new File(output);
        OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
        try {
            connection.connect();
            DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
            converter.convert(inputFile, stw, outputFile, pdf);
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            try{ if(connection != null){connection.disconnect(); connection = null;}}catch(Exception e){}
        }
    }
上面的程式是轉換 STW 到 PDF,如果是 SXD / ODF 則只需要變更 DocumentFormat 的內容即可。
123
DocumentFormat sxd = new DocumentFormat(“OpenOffice.org 1.0 Drawing”, DocumentFamily.DRAWING, “application/vnd.sun.xml.sraw”, “sxd”);
DocumentFormat odf = new DocumentFormat(“OpenDocument Math”, DocumentFamily.TEXT, “application/vnd.oasis.opendocument.formula”, “odf”);
所有 default support 的 DocumentFormat 都在 com.artofsolving.jodconverter.DefaultDocumentFormatRegistry 裡,但並非所有 open office 支援的 file format 都有,所以要像上面的方法自行去定義 DocumentFormat。
在此獻給所有需要作 File Convert 的人試試。
免錢的,最好用。還有 source code 可以自己改。

配置JODConverter为一个WEB应用

2009年04月12日 星期日 18:13

1、安装JDK(具体怎么实现请百度)

2、安装TOMCAT(具体实现请百度)

3、安装OPENOFFICE,可到官方下载http://www.openoffice.org/,然后傻瓜式安装;

3、下载jodconverter-webapp-2.2.1.zip,可到http://sourceforge.net/project/showfiles.php?group_id=91849下载,解压缩,找到jodconverter-webapp-2.2.1.war文件,放到TOMCAT下webapps目录,文件名太长,改个名字,如:converter.war。TOMCAT在运行的时候,会自动识别解压。

4、启动TOMCAT,这个时候还不能直接运行,需要启动OPENOFFICE的服务,否则就要报下面的错误:

5、启动OPENOFFICE的服务,在命令提示符下输入:soffice -headless -accept=”socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard

6、好了,现在可以运行看下效果了: