1。我的word转pdf用到了一个虚拟的打印机,安装一个Adobe Acrobat 7.0 Professional就可以了
2。配置虚拟打印机,开始--打印机和传真--添加打印机---一步一步的配置就行了。
3。点击配置的打印机右键首选项----设置----把不要发送字体到打印机取消勾选
4。下载Jacob.jar包。把jacob.jar所对应的Jacob.dll放在windows/sys32下或者jre/bin下
5。代码部分
代码 package demo;
* 打开word文档 * * * } ex.printStackTrace(); } } * 关闭word文档 } } * 将word文档打印为PS文件后,使用Distiller将PS文件转换为PDF文件 * * * 源文件路径 * * 首先生成的PS文件路径 * * 生成PDF文件路径 String destinPDFFilePath) { closeWord( } Variant Range Dispatch.callN((Dispatch) wordDoc, Background, Append, Range, OutputFileName }); System.out.println( inputPostScriptFilePath, outputPDFFilePath, PDFOption }); System.out.println( } ex.printStackTrace(); } closeWord( } } WordToPdf d2p
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
/*
* 注意word转pdf要安装虚拟打印机,且要配置
* 使用jacob框架,把dll文件放到jre/bin目录下
*/
public class WordToPdf {
private ActiveXComponent wordCom = null;
wordCom = new ActiveXComponent("Word.Application");
Dispatch wrdDocs = wordCom.getProperty("Documents").toDispatch();
wordDoc = Dispatch.invoke(wrdDocs, "Open", Dispatch.Method,
wordCom.invoke("Quit",new Variant[]{});
wordCom=null;
ComThread.Release();
ActiveXComponent distiller = new ActiveXComponent("PDFDistiller.PDFDistiller.1");
wordCom.setProperty("ActivePrinter", new Variant("Adobe PDF"));
Variant Background = False;
Variant Append = False;
int wdPrintAllDocument = 0;
Variant OutputFileName = new Variant(destinPSFilePath);
Variant inputPostScriptFilePath = new Variant(destinPSFilePath);
Variant outputPDFFilePath = new Variant(destinPDFFilePath);
Variant PDFOption = new Variant("");
Dispatch.callN(distiller, "FileToPDF", new Variant[] {
d2p.docToPDF("D:\\test.doc", "D:\\test.ps", "D:\\test.pdf");
boolean success = (new File("D:\\test.ps")).delete();
if(success){
System.out.println("删除打印机文件成功");
}
}
}
来源:https://www.cnblogs.com/Seamanm/archive/2010/10/04/1842091.html