For a task that required the conversion of a PDF for print to image files sequence for web display, I had to figure how to export them as quickly as possible, re-combine two facing files into a single “spread”, and add a graphic element that makes them appear more like books. It is a bit of pseudo code, since I am not very familiar with Terminal, besides entering single commands, and installing add-ons in python always seems a bit daunting.

Here is the process for Ubuntu 12.04:

  • Starting with a book.pdf, convert all PDF pages to images, using ghostscript. First, open Terminal, and type “cd”, drag and drop the directory where your PDF is located into terminal, and press enter. Then, type the following command:
    gs -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r300  -sOutputFile='page-%00d.png' 'book.pdf'

    Now you should have a png for each page

  • To combine them into spreads, with Imagemagick installed:
    -montage -geometry +0+0 page-2.png page-3.png spread2-3.png

    However, if you have 160 pages, handwriting that would take a bit of time, so I made a python script that makes a text file with the above command for all pages

  • In gimp, I made a gradient line in the middle to make the images appear more like book pages. I started with one of the spread, created a new layer, in which I put the gradient exactly in the middle, and then erased everything except the gradient line, keeping the dimensions exactly the same.
  • To overlay the gradient line with each of the spreads without opening Gimp or Photoshop
    composite line.png spread2-3.png
  • I am not sure yet how to develop loops with terminal, so I made the following python script that creates a text files with commands that I then copy and paste into Terminal:
    # outputs a file to use for terminal, specifically for PDFs
    
    #create or open a text file
    f = open("file.txt", "w")
    
    a=0
    b=0
    
    outNames = []
    
    # output spreads
    # range of pages, start with 2, since spreads usually are even-odd page
    for i in range(2,10):
        if i%2==0:
            a = i
        else:
            b = i
            c = ("s%s-%s.png" % (a,b))
            outNames.append(c)
            text = ("montage -geometry +0+0 page-%s.png page-%s.png %s; " % (a,b,c))
            f.write(text)
            f.write("n")
    
    f.write("n")
    
    #overlay with gradient line
    for i in outNames:
        text2 = ("composite line.png %s s%s;" % (i,i))
        f.write(text2)
        f.write("n")
    
    f.close()

    I pasted a quarter at a time, so as not to crash Terminal.

To do the same simple task without a little bit of code, would either mean Batch processing in Photoshop, or manually opening in Gimp or Photoshop, which doesn’t guarantee that on each page, they gradient line would be in the exactly the same place. However, I also know that this isn’t the most efficient way yet. If anyone has any suggestions, please share them.