SAP GUI 脚本 - 在 pywin32 中从打印屏幕创建 PDF

SAP GUI Scripting - Create PDF from print screen in pywin32

我正在尝试编写查看自定义报告的 SAP 流程的脚本。该报告可以是 "printed",然后另存为 pdf。但是,一旦您将 "LOCL" 指定为输出设备并指定 select 复选框,它将转到未包含在 gui 脚本输出中的打印屏幕。

有谁知道如何在 vba 或 python 中编写脚本以继续?我附上了弹出的打印对话框的屏幕截图,我不知道如何在 vba 或 python 中工作。然后出现的第二个对话框要求文件路径和文件名。

pywin32 应该可以,但我想不通。

使用 pywinauto 应该容易得多:pip install pywinauto。代码应如下所示:

from pywinauto import Application

# handle Print dialog
app = Application(backend="win32").connect(title="Print") # timeout (in sec.) is optional
app.PrintDialog.OK.click() # or .click_input() for real click
app.PrintDialog.wait_not("visible") # to make sure it is closed

# handle Save dialog
app = Application(backend="win32").connect(title="Save Print Output As") # maybe not needed if it is the same process
app["Save Print Output As"].FileNameEdit.set_text(file_path) # or .type_keys(file_path, with_spaces=True)
app["Save Print Output As"].SaveButton.click() # or .click_input()
app["Save Print Output As"].wait_not("visible")