Sebastian Lenzlinger b95d071caa New aliases
2024-05-08 15:06:26 +02:00

38 lines
783 B
Bash
Executable File

#!/usr/bin/env bash
# Check if qpdf is installed
if ! command -v qpdf &> /dev/null; then
echo "Error: qpdf could not be found. Please install qpdf."
exit 1
fi
# Target PDF filename
output_pdf="$1.pdf"
if [[ -z "$1" ]]; then
echo "Usage: $0 <output-file-base-name>"
exit 1
fi
# Prepare an array to hold the PDF files
pdf_files=()
shopt -s nullglob
for file in *.pdf; do
pdf_files+=("$file")
done
# Check if we found any PDF files
if [[ ${#pdf_files[@]} -eq 0 ]]; then
echo "No PDF files found in the current directory."
exit 1
fi
# Sort files just in case
IFS=$'\n' pdf_files=($(sort <<<"${pdf_files[*]}"))
unset IFS
# Run qpdf to combine PDF files
qpdf --empty --pages "${pdf_files[@]}" -- "$output_pdf"
echo "PDF files combined into $output_pdf"