在 ShellExecute 中,如何指定页面范围、托盘等打印参数? [英] In ShellExecute, how to specify print parameters like page range, tray etc?
问题描述
这是我使用 Python 在 Windows 机器上打印 pdf 文件的代码.我安装了 adobe Acrobat Reader 以帮助打印.
win32api.ShellExecute(0,"print",file_path,"NPIAC1EC3 (HP LaserJet Pro MFP M226dw)",".",3)
如何添加其他选项以提及诸如打印机托盘/页面来源、页面范围等内容?
我已阅读有关 ShellExecute.
我在文档中看到有一个 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);
参数
...
lpOperation [输入,可选]
类型:LPCTSTR
指向以空字符结尾的字符串的指针,在这种情况下称为动词,...以下动词是常用的:
...打印
打印 lpFile 指定的文件.如果 lpFile 不是文档文件,则函数失败.
所以当你使用 "print"
作为动词时 lpFile
应该是一个文档文件
...
lpParameters [输入,可选]
类型:LPCTSTR
如果 lpFile 指定一个可执行文件,则此参数是一个指向以空字符结尾的字符串的指针,该字符串指定要传递给应用程序的参数.此字符串的格式由要调用的动词决定.如果 lpFile 指定了一个文档文件,lpParameters 应该是 NULL.
所以当你使用print
作为动词时,lpFile
必须是一个文档文件,并且lpParameters
必须为空:没有规定将附加参数传递给 ShellExecute
打印操作.
This is the code I'm using to print a pdf file on a Windows machine using Python. I've adobe Acrobat Reader installed to aid in printing.
win32api.ShellExecute(0,"print",file_path,"NPIAC1EC3 (HP LaserJet Pro MFP M226dw)",".",3)
How can I add additional options to mention things like Printer Tray/Page Source, page range etc?
I've read the documentation on ShellExecute from MSDN .
I've seen in the documentation that there is a lpParameters (I'm totally guessing that this is where I specify printing parameters) but no explanations on how to use it with "print" parameter.
The linked documentation states what what you want is not possible. Commented extracts (emphasize mine):
Syntax:
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.
So when you use "print"
as a verb lpFile
shall be a document file
...
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.
So when you use print
as the verb, lpFile
must be a document file, and lpParameters
must be null: there is no provision to pass additional parameters to a ShellExecute
print action.
这篇关于在 ShellExecute 中,如何指定页面范围、托盘等打印参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!