Generalize PDF-to-JPEG conversion script
feat: accept PDF filename as input argument - Allow PDF file to be specified on the command line - Derive output JPEG name from input PDF basename - Generate files using IMG_<pdf-name>.jpg naming convention - Retain first-page conversion behavior - Improve script reusability for multiple PDFs
This commit is contained in:
1 parent
d0b6444332
commit
a209038263
2 files changed
+28
-1
No files matched your search
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Convert the first page of a PDF to a JPEG image.
|
||||
# Usage: ./pdf_to_jpg.sh <file.pdf>
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -ne 1 ]]; then
|
||||
echo "Usage: $0 <file.pdf>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INPUT_PDF="$1"
|
||||
|
||||
if [[ ! -f "$INPUT_PDF" ]]; then
|
||||
echo "Error: '$INPUT_PDF' not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove .pdf extension and prepend IMG_
|
||||
BASE_NAME="$(basename "$INPUT_PDF" .pdf)"
|
||||
OUTPUT_JPG="IMG_${BASE_NAME}.jpg"
|
||||
|
||||
echo "Converting first page of '$INPUT_PDF' to '$OUTPUT_JPG'..."
|
||||
|
||||
pdftoppm -f 1 -l 1 "$INPUT_PDF" | pnmtojpeg > "$OUTPUT_JPG"
|
||||
|
||||
echo "Done: $OUTPUT_JPG created."
|
||||
Reference in new issue
Block a user