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

Time:03-22

Following the Opening pdf file question

I am looking for a way to also command Adobe Acrobat Reader to save the file programmatically using Python.

I am not looking for the pikepdf way of saving the file.

Reason: This PDF file, created with fill-pdf, needs to go through special formatting done by Acrobat Reader upon opening. Upon exit Acrobat Reader asks whether to save the formatting it did, I need this "Yes, Save" to be via code.

Edit: How to proceed from here using 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")

CodePudding user response:

solution with pyautogui:

import os
file_name = "Total"
os.startfile(pdf_file)
time.sleep(3)
pg.getWindowsWithTitle(file_name)[0].show()
time.sleep(1)
pg.hotkey('ctrl', 's')
time.sleep(1)
pg.hotkey('ctrl', 'q')
print("Blessed Be God")
  • Related