Skip to content

Instantly share code, notes, and snippets.

@piotrplenik
Created November 25, 2013 15:25
Show Gist options
  • Save piotrplenik/7642967 to your computer and use it in GitHub Desktop.
Save piotrplenik/7642967 to your computer and use it in GitHub Desktop.
Create flatten PDF file
#!/bin/bash
# Script to convert PDF - create flatten PDF file
#
# Format:
# ./convert input-file.pdf output-file.pdf
#
# Dependencies:
# * pdftk
# * imagemagick
PDF=$1
OUT_PDF=$2
DENSITY=300
echo "Processing $PDF"
DIR=`basename "$1" .pdf`
echo ' Converting pages to JPEG files...'
pdftocairo -r $DENSITY -jpeg $PDF /tmp/convert-"$DIR"
echo ' Merge JPEG files into one PDF'
convert -density $DENSITY /tmp/convert-"$DIR"* $OUT_PDF
rm /tmp/convert-"$DIR"*
echo 'All done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment