问题
i am trying to print pdf file with custom page size in python with win32print i can change other setting like number of copies but setting custom page length and width is not working it always try to fit pdf content into page by covering whole page this is my code
printers=win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL)
PRINTER_DEFAULTS = {"DesiredAccess":win32print.PRINTER_ALL_ACCESS}
temprint=printers[1][2]
handle = win32print.OpenPrinter(temprint, PRINTER_DEFAULTS)
level = 2
attributes = win32print.GetPrinter(handle, level)
attributes['pDevMode'].PaperWidth = 600
attributes['pDevMode'].PaperLength = 30
attributes['pDevMode'].PaperSize =0
print(win32print.SetPrinter(handle, level, attributes, 0))
win32api.ShellExecute(0,'printto','test.pdf','"%s"' % temprint,'.',0)
win32print.ClosePrinter(handle)
can anyone tell me what i am doing wrong here
回答1:
I am not sure if this also applies in this case. But from the class documentation, I remember that the values for the mentioned attributes were assigned as (Tenths of a millimeter)
.
Your values here don't correspond to that
attributes['pDevMode'].PaperWidth = 600
attributes['pDevMode'].PaperLength = 30
attributes['pDevMode'].PaperSize =0
来源:https://stackoverflow.com/questions/62610277/python-win32print-cant-set-custom-page-size