-
官方網(wǎng)站下載
jodconverter開發(fā)包。

下載.png
2.解壓下載后的開發(fā)包,將lib下的jar包全部拷貝到項(xiàng)目中去。

引入jar.png
3.附文檔轉(zhuǎn)換源碼
/**
* 可以將一種類型的文檔轉(zhuǎn)化為另一種類型,例如:.doc 轉(zhuǎn)為 .pdf
*
* @param sourcePath
* 源文件路徑
* @param destPath
* 目標(biāo)文件路徑
* @return
*/
public int turn(String sourcePath, String destPath) {
try {
File inputFile = new File(sourcePath);
if (!inputFile.exists()) {
return -1;// 找不到源文件, 則返回-1
}
File outputFile = new File(destPath);
// 連接到openOffice服務(wù)
OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
connection.connect();
// 將源文件轉(zhuǎn)換為目標(biāo)文件
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// 關(guān)閉連接服務(wù)
connection.disconnect();
return 0;
} catch (ConnectException e) {
e.printStackTrace();
}
return 1;
}