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