使用 Acrobat Reader 在后台使用 Python 打开和保存 PDF 文件

Open and save a PDF file using Acrobat Reader in the background using Python

紧随 Opening pdf file question

我正在寻找一种方法来同时命令 Adob​​e Acrobat Reader 使用 Python.

以编程方式保存文件

我不是在寻找 pikepdf 保存文件的方式。

原因This PDF file, created with fill-pdf,需要在打开时通过 Acrobat Reader 进行特殊格式化。退出 Acrobat 时 Reader 询问是否保存它所做的格式,我需要这个“是的,保存”通过代码。

编辑:如何从这里开始使用 pywinauto?

import time
from pywinauto.application import Application

pdf_file = r'C:\Path\To\Total.pdf'
acrobat_path = r"C:\Path\To\Acrobat.exe"

app = Application(backend=u'uia').start(cmd_line = acrobat_path + ' ' + pdf_file)
print("started")
time.sleep(1)
app = Application(backend=u'uia').connect(path=acrobat_path)
print("connected")

用pyautogui解决:

import os
os.startfile(path)
filename = os.path.basename(path)
focus = pg.getWindowsWithTitle(filename)
while len(focus) == 0:
    focus = pg.getWindowsWithTitle(filename)
focus [0].show() # show() for python3.9, activate() for python3.7
time.sleep(1)
pg.hotkey('ctrl', 's')
time.sleep(1)
pg.hotkey('ctrl', 'q')
print("Blessed Be God")