Skip to content

Instantly share code, notes, and snippets.

@josephbolus
Created July 4, 2024 19:49
Show Gist options
  • Save josephbolus/ba9d506873c0848723b79f00ea05fd8e to your computer and use it in GitHub Desktop.
Save josephbolus/ba9d506873c0848723b79f00ea05fd8e to your computer and use it in GitHub Desktop.
Use the following tiny script to make PDFs look like they have been scanned.
#!/bin/sh
# Help message
show_help() {
echo
echo "Convert PDFs to make them look like they have been scanned"
echo "Example: $0 file.pdf"
}
# Check if the provided argument is not empty
if [ -z "$1" ]; then
echo "Error: Argument cannot be empty."
show_help
exit 1
fi
# Assign argument to variable
ORIGINAL_PDF=$1
# Generate the scanned PDF filename by appending '_scanned' to the original filename
SCANNED_PDF="${ORIGINAL_PDF%.pdf}_scanned.pdf"
# Random rotation value
ROTATION=$(shuf -n 1 -e '-' '')$(shuf -n 1 -e $(seq 0.05 .5))
# Convert the PDF
convert -density 150 "$ORIGINAL_PDF" \
-linear-stretch '1.5%x2%' \
-rotate "${ROTATION}" \
-attenuate '0.01' \
+noise Multiplicative \
-colorspace 'gray' "$SCANNED_PDF"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment