Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Xosrov/4a33e148e7030217074cfd77cece0d66 to your computer and use it in GitHub Desktop.
Save Xosrov/4a33e148e7030217074cfd77cece0d66 to your computer and use it in GitHub Desktop.
Compress images and create PDF from them, remove any existing EXIF data before and after pdf creation using multiple methods.
  • Create image scans using any method(this one is good)
  • Pass images to this script(tested on ubuntu)
  • Script requirements(tested with apt install on Ubuntu): exiftool imagemagick img2pdf ghostscript qpdf
#!/bin/bash
if [ $# -eq 0 ]
then
	echo "Input images to convert"
else
	for i in "$@"; do
		if [ ! -f $i ]; then
			echo "File ${i} does not exist"
			exit
		fi
	done
	RED='\033[0;31m'
	NC='\033[0m'
	exiftool -overwrite_original -all:all= $@
	mogrify -quality 70 $@ 
	img2pdf $@ > middle.pdf
	gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf middle.pdf
	rm middle.pdf
	exiftool -overwrite_original -all:all= output.pdf
	echo -e "${RED}Done"
	qpdf --linearize --replace-input output.pdf
	echo -e "Remaining embedded exif data:${NC}"
	exiftool -ee -all:all output.pdf
	echo -e "${RED}Remaining pdf exif data:${NC}"
	exiftool -all:all output.pdf
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment