jacob-project icon indicating copy to clipboard operation
jacob-project copied to clipboard

Ask for help, print .docx file to physical printer by jacob (JAVA-COM Bridge) as Monochrome printing

Open yeminv opened this issue 1 year ago • 1 comments

I want to print .docx file to a physical printer by jacob. And it's work as below.

       <dependency>
            <groupId>com.jacob</groupId>
            <artifactId>jacob</artifactId>
            <version>1.20</version>
        </dependency>
public class JacobPrint {
    static void print( String filePath){// filePath="D:\\1.doc";
        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", filePath).toDispatch();

        try {
            Dispatch.call(doc, "PrintOut");
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                if(doc!=null){
                    Dispatch.call(doc, "Close",new Variant(0));
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            ComThread.Release();
        }
}

But it is color printing. How do I control it to print in color or monochrome?

I have reference to Microsoft's official documentation: Printer.ColorMode property (Access)

But it seems to only work in the Access app, not in Word.

Thanks a lot!

yeminv avatar Dec 21 '23 09:12 yeminv

This isn't a Jacob issue. Jacob will execute whatever calls you need to make. It's a question about the Microsoft COM API for Word.

EJP286CRSKW avatar Dec 25 '23 06:12 EJP286CRSKW