Manipulating PDF & PostScript files

In this page

  1. The tools
  2. Page ordering
  3. Touching up eps files
  4. Wine & PDF

1. The Tools

The main tools I use to work with PDF and PostScript files are:

  • pdftk: The PDF tool kit allegedly does everything you need to pdf files. It is in the ubuntu repositories.
  • epstool: extremelly handy to work on encapsulated postscript files. In particular to handle issues with the bounding box.
  • Foxit: I find it better than evince and lighter than acrobat.
  • PDF Studio: adobe does not make the full acrobat for linux. The best alternative I found is PDF Studio. It is a commercial application.

2. Page ordering

Erase pages

Manipulations to erase pages from a pdf file:

$ pdftk file.pdf cat 2-end output new.pdf      # Erase first page
$ pdftk file.pdf cat 1-5 6-end output new.pdf  # Erase page 5

Reverse pages

How to reverse the pages of a pdf file:

$ pdftk file.pdf cat end-1 output rev.pdf      # Reverse page order


Interleave pages from two files, one containing the odd (o.pdf) and the other the even (e.pdf) pages:

$ pdftk f1.pdf f2.pdf (...) cat output new.pdf   # Concatenate files
$ pdftk *.pdf cat output new.pdf                 # Concatenate using wild cards

Interleave pages

Interleave pages from two files, one containing the odd (o.pdf) and the other the even (e.pdf) pages:

$ pdftk o.pdf burst output ilv%04d_A.pdf   # Odd pages into files ilv####_A.pdf
$ pdftk e.pdf burst output ilv%04d_B.pdf   # Even pages into files ilv####_B.pdf
$ pdftk ilv*.pdf cat output file.pdf       # Merge the pages back into one file

Creating a booklet

To create a booklet you need to go back to postscript and reorder the pages accordingly. The booklet output is such that a double-sided printout can be folded in the middle and the pages will be in order:

$ pdf2ps file.pdf                                     # Convert to postscript
( $ pdftops file.pdf )                                ( # if the previous fails )
$ psbook                         # Rearrange pages
$ psnup [-s1] [-mxxx] -2 # Make booklet.  
$ ps2pdf                              # Reconvert to pdf

In psnup, -s1 forces 1:1 scale. Also possible for is -s1.1. The margin can be set with -mxxx where xxx is a positive or negative number. Use the option -d to see a box around the page.

3. Touching up eps files

Bounding box

Why some programs generate bounding boxes poorly calculated goes beyond my understanding. This is how to correct them:

$ epstool --copy --bbox in.eps out.eps        # Recalculate bounding box

4. Printing to pdf files from wine applications

There is no wonderful solution. The best I could find is to install cups-pdf:

$ sudo apt-get install cups-pdf

Re-start the wine application and a pdf printer should be there. Print to it and a pdf file will be put in the "~/PDF" folder. Photos in a word file do not get a nice output.

An alternative is to print to a (prn) file using one of the installed regular printers. This being linux, There is a chance that the printer format is postscript or something readable by evince. If it is postscript you can use ps2pdf:

$ ps2pdf <filename>

You can also try to open the file in evince and print it to another ps or pdf file.