Java Jacob calls printer to print Word document

Source: Internet
Author: User

It says how Java generates complex Word documents this year, documenting how Java calls printers to print Word documents.

The original use of the PrintJob, but the system provides a printing mechanism than immature complete. The code on the Web is also a cookie-cutter, on my print device Canon ir2525/2530 Ufrii LT, I can get to the printer's various properties, the current number of tasks. But the printer didn't respond.

Refer to these two articles:


Toss for a long time, the final decision by using a third party, found Jacob, also good, hereby recorded.

1. Copy Jacob's DLL file to C:\Windows\System32.

2. Open service DCOM Server Process Launcher (dcomlaunch) in Task Manager.

3. Copy the Jacob.jar to the project's/libs directory.

Note that I cannot find the DLL file on Windows Server 2008, Error: Exception in thread "main" Java.lang.UnsatisfiedLinkError:no jacob-1.17-x86 In Java.library.path

But on the win system, it's okay.

The code is as follows:

 Public classTestdoc { Public Static voidMain (string[] args) {String path= "D:\\yanqiong.doc"; System.out.println ("Start Printing");        Comthread.initsta (); Activexcomponent Word=NewActivexcomponent ("Word.Application"); Dispatch Doc=NULL; Dispatch.put (Word,"Visible",NewVariant (false)); Dispatch Docs=word.getproperty ("Documents"). Todispatch (); (Docs, "Open", Path). Todispatch (); Try{ (doc,"PrintOut");//Print}Catch(Exception e) {e.printstacktrace (); System.out.println ("Print Failed"); }finally{            Try {                if(doc!=NULL) { (doc,"Close",NewVariant (0)); }            } Catch(Exception E2) {e2.printstacktrace (); }            //Freeing Resourcescomthread.release (); }    }}

Example code:

Http:// up56

Java Jacob calls printer to print Word document

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.