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

javapdftoword

發布時間:2022-08-18 12:50:09

『壹』 java如何將pdf轉成html或者word-CSDN論壇

試試PDFBox
我昨天用著生成PDF文檔,還行,挺好用,自帶的example把基本的操作都說明了
至於生成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文件和WORD再轉換成PDF文件的功能,求給個思路,盡可能的詳細些。

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

『叄』 如何用純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 怎麼把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導出word

java導出word代碼如下:

package com.bank.util;
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
public class WordTools {
public void createDocContext(String file) throws DocumentException,
IOException {
// 設置紙張大小
Document document = new Document(PageSize.A4);
// 建立一個書寫器(Writer)與document對象關聯,通過書寫器(Writer)可以將文檔寫入到磁碟中
RtfWriter2.getInstance(document, new FileOutputStream(file));
document.open();
// 設置中文字體
BaseFont bfChinese = BaseFont.createFont("STSongStd-Light",
"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
// 標題字體風格
Font titleFont = new Font(bfChinese, 12, Font.BOLD);
// 正文字體風格
Font contextFont = new Font(bfChinese, 10, Font.NORMAL);
Paragraph title = new Paragraph("標題");
// 設置標題格式對齊方式
title.setAlignment(Element.ALIGN_CENTER);
title.setFont(titleFont);
document.add(title);
String contextString = "iText是一個能夠快速產生PDF文件的java類庫。"
+ " \n"// 換行
+ "iText的java類對於那些要產生包含文本,"
+ "表格,圖形的只讀文檔是很有用的。它的類庫尤其與java Servlet有很好的給合。"
+ "使用iText與PDF能夠使你正確的控制Servlet的輸出。";
Paragraph context = new Paragraph(contextString);
// 正文格式左對齊
context.setAlignment(Element.ALIGN_LEFT);
context.setFont(contextFont);
// 離上一段落(標題)空的行數
context.setSpacingBefore(5);
// 設置第一行空的列數
context.setFirstLineIndent(20);
document.add(context);
//利用類FontFactory結合Font和Color可以設置各種各樣字體樣式
/**
* Font.UNDERLINE 下劃線,Font.BOLD 粗體
*/
Paragraph underline = new Paragraph("下劃線的實現", FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 18, Font.UNDERLINE,
new Color(0, 0, 255)));
document.add(underline);

// 設置 Table 表格
Table aTable = new Table(3);
int width[] = {25,25,50};
aTable.setWidths(width);//設置每列所佔比例
aTable.setWidth(90); // 占頁面寬度 90%
aTable.setAlignment(Element.ALIGN_CENTER);//居中顯示
aTable.setAlignment(Element.ALIGN_MIDDLE);//縱向居中顯示
aTable.setAutoFillEmptyCells(true); //自動填滿
aTable.setBorderWidth(1); //邊框寬度
aTable.setBorderColor(new Color(0, 125, 255)); //邊框顏色
aTable.setPadding(0);//襯距,看效果就知道什麼意思了
aTable.setSpacing(0);//即單元格之間的間距
aTable.setBorder(2);//邊框
//設置表頭
/**
* cell.setHeader(true);是將該單元格作為表頭信息顯示;
* cell.setColspan(3);指定了該單元格佔3列;
* 為表格添加表頭信息時,要注意的是一旦表頭信息添加完了之後, \
* 必須調用 endHeaders()方法,否則當表格跨頁後,表頭信息不會再顯示
*/
Cell haderCell = new Cell("表格表頭");
haderCell.setHeader(true);
haderCell.setColspan(3);
aTable.addCell(haderCell);
aTable.endHeaders();
Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.GREEN);
Cell cell = new Cell(new Phrase("這是一個測試的 3*3 Table 數據", fontChinese ));
cell.setVerticalAlignment(Element.ALIGN_TOP);
cell.setBorderColor(new Color(255, 0, 0));
cell.setRowspan(2);
aTable.addCell(cell);
aTable.addCell(new Cell("#1"));
aTable.addCell(new Cell("#2"));
aTable.addCell(new Cell("#3"));
aTable.addCell(new Cell("#4"));
Cell cell3 = new Cell(new Phrase("一行三列數據", fontChinese ));
cell3.setColspan(3);
cell3.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell3);
document.add(aTable);
document.add(new Paragraph("\n"));
//添加圖片
// Image img=Image.getInstance("http://127.0.0.1:8080/testSystem/images/1_r1_c1.png");
// img.setAbsolutePosition(0, 0);
// img.setAlignment(Image.RIGHT);//設置圖片顯示位置
// img.scaleAbsolute(12,35);//直接設定顯示尺寸
// img.scalePercent(50);//表示顯示的大小為原尺寸的50%
// img.scalePercent(25, 12);//圖像高寬的顯示比例
// img.setRotation(30);//圖像旋轉一定角度
// document.add(img);
document.close();
}
public static void main(String[] args){
WordTools b=new WordTools();
try {
b.createDocContext("d:/demo.doc");
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

『陸』 如何用java實現pdf轉word

用java似乎無法實現
靠譜的方法是用ocr軟體,比如abbyy finereader

『柒』 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文檔

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

『玖』 如何用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(這是我們要的)
}
}

閱讀全文

與javapdftoword相關的資料

熱點內容
win埠重啟命令 瀏覽:578
哪部電影有分娩鏡頭 瀏覽:29
韓國R級朴銀狐 瀏覽:237
在沈陽做app推廣地址在哪裡好 瀏覽:207
vue項目獲取組件源碼 瀏覽:9
朝鮮抗日戰爭電影 瀏覽:951
姜銀惠全部5部影片 瀏覽:278
龍游花叢全文閱讀300 瀏覽:522
教授的妻子是房產中介的外國電影 瀏覽:953
法國LOVE電影,在線 瀏覽:599
藝術家的解壓方式 瀏覽:290
如何分段壓縮文件 瀏覽:139
java秒轉分鍾 瀏覽:108
生活中的瑪麗主演 瀏覽:264
紫牛程序員電子書 瀏覽:67
每個軟體自帶編譯器嗎 瀏覽:818
夏晴的都市小說叫什麼 瀏覽:929
pdf中復制文字不顯示 瀏覽:534
回踩黃金分割線選股器源碼 瀏覽:605
騰訊游戲伺服器怎麼總是丟包 瀏覽:726