-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai.sh
More file actions
executable file
·32 lines (22 loc) · 804 Bytes
/
ai.sh
File metadata and controls
executable file
·32 lines (22 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# after done: execute
# chmod +x ai.sh
# ./ai.sh
for pdf_file in ./*.pdf; do
# Extract the base name of the PDF (without the directory and extension)
base_name=$(basename "$pdf_file" .pdf)
output_folder="./book-$base_name"
mkdir -p "$output_folder" # Create a folder using the PDF file name
echo "Processing $pdf_file into $output_folder ..."
# Convert PDF to images
pdftocairo "$pdf_file" "$output_folder/page" -jpeg -cropbox # Adjust to -jpeg, -png, etc. as needed
# Change to the output folder
cd "$output_folder" || exit
# Rename files
for f in page-*.jpg; do
mv "$f" "$(echo $f | sed -E 's/page-0+([0-9]+)\.jpg$/page-\1.jpg/')"
done
echo "Renamed files in $output_folder"
# Go back to the original directory
cd - > /dev/null
done