RubyPDF Blog English,PDF,tutorial Fixing PDF margins

Fixing PDF margins

LSAC, the Law School Admission Council, distributes PDF files with busted margins.
Instead of half inch margins all around the page,
they have a one inch margin at the top and no margin at the bottom
(i.e., text runs flush with the bottom of the page).

After spending a few hours trying different poorly documented CUPS command invokations,
I finally found the pdfcrop command.
It was such a frustrating experience,
I have decided to document the solution in hopes of preventing at least one other person from the same hell.

So first I ran pdfinfo on the file to get the page size:

$ pdfinfo recommend.pdf                                                                                                                               
Title:           
Author:         DZS
Creator:        Toolkit http://www.activepdf.com
Producer:       Toolkit http://www.activepdf.com
CreationDate:   Mon Oct 16 03:22:47 2006
ModDate:        Mon Oct 16 03:22:47 2006
Tagged:         no
Pages:          1
Encrypted:      no
Page size:      612 x 792 pts (letter)
File size:      122713 bytes
Optimized:      no
PDF version:    1.5

So the page is 612 by 792.
Next we run pdfcrop to produce a file without any margins:

$ pdfcrop recommend.pdf recommend-cropped.pdf                                                                                                         
PDFCROP 1.5, 2004/06/24 - Copyright (c) 2002, 2004 by Heiko Oberdiek.
==> 1 pages written on `recommend-cropped.pdf'.

Now run pdfinfo on the resulting file:

$ pdfinfo recommend-cropped.pdf                                                                                                                       
Creator:        TeX
Producer:       pdfeTeX-1.21a
CreationDate:   Tue Oct 17 00:50:47 2006
Tagged:         no
Pages:          1
Encrypted:      no
Page size:      551 x 716 pts
File size:      110258 bytes
Optimized:      no
PDF version:    1.4

Notice that the page size has shrunk from 612 by 792 to 551 by 716.
So 612 – 551 = 61 pts narrower,
and 792 – 716 = 76 pts shorter.
We can now use this knowledge along with pdfcrop‘s --margins option
to recenter the resulting document:

$ pdfcrop --margins "31 38 30 38" recommend.pdf recommend-fixed.pdf
PDFCROP 1.5, 2004/06/24 - Copyright (c) 2002, 2004 by Heiko Oberdiek.
==> 1 pages written on `recommend-fixed.pdf'.

Voila.
You have successfully compensated for the incompetence of the institution that holds complete control over who can practice US law.

From: Fixing PDF margins

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.