Printing in Duplexpage a word document

2019-04-12 15:23发布

问题:

I am trying to automate the task of printing two copies at double page of ~30 Word document (*.doc). I want to send the program converted to .exe (I plan it just for Windows computers) using py2exe. I know that I can manually check the options but I will not be able to do so on the 20 or so computer where it will be used, as well as I cannot install in this computers new software (That's why I want to convert it into .exe).

I copied this solution to print, but I can't adapt it to do what I want:

from win32com import client
import time

word = client.Dispatch("Word.Application")

filename=input("What files do you want to print?")

def printWordDocument(filename):
    """Given a name of a file prints it. TODO: Add double page."""

    word.Documents.Open(filename)
    word.ActiveDocument.PrintOut()
    time.sleep(2)
    word.ActiveDocument.Close()

    word.Quit()

I couldn't find any option to print in double pages, or at least automatically, the only option of double page of PrintOut method is ManualDuplexPrint which in the documentation says: "True to print a two-sided document on a printer without a duplex printing kit.", but I don't want to make it even easier to print all the set of documents. And make a program portable to other computers, without modifying the Word documents (I don't create them).

Any other way to do it? Or any other option to do it?

UPDATE

I am not able to code in visual-basic (yet), but if I get a template or some hints I think I will manage to make something adapted to my conditions.

回答1:

I have ended doing a macro, but this just works for my own computer and not for all the computers where should work.

Sub Test()
'
' Test Macro
' Print in double page and 2 copies
'
    ActivePrinter = "Xerox WC 24 PCL"
    Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentWithMarkup, Copies:=2, Pages:="", PageType:= _
        wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
        PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
        PrintZoomPaperHeight:=0
End Sub