ShellExecute(0,'print',txtfile,'/d:"%s"' % myprinter,'.',0) # 指定打印机打印 win32api.ShellExecute ( 0, "printto", txtfile, '"%s"' % f'{myprinter}', ".", 0 ) 注意win32api是pywin32的一个模块,需要安装pywin32库
发送文件:使用win32api.ShellExecute函数将文件发送到打印机。printto命令允许我们指定打印机。 关系图 我们可以使用Mermaid语法绘制关系图,展示打印文件的流程与相关组件: PRINT_JOBstringfile_pathstringprinter_namestringstatusFILEPRINTERsendsuses 关系图说明 在这个关系图中,PRINT_JOB表示打印任务,它包含file_path(文件...
importwin32printimportwin32uifromPILimportImagedefprint_file(printer_name,file_path):# 获取打印机句柄hprinter=win32print.OpenPrinter(printer_name)# 创建打印任务hdc=win32ui.CreateDC("WINSPOOL",printer_name,None)hdc.StartDoc(file_path)hdc.StartPage()# 打开要打印的文件img=Image.open(file_path)# ...
首先,需要使用pywin32模块初始化打印机,准备好打印任务。 import win32print import win32api 获取默认打印机 printer_name = win32print.GetDefaultPrinter() 发送PDF打印任务 接下来,可以设置打印任务的参数,并发送要打印的PDF文件到打印队列。 filename = "C:\\path\\to\\your\\file.pdf" win32api.ShellExec...
我使用的方法是使用命令 os.startfile('PDFfile.pdf', "print") 但它打开默认查看器(我的是 Adobe Reader)并且在打印后它仍然打开,试图用 os.system("TASKKILL /F /IM AcroRD32.exe") 杀死进程其他打开的窗口,我不想要它。 使用下一个命令,它也会打印,但它也让 Adobe Reader 打开 currentprinter = win32...
from tkinter import * from tkinter import messagebox from tkinter import filedialog def print_to_printer(): try: # 创建打印对话框 root = Tk() root.withdraw() filename = filedialog.askopenfilename() if filename: # 打印文件 root.attributes('-topmost', True) root.update() root.attributes('...
https://www.analyticsvidhya.com/blog/2020/08/how-to-extract-tabular-data-from-pdf-document-using...
printer(filename) 这里的打印机用的是共享打印机,所以需要指定域名和打印机名称,而且"/D:"表示的是打印设备的意思。 2、windows下如何用python控制打印机打印 参考网站 首先下载python需要的库 pipinstallpypiwin32 简单例子 import tempfile importwin32apiimportwin32printfilename = tempfile.mktemp (".txt") ...
open(filename,"w").write ("This is a test") win32api.ShellExecute ( 0, "print", filename, # # If this is None, the default printer will # be used anyway. # '/d:"%s"'%win32print.GetDefaultPrinter (), ".", 0 ) 另一个版本 ...
在Python中,你可以使用第三方库win32print来调用打印机打印文档。以下是一个简单的示例代码: import win32print import win32api # 获取默认打印机 printer_name = win32print.GetDefaultPrinter() # 打开打印机 printer = win32print.OpenPrinter(printer_name) # 打印文件 file_path = "path/to/your/document....