如何在python中打印pdf文件而不打开pdf查看器打印提示



我想用Python打印一个PDF文件,而不打开任何PDF查看器程序(例如adobe(。

我尝试了一些代码。它在打印之前弹出adobe程序。

第一代码

import win32print
import win32api
currentprinter = win32print.GetDefaultPrinter()
win32api.ShellExecute(0, "print", 'report.pdf', currentprinter,  ".",  0)

第二代码

import os
os.startfile("report.pdf", "print")

有什么代码我必须重写,或者有什么推荐程序可以代替adobe使用?

  1. 下载PDFtoPrinter.exe并将其移动到文件夹中。

  2. 编码。

    import subprocess
    def command_print(event = None):
    command = "{} {}".format('PDFtoPrinter.exe','report.pdf')
    subprocess.call(command,shell=True)
    command_print()
    

最新更新