pythonをつかってアクロバットでPDFを開いて、保存するスクリプト

pythonのスクリプト内からアクロバットを使ってPDFを開き、再保存する方法

give me a python code that automatically open pdf files in acrobat then save again in acrobat.

https://chat.openai.com/

Certainly! Here’s a Python code snippet that uses the subprocess module to open PDF files in Adobe Acrobat and save them again:

import subprocess

def open_pdf_and_save(filepath):
# Specify the path to your Adobe Acrobat executable
acrobat_path = r’C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe’

# Open the PDF file in Adobe Acrobat
subprocess.Popen([acrobat_path, filepath])

# Wait for Adobe Acrobat to open
input(“Press Enter after saving the PDF in Adobe Acrobat:”)

# Close Adobe Acrobat
subprocess.call([‘taskkill’, ‘/F’, ‘/IM’, ‘Acrobat.exe’])

# Usage example
pdf_filepath = r’C:\path\to\your\pdf\file.pdf’
open_pdf_and_save(pdf_filepath)

In this code, you need to provide the path to your Adobe Acrobat executable in the acrobat_path variable. Update the pdf_filepath variable with the path to your PDF file.

When you run the code, it will open the specified PDF file in Adobe Acrobat. After making any desired changes and saving the file in Adobe Acrobat, press Enter in the terminal to continue the Python script. The script will then close Adobe Acrobat.

Note: Make sure to replace C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe with the actual path to your Adobe Acrobat executable. The path may vary depending on the version and installation location of Adobe Acrobat on your system.

アドビアクロバットの場所の見つけ方

How can tell the path to my Adobe Acrobat executable in the acrobat_path variable in python language?

To find the path to your Adobe Acrobat executable programmatically in Python, you can utilize the winreg module to access the Windows registry. Here’s an example code snippet that retrieves the path to Adobe Acrobat:

import winreg

def get_acrobat_path():
acrobat_key_path = r”SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe”

try:
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, acrobat_key_path) as key:
acrobat_path = winreg.QueryValue(key, None)
return acrobat_path
except FileNotFoundError:
return None

# Usage example
acrobat_path = get_acrobat_path()
if acrobat_path:
print(“Adobe Acrobat path:”, acrobat_path)
else:
print(“Adobe Acrobat is not installed or path not found.”)

This code uses the winreg.OpenKey() function to open the registry key for Adobe Acrobat (SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe). If the key is found, it retrieves the default value, which represents the path to the Adobe Acrobat executable.

The get_acrobat_path() function returns the Adobe Acrobat path if found, or None if Adobe Acrobat is not installed or the path is not found.

You can then assign the returned acrobat_path to the acrobat_path variable in your code snippet.

 

フォルダ内の全てのPDFファイルに同様の処理をする方法

give me a python code that use adobe acrobat to open PDF fiels in a folder and resave each.

Certainly! Here’s a Python code snippet that uses Adobe Acrobat to open PDF files in a folder and resave each file:

import os
import subprocess

def open_pdf_and_resave(pdf_filepath):
# Specify the path to your Adobe Acrobat executable
acrobat_path = r’C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe’

# Open the PDF file in Adobe Acrobat
subprocess.Popen([acrobat_path, pdf_filepath])

# Wait for Adobe Acrobat to open
input(“Press Enter after resaving the PDF in Adobe Acrobat:”)

# Close Adobe Acrobat
subprocess.call([‘taskkill’, ‘/F’, ‘/IM’, ‘Acrobat.exe’])

def open_and_resave_pdfs_in_folder(folder_path):
# Get all PDF files in the folder
pdf_files = [file for file in os.listdir(folder_path) if file.endswith(‘.pdf’)]

# Iterate over each PDF file and open/resave it in Adobe Acrobat
for pdf_file in pdf_files:
pdf_filepath = os.path.join(folder_path, pdf_file)
open_pdf_and_resave(pdf_filepath)

# Usage example
folder_path = r’C:\path\to\your\folder\containing\pdfs’
open_and_resave_pdfs_in_folder(folder_path)

In this code, you need to provide the path to your Adobe Acrobat executable in the acrobat_path variable. Update the folder_path variable with the path to the folder containing the PDF files you want to open and resave.

When you run the code, it will iterate over each PDF file in the specified folder. It will open each file in Adobe Acrobat, allowing you to make any desired changes or modifications. After resaving the PDF file in Adobe Acrobat, press Enter in the terminal to continue the Python script. The script will then close Adobe Acrobat and proceed to the next PDF file in the folder.

Note: Make sure to replace C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe with the actual path to your Adobe Acrobat executable. The path may vary depending on the version and installation location of Adobe Acrobat on your system.

再保存まで自動でやる方法

give me a python code that use adobe acrobat to open PDF fiels in a folder and resave each also automatically in python without any human hands.

import os
import subprocess
import time
import pyautogui

def open_pdf_and_resave(pdf_filepath):
# Specify the path to your Adobe Acrobat executable
acrobat_path = r’C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe’

# Open the PDF file in Adobe Acrobat
subprocess.Popen([acrobat_path, pdf_filepath])

# Wait for Adobe Acrobat to open
time.sleep(5) # Adjust the sleep duration as needed

# Use PyAutoGUI to automate the resave process
pyautogui.hotkey(‘ctrl’, ‘shift’, ‘s’)
time.sleep(1)
pyautogui.press(‘enter’)

# Wait for the resave to complete
time.sleep(2)

# Close Adobe Acrobat
pyautogui.hotkey(‘ctrl’, ‘w’)

def open_and_resave_pdfs_in_folder(folder_path):
# Get all PDF files in the folder
pdf_files = [file for file in os.listdir(folder_path) if file.endswith(‘.pdf’)]

# Iterate over each PDF file and open/resave it in Adobe Acrobat
for pdf_file in pdf_files:
pdf_filepath = os.path.join(folder_path, pdf_file)
open_pdf_and_resave(pdf_filepath)

# Usage example
folder_path = r’C:\path\to\your\folder\containing\pdfs’
open_and_resave_pdfs_in_folder(folder_path)

In this code, you need to provide the path to your Adobe Acrobat executable in the acrobat_path variable. Update the folder_path variable with the path to the folder containing the PDF files you want to open and resave.

When you run the code, it will iterate over each PDF file in the specified folder. It will open each file in Adobe Acrobat using the subprocess module and then use PyAutoGUI to automate the resave process. The code simulates the keyboard shortcuts (Ctrl+Shift+S to save, Enter to confirm, and Ctrl+W to close) using the pyautogui library. Adjust the time.sleep() durations as needed to ensure proper timing for each action.

Please note that GUI automation can be sensitive to screen resolutions, window positions, and other factors. Make sure that your screen is set up appropriately and that Adobe Acrobat is visible and in focus when running the code. Additionally, exercise caution when automating GUI interactions and ensure that you have appropriate permissions for the files and applications involved.