#!/bin/bash

# Directory containing the PDFs
input_dir="../"  # Replace with the desired folder if needed

# Loop through all PDF files in the directory
for pdf_file in "$input_dir"*.pdf; do
    # Check if there are any PDF files
    if [[ ! -e "$pdf_file" ]]; then
        echo "No PDF files found in the directory."
        exit 1
    fi

    # Extract the base filename without extension
    base_name=$(basename "$pdf_file" .pdf)

    # Use pdfseparate to split the PDF into pages
    pdfseparate "$pdf_file" "${base_name}-%d.pdf"
done

echo "PDF splitting complete!"
