如何使用java代码实现pdf文档转成Word文档?
展开全部 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就麻烦了。
爪哇是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaEE, JavaME, JavaSE)的总称。
Java自面世后就非常流行,发展迅速,对C++语言形成了有力冲击。
Java技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于个人PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
在全球云计算和移动互联网的产业环境下,Java更具备了显著优势和广阔前景。
如何用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的DispatchDispatch wrdDocs = wordCom.getProperty("Documents").toDispatch();//调用wrdCom.Documents.Open方法打开指定的word文档,返回wordDocwordDoc = 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 PDFDistillerComThread.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(这是我们要的)}}
word文档转换成pdf 用java代码怎么实现
推荐下面免费的方法转成PDF试试:方法一:使用虚拟打印机pdf factory即可,而且其他格式文件只要是能够打印,选择这个虚拟打印机,都可以做成PDF文件,很简单实用;方法二:使用专门的转换软件,把文件转成PDF文件;方法三:用其他虚拟打印机转成PDF文件。
方法四:用WPS本身自带的转换功能转成PDF文件。
...
PDF文件转Word文档急
PDF2Word(pdf转word工具)V1.6 汉化绿色修正版 PDF2Word(pdf to word)让你可以把文本,图片以及其他内容从pdf文档中输出到word文档中,所以你能够重新编辑pdf内容,PDF2Word将保存文本,版面和图片到生成的word文档中。
PDF2Word(pdf to word)是一个独立的软件,所以你不需要安装Microsoft Word,Adobe Acrobat,甚至 Acrobat Reader来运行它。
PDF的阅读 用Adobe公司的Arcobat Reader 9.0软件(该软件免费)即可阅读PDF文件。
更多信息请访问 Adobe 站点。
( ) 还有现在很多厂家的产品也能够浏览pdf,比如windows平台下的Apabi Reader,linux平台下的kpdf等等 Adobe Reader 9.3 简体中文版
java 生成PDF表格
展开全部 实现代码如下:package com.qhdstar.java.pdf; import java.awt.Color;import java.io.FileOutputStream; import com.lowagie.text.Chapter;import com.lowagie.text.Document;import com.lowagie.text.Font;import com.lowagie.text.FontFactory;import com.lowagie.text.PageSize;import com.lowagie.text.Paragraph;import com.lowagie.text.Section;import com.lowagie.text.pdf.PdfWriter; /** * 描述:TODO 【JAVA生成PDF】 * * * @title GeneratePDF* @version V1.0 */public class GeneratePDF { public static void main(String[] args) { //调用第一个方法,向C盘生成一个名字为ITextTest.pdf 的文件 try { writeSimplePdf(); } catch (Exception e) { e.printStackTrace(); }//调用第二个方法,向C盘名字为ITextTest.pdf的文件,添加章节。
try { writeCharpter(); } catch (Exception e) { e.printStackTrace(); }} public static void writeSimplePdf() throws Exception { // 1.新建document对象 // 第一个参数是页面大小。
接下来的参数分别是左、右、上和下页边距。
Document document = new Document(PageSize.A4, 50, 50, 50, 50); // 2.建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
// 创建 PdfWriter 对象 第一个参数是对文档对象的引用,第二个参数是文件的实际名称,在该名称中还会给出其输出路径。
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:\\ITextTest.pdf")); // 3.打开文档 document.open(); // 4.向文档中添加内容 // 通过 com.lowagie.text.Paragraph 来添加文本。
可以用文本及其默认的字体、颜色、大小等等设置来创建一个默认段落 document.add(new Paragraph("First page of the document.")); document.add(new Paragraph("Some more text on the first page with different color and font type.", FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new Color(255, 150, 200)))); // 5.关闭文档 document.close(); } /** * 添加含有章节的pdf文件 * * @throws Exception */ public static void writeCharpter() throws Exception { // 新建document对象 第一个参数是页面大小。
接下来的参数分别是左、右、上和下页边距。
Document document = new Document(PageSize.A4, 20, 20, 20, 20); // 建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:\\ITextTest.pdf")); // 打开文件 document.open(); // 标题 document.addTitle("Hello mingri example"); // 作者 document.addAuthor("wolf"); // 主题 document.addSubject("This example explains how to add metadata."); document.addKeywords("iText, Hello mingri"); document.addCreator("My program using iText"); // document.newPage(); // 向文档中添加内容 document.add(new Paragraph("\n")); document.add(new Paragraph("\n")); document.add(new Paragraph("\n")); document.add(new Paragraph("\n")); document.add(new Paragraph("\n")); document.add(new Paragraph("First page of the document.")); document.add(new Paragraph("First page of the document.")); document.add(new Paragraph("First page of the document.")); document.add(new Paragraph("First page of the document.")); document.add(new Paragraph("Some more text on the first page with different color and font type.", FontFactory.getFont(FontFactory.defaultEncoding, 10, Font.BOLD, new Color(0, 0, 0)))); Paragraph title1 = new Paragraph("Chapter 1", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255))); // 新建章节 Chapter chapter1 = new Chapter(title1, 1); chapter1.setNumberDepth(0); Paragraph title11 = new Paragraph("This is Section 1 in Chapter 1", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0))); Section section1 = chapter1.addSection(title11); Paragraph someSectionText = new Paragraph("This text comes as part of section 1 of chapter 1."); section1.add(someSectionText); someSectionText = new Paragraph("Following is a 3 X 2 table."); section1.add(someSectionText); document.add(chapter1); // 关闭文档 document.close(); } }
转载请注明出处51数据库 » java web pdf转word文档