導航:首頁 > 文檔加密 > java把pdf轉換成word

java把pdf轉換成word

發布時間:2022-12-13 14:11:44

java word轉pdf

可以試試spire.doc for java轉換Word到PDF

㈡ java 怎麼把pdf轉成word

可以用PDFBox
至於生成word,用POI;HTML的話,自己解析就可以了
PDFBox是一個開源的可以操作PDF文檔的Java PDF類庫。它可以創建一個新PDF文檔,操作現有PDF文檔並提取文檔中的內容。
它具有以下特性:
1.將一個PDF文檔轉換輸出為一個文本文件。
2.可以從文本文件創建一個PDF文檔。
3.加密/解密PDF文檔。
4.向已有PDF文檔中追加內容。
5.可以從PDF文檔生成一張圖片。
6.可以與Jakarta Lucene搜索引擎的整合

㈢ 如何使用java代碼實現pdf文檔轉成Word文檔

不需要那麼麻煩,Adobe公司的軟體可以完美解決你的困惑

㈣ 用java編程,完成本地PDF文件轉換成WORD文件和WORD再轉換成PDF文件的功能,求給個思路,盡可能的詳細些。

思路是先把PDF文件轉換成WORD然後再把WORD轉換成PDF,代碼你自己寫吧

㈤ 如何用java將pdf文件轉換成word文件

