导航:首页 > 文档加密 > 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相关的资料

热点内容
编译方式可生成可执行文件 浏览:768
穿越德国重生1932 浏览:506
蚂蚁金服二面的算法 浏览:516
夸赞程序员的文案 浏览:650
服务器托管属于什么行业类别 浏览:145
大尺度韩国电影 浏览:904
房子解压之后能买吗 浏览:231
丧尸片美味的女主叫什 浏览:604
linux标准c编译器 浏览:221
telnet怎么开启linux 浏览:985
谁有看那种电脑的网站 浏览:650
两界来回穿越的小说 浏览:851
c4d中文本命令出不来文字 浏览:863
方舟服务器怎么设定伽玛 浏览:760
各省父母对程序员女婿评价 浏览:326
电影中有一个叫游白云的是什么电影 浏览:607
单片机原理及接口技术胡建 浏览:652
外国电视剧一般发布在什么网站上 浏览:359
北京市网络加密系统 浏览:537