導航:首頁 > 文檔加密 > socketpdf

socketpdf

發布時間:2024-12-30 17:11:10

㈠ 請教關於java利用現有word文檔生成pdf的問題

1. 需要用的軟體
OpenOffice 下載地址http://www.openoffice.org/
JodConverter 下載地址http://sourceforge.net/projects/jodconverter/files/JODConverter/,也可以直接從附件裡面下載

2.啟動OpenOffice的服務

安裝完openoffice,安裝服務
cd C:\Program Files (x86)\OpenOffice 4\program
執行
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
查看是否安裝成功,查看埠對應的pid
netstat -ano|findstr "8100"
查看pid對應的服務程序名
tasklist|findstr "pid值"

3.將JodConverter相關的jar包添加到項目中

4. 下面是實現代碼

附件裡面有現成的可以用的項目示例,直接導入eclipse就可以運行

[java] view plain
/**
* 將Office文檔轉換為PDF. 運行該函數需要用到OpenOffice, OpenOffice下載地址為
* http://www.openoffice.org/
*
* <pre>
* 方法示例:
* String sourcePath = "F:\\office\\source.doc";
* String destFile = "F:\\pdf\\dest.pdf";
* Converter.office2PDF(sourcePath, destFile);
* </pre>
*
* @param sourceFile
* 源文件, 絕對路徑. 可以是Office2003-2007全部格式的文檔, Office2010的沒測試. 包括.doc,
* .docx, .xls, .xlsx, .ppt, .pptx等. 示例: F:\\office\\source.doc
* @param destFile
* 目標文件. 絕對路徑. 示例: F:\\pdf\\dest.pdf
* @return 操作成功與否的提示信息. 如果返回 -1, 表示找不到源文件, 或url.properties配置錯誤; 如果返回 0,
* 則表示操作成功; 返回1, 則表示轉換失敗
*/
public static int office2PDF(String sourceFile, String destFile) {
try {
File inputFile = new File(sourceFile);
if (!inputFile.exists()) {
return -1;// 找不到源文件, 則返回-1
}

// 如果目標路徑不存在, 則新建該路徑
File outputFile = new File(destFile);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}

// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(
"127.0.0.1", 8100);
connection.connect();

// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(
connection);
converter.convert(inputFile, outputFile);

// close the connection
connection.disconnect();

return 0;
} catch (FileNotFoundException e) {
e.printStackTrace();
return -1;
} catch (ConnectException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return 1;
}

㈡ 如何用java判斷一個url是不是PDF類型的文件

我不知道該如何判斷  但我有一個很笨的方法
如果是一個下載文件 後台會有下面的操作(J2EE,其他平台也一樣,重點是括弧裡面的參數)
res.setContentType("application/x-download;charset=gbk");
res.setHeader("Content-Disposition" ,"attachment;filename=test.pdf");
得到鏈接之後需要訪問每個鏈接 使用socket的輸入流獲取每個鏈接的頭信息  根據頭信息判斷是否為pdf文件
但這樣有一個bug  有些網站給文件取名字不一定就是以真正文件的後綴名結尾 
其次 一些壓縮文件裡面可能也有pdf文件  這樣的pdf文件是搜索不出來的

閱讀全文

與socketpdf相關的資料

熱點內容
路由器怎麼加密更安全 瀏覽:695
內存卡加密卡是什麼意思 瀏覽:694
幫別人做app需要注意什麼 瀏覽:667
android獲取string字元 瀏覽:181
python中的計數器 瀏覽:622
海地加密驅動安裝 瀏覽:842
慧凈電子12單片機開發板 瀏覽:940
什麼網段伺服器好 瀏覽:598
伺服器商店怎麼造 瀏覽:934
有什麼跳鬼步舞的app 瀏覽:250
倚天2如何自己搭建伺服器 瀏覽:553
我的世界如何讓伺服器刷神寵 瀏覽:624
為什麼程序員要盡量進大廠 瀏覽:3
phpfiletype 瀏覽:936
PHP用戶登錄管理系統源碼 瀏覽:199
你適合做程序員嗎 瀏覽:896
easyuidatagrid源碼分析 瀏覽:115
安卓系統固件怎麼下載 瀏覽:491
php如何執行sql語句 瀏覽:30
通知加密怎麼設置vivo 瀏覽:989