需要用到插件jacob,自己去下載吧。
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class D2P {
private ActiveXComponent wordCom = null;

private Object wordDoc = null;

private final Variant False = new Variant(false);

private final Variant True = new Variant(true);

/** *//** *//** *//**
* 打開word文檔
*
* @param filePath
* word文檔
* @return 返回word文檔對象
*/
public boolean openWord(String filePath) {
//建立ActiveX部件
wordCom = new ActiveXComponent("Word.Application");

try {
//返回wrdCom.Documents的Dispatch
Dispatch wrdDocs = wordCom.getProperty("Documents").toDispatch();
//調用wrdCom.Documents.Open方法打開指定的word文檔,返回wordDoc
wordDoc = Dispatch.invoke(wrdDocs, "Open", Dispatch.Method,
new Object[] { filePath }, new int[1]).toDispatch();
return true;
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}

/** *//** *//** *//**
* 關閉word文檔
*/
public void closeWord() {
//關閉word文件
wordCom.invoke("Quit", new Variant[] {});
}

/** *//** *//** *//**
* * 將word文檔列印為PS文件後,使用Distiller將PS文件轉換為PDF文件 *
*
* @param sourceFilePath
* 源文件路徑 *
* @param destinPSFilePath
* 首先生成的PS文件路徑 *
* @param destinPDFFilePath
* 生成PDF文件路徑
*/
public void docToPDF(String sourceFilePath, String destinPSFilePath,
String destinPDFFilePath) {
if (!openWord(sourceFilePath)) {
closeWord();
return;
}
//建立Adobe Distiller的com對象
ActiveXComponent distiller = new ActiveXComponent(
"PDFDistiller.PDFDistiller.1");
try {
//設置當前使用的列印機,我的Adobe Distiller列印機名字為"Adobe PDF"
wordCom.setProperty("ActivePrinter", new Variant("MS Publisher Color Printer"));
//設置printout的參數,將word文檔列印為postscript文檔。目前只使用了前5個參數,如果要使用更多的話可以參考MSDN的office開發相關api
//是否在後台運行
Variant Background = False;
//是否追加列印
Variant Append = False;
//列印所有文檔
int wdPrintAllDocument = 0;
Variant Range = new Variant(wdPrintAllDocument);
//輸出的postscript文件的路徑
Variant OutputFileName = new Variant(destinPSFilePath);

Dispatch.callN((Dispatch) wordDoc, "PrintOut", new Variant[] {
Background, Append, Range, OutputFileName });
System.out.println("由word文檔列印為ps文檔成功!");
//調用Distiller對象的FileToPDF方法所用的參數,詳細內容參考Distiller Api手冊
//作為輸入的ps文檔路徑
Variant inputPostScriptFilePath = new Variant(destinPSFilePath);
//作為輸出的pdf文檔的路徑
Variant outputPDFFilePath = new Variant(destinPDFFilePath);
//定義FileToPDF方法要使用adobe pdf設置文件的路徑,在這里沒有賦值表示並不使用pdf配置文件
Variant PDFOption = new Variant("");
//調用FileToPDF方法將ps文檔轉換為pdf文檔
Dispatch.callN(distiller, "FileToPDF", new Variant[] {
inputPostScriptFilePath, outputPDFFilePath, PDFOption });
System.out.println("由ps文檔轉換為pdf文檔成功!");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
closeWord();
wordCom=null;
//釋放在程序線程中引用的其它com,比如Adobe PDFDistiller
ComThread.Release();
}
}

public static void main(String[] argv) {
D2P d2p = new D2P();
d2p.docToPDF("d:/12.doc", "d:/1p.ps", "d:/1p.pdf");
//這里是你建一個叫12.doc的word文檔,生成的文檔將在D盤下
//1p.ps和1p.pdf(這是我們要的)
}
}

㈥ 如何用純java代碼實現word轉pdf

幾種方案:
方法一:用apache pio 讀取doc文件,然後轉成html文件用Jsoup格式化html文件,最後用itext將html文件轉成pdf。

方法2:使用jdoctopdf來實現,這是一個封裝好的包,可以把doc轉換成pdf,html,xml等格式,調用很方便
地址:
需要注意中文字體的寫入問題。

方法3:使用jodconverter來調用openOffice的服務來轉換,openOffice有個各個平台的版本,所以這種方法跟方法1一樣都是跨平台的。
jodconverter的下載地址:
首先要安裝openOffice,下載地址:
安裝完後要啟動openOffice的服務,具體啟動方法請自行google

方法4:效果最好的一種方法,但是需要window環境,而且速度是最慢的需要安裝msofficeWord以及SaveAsPDFandXPS.exe(word的一個插件,用來把word轉化為pdf)
Office版本是2007,因為SaveAsPDFandXPS是微軟為office2007及以上版本開發的插件
SaveAsPDFandXPS下載地址:
jacob 包下載地址:

㈦ 如何用純java代碼實現word轉pdf

1:用apache pio 讀取doc文件,然後轉成html文件用Jsoup格式化html文件,最後用itext將html文件轉成pdf。

2:使用jdoctopdf來實現,這是一個封裝好的包,可以把doc轉換成pdf,html,xml等格式,調用很方便。

3:地址http://www.maxstocker.com/jdoctopdf/downloads.php

需要注意中文字體的寫入問題。

4:使用jodconverter來調用openOffice的服務來轉換,openOffice有個各個平台的版本,所以這種方法跟方法1一樣都是跨平台的。

jodconverter的下載地址:http://www.artofsolving.com/opensource/jodconverter

首先要安裝openOffice,下載地址:office.org/download/index.html" target="_blank">http://www.openoffice.org/download/index.html

5:安裝完後要啟動openOffice的服務,具體啟動方法請自行google。

6:效果最好的一種方法,但是需要window環境,而且速度是最慢的需要安裝msofficeWord以及SaveAsPDFandXPS.exe(word的一個插件,用來把word轉化為pdf)

7:Office版本是2007,因為SaveAsPDFandXPS是微軟為office2007及以上版本開發的插件。

8:SaveAsPDFandXPS下載地址:microsoft.com/zh-cn/download/details.aspx?id=7" target="_blank">http://www.microsoft.com/zh-cn/download/details.aspx?id=7。

9:需要轉換的工具 ,看你是linux還是word 。word還好不需要安裝。linux就麻煩了。

㈧ java中怎麼將word轉pdf

能安裝第三方軟體的話,可以考慮以使用Spire.Doc for Java:

你可以在Java程序中添加 Spire.Doc.jar 文件作為依賴項。可以從這個鏈接下載 JAR 文件;如果使用Maven,則可以通過在 pom.xml 文件中添加以下代碼導入 JAR 文件。

repositories>
<repository>
<id>com.e-iceblue</id>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository></repositories><dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>5.2.3</version>
</dependency></dependencies>

將Word轉換成PDF:

Spire.Doc for Java擁有強大的文件轉換功能,其提供了 Document. saveToFile(String fileName, FileFormat fileFormat) 方法可將 Word 文檔轉為多種格式的目標文件,下面是轉為 PDF 的方法步驟:

Java代碼如下:

import com.spire.doc.*;public class WordToPDF{
public static void main(String[] args) {
//實例化Document類的對象
Document doc = new Document();

//載入Word
doc.loadFromFile("測試.docx");

//保存為PDF格式
doc.saveToFile("WordToPDF.pdf",FileFormat.PDF);
}

}

希望對您有幫助。

閱讀全文

與java把pdf轉換成word相關的資料

熱點內容
dvd光碟存儲漢子演算法 瀏覽:757
蘋果郵件無法連接伺服器地址 瀏覽:962
phpffmpeg轉碼 瀏覽:671
長沙好玩的解壓項目 瀏覽:142
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:732
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:484
h3c光纖全工半全工設置命令 瀏覽:141
公司法pdf下載 瀏覽:381
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:349
風翼app為什麼進不去了 瀏覽:778
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:150
伊克塞爾文檔怎麼進行加密 瀏覽:890
app轉賬是什麼 瀏覽:163