python win32print无法设置自定义页面大小 [英] python win32print can't set custom page size
问题描述
我正在尝试使用 win32print 在 python 中打印具有自定义页面大小的 pdf 文件我可以更改其他设置,例如份数但是设置自定义页面长度和宽度不起作用它总是尝试通过覆盖整个页面来将 pdf 内容放入页面这是我的代码
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
推荐答案
我不确定这是否也适用于这种情况.但是从 documentation 类中,我记得上述属性的值被指定为 (十分之一毫米)
.
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)
.
您在此处的值与此不符
attributes['pDevMode'].PaperWidth = 600
attributes['pDevMode'].PaperLength = 30
attributes['pDevMode'].PaperSize =0
这篇关于python win32print无法设置自定义页面大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!