Wor" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > 在linux环境下,<em>java</em>怎么实现从<em>word</e

在linux环境下,<em>java</em>怎么实现从<em>word</e

作者:乔山办公网日期:

返回目录:word文档


http://git.oschina.net/Count/html2pdf
这儿html转pdf的

Word转换成pdf格式是比较简单的,我们使用pdf转换器就可以轻松将word转换成pdf格式

参考软件:迅捷pdf转换器

参考步骤:第一步:打开桌面上的迅捷pdf转换器,然后选择“其他文件转换成PDF”,再选择“word转成pdf”

第二步:然后选择添加zd文件,把需要转换的文件的添加进去,之后选择“开始转换”

第三步:转换好之后选择“输出”,把转换好的文件输出保存下来就可以了


import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

/**
* @author XuMing Li
*
* @version 1.00, 2007-4-9
*
*/
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方法打开指7a686964616fe58685e5aeb9361定的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( "Adobe PDF "));
//设置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();
}
}

public static void main(String[] argv) {
D2P d2p = new D2P();
// d2p.openWord( "c:/12.doc ");
// d2p.callWordMacro( "c:/12.docc ", "MyWordMacro ",
// new String[] { "这是调用word宏的测试程序 " });
d2p.docToPDF( "d:/12.doc ", "c:/1p.ps ", "c:/1p.pdf ");
}
}

Docs to PDF Converter纯java,不过作者不再维护了zd.

支持格式:DOC, DOCX, PPT, PPTX and ODT

https://github.com/yeokm1/docs-to-pdf-converter

XDocReport纯java

https://github.com/opensagres/xdocreport

jodconverter,支持MS office 2007大部分格式转换到pdf

使用须知:

  1. java运行时1.4或更高.

  2. openoffice v2.0.3或者更高,openoffice需要安装在linux上.

支持格式:

相关阅读

  • <em>java</em> 怎么把<em>pdf</em>转成<e

  • 乔山办公网word文档
  • 用Java内嵌iText生成PDF文档需要5个步骤:百①建立com.lowagie.text.Document对象的实例。Document document = new Document();②建立一个度书写器(Writer)与document对象关知联,通过书道写器(Writer)可以将文
  • <em>word</em>文档转换成<em>pdf</em> 用<

  • 乔山办公网word文档
  • 我曾经也尝试使用纯百java技术去解析word文档,并且使用度了apache的jacob,POI等项目,但是由于Microsoft Word使用的doc不是标准DOC文件,而是自己加处理过的,问所以现在解析微软的doc都只能
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网