很多人问我怎么将word文档转为pdf,用程序,这个就是
package com.zms.office2pdf;
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("C://zms//temp//a.ppt","C://zms//temp//c.pdf");
}
}
是不是很简单,事实上,这个函数可以将Office文档(word,excel,powerpoint)转为pdf
这段代码使用了jcom( http://sourceforge.net/projects/jcom),小日本的一个项目
你的机器需要安装ms office以及acrobat(不是reader)
package com.zms.office2pdf;
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("C://zms//temp//a.ppt","C://zms//temp//c.pdf");
}
}
是不是很简单,事实上,这个函数可以将Office文档(word,excel,powerpoint)转为pdf
这段代码使用了jcom( http://sourceforge.net/projects/jcom),小日本的一个项目
你的机器需要安装ms office以及acrobat(不是reader)