2

I am currently working on a script that will crop PDF files to my requirements and merge them into a pdf file. This should be printed directly afterwards via the default printer, but using the side printer tray and in A6 format. Therefore I want the script to open the printer properties dialog window before printing.

I am talking about this dialog window

I am grateful for any help, as I have already searched countless hours on the internet

Erdorano
  • 21
  • 2
  • Did you find a solution? I've been looking for a good way to open this dialog for months now. All i could do Is open it but it crashes often. – Core taxxe Oct 19 '21 at 09:57
  • @Coretaxxe I created a copy of my existing printer in the Windows Control center and entered my required settings there as default values (black and white DIN A6 printing via the secondary printer tray). I then worked with Ghostscript as described [here](https://stackoverflow.com/questions/27195594/python-silent-print-pdf-to-specific-printer) The printed results didn't look right at this point. I had to add a few parameters in my [python code](https://imgur.com/a/DeBD2RC) – Erdorano Oct 20 '21 at 19:41

1 Answers1

0

I finally found a solution. Hopefully, this also helps you as well/is what you were looking for.

import win32print

name="printername"

# access defaults
PRINTER_DEFAULTS = {"DesiredAccess": win32print.PRINTER_ALL_ACCESS}

# open printer to get the handle
pHandle = win32print.OpenPrinter(name,PRINTER_DEFAULTS)

# get the current properties
properties = win32print.GetPrinter(pHandle, 2)

#get the devmode
pDevModeObj = properties['pDevMode']

#open the printer properties and pass the devmode
win32print.DocumentProperties(0, pHandle, name, pDevModeObj, None, 5)

# reassign the devmode
properties['pDevMode'] = pDevModeObj

# save the printer settings
win32print.SetPrinter(pHandle,2,properties,0)

# close the printer
win32print.ClosePrinter(pHandle)
Core taxxe
  • 299
  • 2
  • 12