Creating Double Page JPEG images from PDF

While in the process of making a photobook in Lightroom I wanted to review the book before actually ordering it. For this I wanted to have the pages in JPEG format instead of one big PDF.

It turns out that with ghostscript one can easily extract the images.

I am using cygwin on a Windows 7 64 Bit operating system to work with ImageMagick, Ghostview and the like.

But before I was able to use ghostscript I had to fix this error I was getting about the font Arial.ttf not being found, after some research I found that creating the missing directories and adding a link to the font in the Windows directory fixes that issue:

mkdir /usr/share/fonts/
mkdir /usr/share/fonts/TTF
ln -s /cygdrive/c/Windows/Fonts/arial.ttf /usr/share/fonts/TTF/

Then I used ghostview to convert the PDF pages to individual JPEG files in a directory called jpgs:

$ gs -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=108 -sOutputFile=jpgs/usa_1991_%03d.jpg -dJPEGQ=80 -r300x300 -q "USA 1991.pdf" -c quit

I also did that for the cover PDF, then opened the image in Photoshop and created two additional images from the front and back cover and named them usa_1991_000.jpg and usa_1991_109.jpg to be able to combine them with the single first and last pages of the book.

The shell script below was used to combine each two JPEG images into a single file:

#!/bin/bash

indexPlusOne=1
# counting from 0 to 109 (number of pages) in steps of 2
# numbers are padded with zeroes, so 1 becomes 001
for index in $(seq -f "%03g" 0 2 109)
do
  # left image file name
  left="usa_1991_$index.jpg"  
  # create the padded number for the right image, add padding, store it in indexPlusOnePadded
  printf -v indexPlusOnePadded "%03d" $indexPlusOne
  # add two to the right page number
  let indexPlusOne+=2  
  # right image file name
  right="usa_1991_$indexPlusOnePadded.jpg"  
  # combine the images using ImageMagick
  montage -density 300 $left $right -tile 2x1 -quality 100 -geometry 2888x2475 "page-$index.jpg"
done

Here are some examples of the finished double-spread images in reduced size: