python win32print can't set custom page size

旧时模样 提交于 2021-01-29 08:42:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!