当前位置:网站首页>Jacob print word

Jacob print word

2022-04-23 14:03:00 one billion twenty-nine million one hundred and seventy-nine th

One 、 Preface
utilize jacob Print word, The first thing you need to jacob.jar and jacob.dll Two tools , Are all low-level tools , Just use it . Print word It actually involves a series of word The operation of , For example, replace text , Or into pdf wait , I suggest taking advantage of poi operation word better , Simple , convenient .
Two 、 Download tool
WeChat official account search : The small white XBIT
Reply key :jacob You can get the above two tools
3、 ... and 、 Tool use
1:jacob.jar
(1) Put it in the installation jdk Of bin Directory and jre Under the directory of , At the same time, it should be placed in web-inf Of lib Next, and then build Just a second .
(2) Put it in the installation jdk Of bin Directory and jre Under the directory of , Directly on tomcat Of lib The directory can also ( This is recommended ), The first usually causes loading conflicts .
2:jacob.dll
take jacob.all Put it in C:\Windows\System32 that will do . Pay attention to put the number of corresponding digits according to the number of digits of the computer dll,32 and 64 I have provided download .
Four 、 Print code

/*
	 *  Print the document under the specified path 
	 */
	public String print(String path) {
        ComThread.InitSTA();  
        ActiveXComponent word=new ActiveXComponent("Word.Application");  
        Dispatch doc=null;  
        Dispatch.put(word, "Visible", new Variant(false));  
        Dispatch docs=word.getProperty("Documents").toDispatch();  
        doc=Dispatch.call(docs, "Open", path).toDispatch();     
        try {  
            Dispatch.call(doc, "PrintOut");// Print   
            return "succ";
        } catch (Exception e) {  
            e.printStackTrace();  
            return "fail";
        }finally{  
            try {  
                if(doc!=null){  
                    Dispatch.call(doc, "Close",new Variant(0));  
                }  
            } catch (Exception e2) {  
                e2.printStackTrace();  
            }  
            // Release resources   
            ComThread.Release();  
        }  
	}

版权声明
本文为[one billion twenty-nine million one hundred and seventy-nine th]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401298386.html