Skip to content

Instantly share code, notes, and snippets.

@piotrplenik
Created November 25, 2013 15:25

Revisions

  1. @jupeter jupeter created this gist Nov 25, 2013.
    27 changes: 27 additions & 0 deletions flat-pdf.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/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'