script to explode a pdf into jpgs for individual page editing

 script to explode a pdf into jpgs for individual page editing

#!/bin/bash
sanitize_filename() {
    echo "$1" | sed 's/[^a-zA-Z0-9._-]/_/g'
}
if [ $# -ne 1 ]; then
    echo "Usage: $0 <pdf-file>"
    exit 1
fi
input_file="$1"
if [ ! -f "$input_file" ]; then
    echo "Error: file not found: $input_file"
    exit 1
fi
base_filename=$(basename "$input_file" .pdf)
sanitized_filename=$(sanitize_filename "$base_filename")
output_dir="exploded_$sanitized_filename"
mkdir -p "$output_dir"
echo "Input file: $input_file"
echo "Output folder: $output_dir"
pdftoppm -jpeg "$input_file" "$output_dir/${sanitized_filename}_page"
if [ $? -ne 0 ]; then
    echo "Error during PDF to JPEG conversion."
    exit 1
fi
i=1
for img in "$output_dir"/"${sanitized_filename}_page"-*.jpg; do
    [ -f "$img" ] || continue
    mv "$img" "$output_dir/${sanitized_filename}_page$i.jpg"
    i=$((i+1))
done
echo "Done."

Popular posts from this blog

Automatically Fix Song Metadata and Filenames on Linux with Beets

DropboxMount turns your Dropbox into a live, on-demand drive instead of a sync folder.

script to create an EFI partition on a target bootdrive if none exists