PDF to EPS in MacOS

Study

Convert PDF file to EPS file in MacOS

ps2pdf -dEPScrop figure_intuition.pdf figure_intuition.eps

Python file

import os
import subprocess

# Define the directory containing the PDF files
input_directory = "results/figures"

# Loop through all files in the directory
for filename in os.listdir(input_directory):
    if filename.endswith(".pdf"):  # Only process PDF files
        pdf_path = os.path.join(input_directory, filename)
        eps_path = os.path.splitext(pdf_path)[0] + ".eps"
        
        # Run the ps2pdf command to convert the PDF to EPS
        try:
            subprocess.run(["ps2pdf", "-dEPScrop", pdf_path, eps_path], check=True)
            print(f"Converted {filename} to {os.path.basename(eps_path)}")
        except subprocess.CalledProcessError as e:
            print(f"Error converting {filename}: {e}")

print("Conversion complete.")