Skip to content

Instantly share code, notes, and snippets.

@ethicka
Last active October 9, 2020 14:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethicka/79df1624dccf78c13a6d6539ae51c08b to your computer and use it in GitHub Desktop.
Save ethicka/79df1624dccf78c13a6d6539ae51c08b to your computer and use it in GitHub Desktop.
Convert a folder of PDFs to JPGs

Command Line PDF-to-JPG conversion

I needed to be able to extract the first page from a folder of PDFs and export them as JPGs.

Poked around StackExchange and found out about vips.

I wrote a simple bash script to run inside of the folder with the PDFs.

Instructions

  1. Install vips using Homebrew: brew install vips
  2. Download process.sh and move it into your PDF folder.
  3. Run chmod u+x pdf-to-jpg.sh to give the file permissions.
  4. Execute ./pdf-to-jpg.sh to conver the PDFs to JPGs.
  5. Voila!
#!/bin/bash
# Dependencies: vips
# Homebrew: brew install vips
for file in *.pdf
do
# Run vips pdfload for options
# You could add --page=1 to get the second page (from 0) or --dpi=300, etc. to get different quality images
# The variable gets the filename without the extension
vips pdfload ${file%.*}.pdf ${file%.*}.jpg
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment