• 大小: 982KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-01
  • 语言: Java
  • 标签: java  jacob  word  pdf  格式  

资源简介

java 使用jacob Word转PDF 完美格式,包内含有 jacob.jar包,office提供的SaveAsPDFandXPS.exe插件,以及源码、和步骤操作说明书

资源截图

代码片段和文件信息

package com.dw.ws.KpiQuery;

import java.io.File;

import org.apache.poi.POIxmlDocument;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant; 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Word2pdf {

public static void main(String[] arg){
wordToPDF();
}
static final int wdFormatPDF = 17;// PDF 格式    
    public static void wordToPDF(){    
            
        System.out.println(“启动Word...“);      
        long start = System.currentTimeMillis();      
        ActiveXComponent app = null;  
        Dispatch doc = null;  
        try {      
            app = new ActiveXComponent(“Word.Application“);      
            app.setProperty(“Visible“ new Variant(false));  
            Dispatch docs = app.getProperty(“Documents“).toDispatch();    
            
            //String path =  this.getSession().getServletContext().getRealPath(“/“)+“attachment/“;
            //String sfileName = path+“/doc/“+ docFileName + “.doc“;
            //String toFileName = path+“/pdf/“+ docFileName + “.pdf“;
            
            String sfileName = “C:/Users/xbx/Desktop/关于召开济南高新区创建全国文明城市工作动员暨百日会战誓师大会的工作方案.docx“;
            String toFileName = “C:/Users/xbx/Desktop/关于召开济南高新区创建全国文明城市工作动员暨百日会战誓师大会的工作方案.pdf“;
           
            
            doc = Dispatch.call(docs  “Open“  sfileName).toDispatch();  
            System.out.println(“打开文档...“ + sfileName);  
            System.out.println(“转换文档到PDF...“ + toFileName);      
            File tofile = new File(toFileName);      
            if (tofile.exists()) {      
                tofile.delete();      
            }      
            Dispatch.call(doc      
                          “SaveAs“      
                          toFileName // FileName      
                          wdFormatPDF);      
            long end = System.currentTimeMillis();      
            System.out.println(“转换完成..用时:“ + (end - start) + “ms.“);  
              
                
        } catch (Exception e) {      
            System.out.println(“========Error:文档转换失败:“ + e.getMessage());      
        } finally {  
            Dispatch.call(doc“Close“false);  
            System.out.println(“关闭文档“);  
            if (app != null)      
                app.invoke(“Quit“ new Variant[] {});      
            }  
          //如果没有这句话winword.exe进程将不会关闭  
           ComThread.Release();
           
    }


}  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4001  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\allclasses-frame.html

     文件       3441  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\allclasses-noframe.html

     文件      57300  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\activeX\ActiveXComponent.html

     文件      19767  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\activeX\ActiveXDispatchEvents.html

     文件      15373  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\activeX\ActiveXInvocationProxy.html

     文件       9438  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\activeX\class-use\ActiveXComponent.html

     文件       4379  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\activeX\class-use\ActiveXDispatchEvents.html

     文件       4390  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\activeX\class-use\ActiveXInvocationProxy.html

     文件       1060  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\activeX\package-frame.html

     文件       5292  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\activeX\package-summary.html

     文件       5661  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\activeX\package-tree.html

     文件       5362  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\activeX\package-use.html

     文件       6028  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\ComException.html

     文件       4280  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\ComFailException.html

     文件       4203  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\ComThread.html

     文件       9014  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\Currency.html

     文件       4247  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\DateUtilities.html

     文件      48586  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\Dispatch.html

     文件       6077  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\DispatchEvents.html

     文件       4302  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\DispatchIdentifier.html

     文件       4247  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\DispatchProxy.html

     文件       6037  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\EnumVariant.html

     文件       9810  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\InvocationProxy.html

     文件       4390  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\InvocationProxyAllVariants.html

     文件       8214  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\JacobException.html

     文件      14587  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\Jacobobject.html

     文件       4280  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\JacobReleaseInfo.html

     文件       4247  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\LibraryLoader.html

     文件       6012  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\MainSTA.html

     文件       4357  2015-08-05 05:01  word转pdf完美格式\jacob-1.18\docs\api\com\jacob\com\class-use\NotImplementedException.html

............此处省略79个文件信息

评论

共有 条评论