I have a Windows 11 laptop and an Epson WF-4820 printer.
Is there any way I can programmatically print two files, one on each side of the same sheet of paper?
The following program doesn't quite work (Python 3.13.3):


import win32api
import win32print

printdefaults = {"DesiredAccess": win32print.PRINTER_ACCESS_USE}
handle = win32print.OpenPrinter( win32print.GetDefaultPrinter(), printdefaults )

level = 2
attributes = win32print.GetPrinter(handle, level)
print("Old Duplex = %d" % attributes['pDevMode'].Duplex)
attributes['pDevMode'].Duplex = 2    # flip over long edge
try:
    win32print.SetPrinter(handle, level, attributes, 0)
except Exception as e:
    print(f"win32print.SetPrinter: set 'Duplex' but got Exception {e}")
    # Gets 'Access is denied' Exception but does change the setting.
    for filePath in ('R:\\DSPR\\ShortDocument1.txt', 'R:\\DSPR\\ShortDocument2.txt'): # Absolute paths are necessary AFAIK
        win32api.ShellExecute(0, 'print', filePath, None, '.', 0)
win32print.ClosePrinter(handle)


What happens:
It prints the first file on one side of a sheet, then sucks the sheet back in and prints nothing on the other side.
(Nothing, because the document is short and fits on one side).
Then ejects the paper.
Then does the same thing with the other file.
In other words each file is printed (separately) in duplex mode,
but they are not printed on the same sheet.

If what I want is possible (from my research so far I'm  getting the impression that it isn't) can I do the same thing with image files (print two on opposite sides of the same sheet) ?
TIA
Rob Cliffe
--
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to