`

java 中 word 转pdf

阅读更多
这个需要的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");
        }
} 

   
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics