欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java 中 word 转pdf 博客分类: java word pdf jcomjavapdfdoc转pdf 

程序员文章站 2024-03-25 12:12:04
...
这个需要的jcom.jar和jcom.dll,还需要安装Acrobat_Pro_8.1.2软件
   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");
        }
}