将office文档(word,excel,powerpoint)转换为pdf
本文中的方法可以将Office文档(word,excel,powerpoint)转为pdf文档。代码中使用了jcom(http://sourceforge.net/projects/jcom),日本的一个项目。
import jp.ne.so_net.ga2.no_ji.jcom.IDispatch; import jp.ne.so_net.ga2.no_ji.jcom.ReleaseManager; public class Office2Pdf { public void createPDF(String officePath,String pdfPath) throws Exception { ReleaseManager rm = null; IDispatch app = null; try { rm=new ReleaseManager(); app = new IDispatch(rm, "PDFMakerAPI.PDFMakerApp"); app.method("CreatePDF",new Object[]{officePath,pdfPath}); } catch (Exception e) { throw e; } finally { try { app=null; rm.release(); rm = null; } catch (Exception e) { throw e; } } } public static void main(String[] args) throws Exception { Office2Pdf one=new Office2Pdf(); one.createPDF("E:\\codigg.ppt","E:\\codigg-ppt.pdf"); one.createPDF("E:\\codigg.doc","E:\\codigg-doc.pdf"); one.createPDF("E:\\codigg.xls","E:\\codigg-xls.pdf"); } } |
需要运行环境:Windows,Acrobat(不是Reader哦),MS Office。
本方法由zms@newsmth网友原创。
原创文章如转载,请注明:转载自CODIGG [ http://www.codigg.com/ ]
本文链接地址:http://www.codigg.com/2009/05/office-word-excel-ppt-to-pdf-java/


六月 3rd, 2009 at 05:37
Hi, good post. I have been wondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.
[回复]
六月 3rd, 2009 at 07:30
Hi, good post. I have been wondering about this issue,so thanks for posting.
[回复]
六月 22nd, 2009 at 13:01
有时间了, 试试
[回复]
匿名 回复:
七月 14th, 2009 at 17:42
一直报”Exception in thread “main” java.lang.UnsupportedClassVersionError: Bad version number in .class file”错误,不知道是什么原因
[回复]
Codigg 回复:
七月 27th, 2010 at 11:30
这个是java class版本不对。
[回复]
一月 21st, 2010 at 18:04
thanks
[回复]
三月 24th, 2010 at 14:25
一款高质量的pdf文档转换工具。完全兼容pdf规格,超强转换功能。可自由地将各种文本文件迅速地转换成为pdf文件。
[回复]
七月 6th, 2010 at 22:40
app.method(“CreatePDF”, new Object[] { officePath, pdfPath });
调用的时候会有对话框,
请问怎么隐藏转换对话框(PDFMAKER)??
[回复]
Codigg 回复:
七月 27th, 2010 at 11:31
你的office和adobe pdf版本是多少?
[回复]
八月 18th, 2010 at 09:42
请问下adobe pdf 我装的是专业版,可以转换了。但是现在就是不安装pdf 专业版的话,把安装过的文件PDFMakerAPI等拷下来,作调用,这样可以转吗?
[回复]
Codigg 回复:
八月 18th, 2010 at 15:18
估计够呛。
这个实际上是利用了已经安装的软件的东西,如果只是拷贝,可能有些环境变量没有。
不过您可以试一下,如果可以的话,可以告诉我一下测试结果,谢谢:)
[回复]
八月 29th, 2010 at 10:39
怎么下载啊
[回复]
八月 29th, 2010 at 10:40
怎么下载,急用啊
[回复]
Codigg 回复:
八月 30th, 2010 at 22:14
下载什么?
代码都贴出来了啊
[回复]