Instantly share code, notes, and snippets.

Embed
What would you like to do?
Darkening PDFs

short url to these instructions: caseywatts.com/darken

Other gists & tricks: http://caseywatts.com/gists-and-tricks

Using Monochrome (recommended)

  • obtain your ugly, gray pdf
  • brew install imagemagick
  • brew install ghostscript
  • magic command!
    • convert -density 300x300 MYGRAYPDFNAME.pdf -monochrome -quality 100 NAMEIWANTTOSAVETHISAS.pdf
  • I made a shortcut-y bash script by putting this in my .zshrc (.bashrc would work too~):
# see: caseywatts.com/darken
# accepts 1 argument
#   - filename without extension (no .pdf)
# examples:
#  - darken SheetMusic_Papi
function darken() {
  convert -density 300x300 $1.pdf -monochrome -quality 100 $1_bw.pdf
  echo "saved as $1_bw.pdf"
}

Using Transform

  • obtain your ugly, gray pdf
  • brew install imagemagick
  • brew install ghostscript
  • magic command!
    • convert -density 300x300 MYGRAYPDFNAME.pdf -threshold 80% -quality 100 NAMEIWANTTOSAVETHISAS.pdf
      • you might change the threshold value
      • -density 300x300 helps to read the file at a high resolution
      • -threshold 80% makes everything under this value black and above this value white. see the docs
    • an actual example, and I'm trying a few different thresholds:
      • convert -density 300x300 Uprising.pdf -threshold 80% -quality 100 Uprising_80.pdf
      • convert -density 300x300 Uprising.pdf -threshold 50% -quality 100 Uprising_50.pdf
      • convert -density 300x300 Uprising.pdf -threshold 20% -quality 100 Uprising_20.pdf
  • I made a shortcut-y bash script by putting this in my .zshrc (.bashrc would work too~):
# accepts 2 arguments
#   - filename without extension (no .pdf)
#   - threshold value (default is 80 if none given)
# examples:
#  - darken SheetMusic_Papi 75
#  - darken SheetMusic_Papi
function darken() {
  DENSITY=${2:-80} # either the 2nd argument, or the default will be 80
  convert -density 300x300 $1.pdf -threshold $DENSITY% $1_$DENSITY.pdf
  echo "saved as $1_$DENSITY.pdf"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment