2

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
llrs
  • 3,308
  • 35
  • 68
  • what is wrong with `ManualDuplexPrint`? you could try to use `Dialog object` ([Dialog.Show method](http://msdn.microsoft.com/en-us/library/office/ff197832%28v=office.15%29.aspx) and [its parameters](http://msdn.microsoft.com/en-us/library/office/ff836540%28v=office.15%29.aspx)) – Kazimierz Jawor Mar 23 '14 at 17:06
  • 1
    I also added `word-vba` tag to widen the audience of your question as problem relates to MS Word and VBA as well. – Kazimierz Jawor Mar 23 '14 at 17:08
  • Nothing is wrong, but the printer is able to print at double page. And I would like to avoid as much as possible human interaction. I need to print up to 30 documents, and if someone must be there to change the side of the page... he would get tired at least. Thanks for the tag, I didn't think about it. The links seem useful I found a `DuplexPrint` option, I will try it. – llrs Mar 24 '14 at 09:31
  • @KazJaw now I realized that this is visual basic, I wanted to do it in python because is the language I know but if you could develop a little your answer I would mark it as correct. But I am not sure if this way I will be able to print 30 documents without adding the macro to the computer, (if I need to create a macro) ... – llrs Mar 24 '14 at 19:02
  • please, add your own answer, I would need to make some test & trial to get most appropriate & correct syntax but I believe you already have it ready to copy and paste here. – Kazimierz Jawor Mar 25 '14 at 05:33
  • If I were you, I would focus on GSPrint (http://pages.cs.wisc.edu/~ghost/gsview/gsprint.htm). It's an external tool of python but you can always call it from python and pass arguments. http://stackoverflow.com/questions/1462842/print-pdf-document-with-pythons-win32print-module – ederollora Mar 26 '14 at 20:06
  • @Llopis Why not check the `Duplex Print` in printer properties? All duplex printers have this option in dialog box. Or I misunderstood the problem? – Pylyp Mar 26 '14 at 20:25
  • @ederollora This seems good, but I want to distribute the program over a 12 or more computers with windows, and I don't want to install many things. I planned to create in python and then use the [python2exe](http://www.py2exe.org/index.cgi/FrontPage) to distribute just the standalone .exe program. Pylyp: Yes, they have, but how do I check from a python script? And if I am able to do so, how do I order from python to print in `Duplex Print`? – llrs Mar 26 '14 at 21:13
  • 1
    According to Microsoft (not manual) duplex printing is not possible with the PrintOut method: http://support.microsoft.com/kb/828638 They suggest as a workaround to change the printer setttings via Win32 API SetPrinter. I tried that workaround, didn't work with my printer. YMMV. I also tried WMI. Can't work, WMI only allows reading the duplex printer setting. – Matthias Mar 28 '14 at 17:17
  • Try using a programming language called AutoIt if you're going to be doing a lot of this kind of work. – alvonellos Mar 28 '14 at 23:29
  • Please check the following link, http://blogs.msdn.com/b/vsod/archive/2012/05/19/how-to-set-duplex-printing-for-microsoft-word-automation-clients-in-c-vb-net.aspx There is a sample project attached. – Kaushal Mar 30 '14 at 04:08
  • Great information Matthias and Kausal combining both and my macro I hope to achieve it. Thanks alvonellos for the tip, but (fortunately) I will not do this kind of work often (I hope). – llrs Mar 30 '14 at 08:12

1 Answers1

0

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
llrs
  • 3,308
  • 35
  • 68