这是我使用 Python 在 Windows 机器上打印 pdf 文件的代码。我安装了 adobe Acrobat Reader 以帮助打印。
win32api.ShellExecute(0,"print",file_path,"NPIAC1EC3 (HP LaserJet Pro MFP M226dw)",".",3)
如何添加其他选项来提及诸如打印机托盘/页面源、页面范围等内容?
我已阅读有关 ShellExecute 的文档来自 MSDN。
我在文档中看到有一个lpParameters(我完全猜测这是我指定打印参数的地方)但没有解释如何将它与“打印”参数一起使用.
最佳答案
链接的文档说明你想要什么是不可能的。注释摘录(强调我的):
语法:
HINSTANCE ShellExecute( _In_opt_ HWND hwnd, _In_opt_ LPCTSTR lpOperation, _In_ LPCTSTR lpFile, _In_opt_ LPCTSTR lpParameters, _In_opt_ LPCTSTR lpDirectory, _In_ INT nShowCmd );
Parameters
...
lpOperation [in, optional]
Type: LPCTSTR
A pointer to a null-terminated string, referred to in this case as a verb, ... The following verbs are commonly used:
...Prints the file specified by lpFile. If lpFile is not a document file, the function fails.
因此,当您将“print”
用作动词时,lpFile
应为文档文件
...
lpParameters [in, optional]
Type: LPCTSTR
If lpFile specifies an executable file, this parameter is a pointer to a null-terminated string that specifies the parameters to be passed to the application. The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be NULL.
所以当你使用print
作为动词时,lpFile
必须是文档文件,lpParameters
必须为null:没有规定将附加参数传递给 ShellExecute
打印操作。
关于python - 在 ShellExecute 中,如何指定页面范围、托盘等打印参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50365451/