Skip to content

Instantly share code, notes, and snippets.

@mrbar42
Last active April 2, 2018 11:11
Show Gist options
  • Save mrbar42/2b5452f075106e256f2d092b828980f0 to your computer and use it in GitHub Desktop.
Save mrbar42/2b5452f075106e256f2d092b828980f0 to your computer and use it in GitHub Desktop.
Convert images to one combined PDF file (based on pdftk and imagemagic)
#!/usr/bin/env bash
set -e
if [[ ! "$1" ]]; then
echo "Usage: pdfer page1.png page2.png..."
exit 1
fi
output_file="combined.pdf"
pages=""
for file in ${@}; do
if [[ ! "$file" =~ .pdf$ ]]; then
convert "${file}" "${file}.pdf"
pages+=" ${file}.pdf"
else
pages+=" ${file}"
fi
done
pdftk ${pages} cat output ${output_file}
rm -f ${pages}
echo "Done - saved as $output_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment