Last active
February 13, 2020 11:40
-
-
Save delucis/ca8b1ac260e00cd869ddecea996f9cc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check all required CLIs are available | |
dependencies=( pdftoppm convert ) | |
for dependency in "${dependencies[@]}"; do | |
command -v $dependency >/dev/null 2>&1 || { echo >&2 "‘$dependency’ command is required but it’s not installed. Aborting."; exit 1; } | |
done | |
# Create a directory to hold extracted images | |
if [ ! -d "images" ]; then | |
mkdir images | |
else | |
rm -R images/* | |
fi | |
# Make sure there’s an argument provided | |
if [ -z "$1" ]; then | |
echo "Error: no filename supplied." | |
exit 1 | |
fi | |
SOURCEPDF=$1 | |
FILENAME=$(echo "$SOURCEPDF" | cut -f 1 -d '.') | |
echo "Converting PDF pages to images..." | |
pdftoppm -png "$SOURCEPDF" images/out | |
echo "Converting images to PDF..." | |
cd images || exit 1 | |
convert $( ls ) "../$FILENAME -PROOF IMAGE - DO NOT PRINT.pdf" | |
cd ../ || exit 1 | |
# Tidy up, removing generated images | |
rm -R images |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Homebrew-installable version available here: https://github.com/delucis/pdf2imgpdf