Sometimes I am given a PDF and I wish I could change its margins. For example, when I print out a conference version of a paper to study in detail, usually there isn’t much space on the sides to write my own ideas. I heard Fermat had a solution for this type of issue :P, but in the modern days, I use sticky notes. The same situation surprisingly arises even if you use PDF annotating softwares. Free or not free (no link for them), they simply do not support the “enlarge canvas” feature yet. All you can do is to insert electronic sticky notes. So much for the metaphor!
Now there is actually a technology called “reflowable PDFs”, which are PDFs that contain enough information to support reflowing its content to fit any width. You can see this page for a screenshot of a reflowed document. Reflowing works wonder for text-dominant documents like novels, but the PDF has to be specially prepared for reflowing to really work well. (Try View->Zoom->Reflow in Adobe Reader 8.)
But if the given PDF is not reflowable, we can still use some graphics editor and edit the PDF interactively. After all, a PDF is mostly a vector graphics file, modulo some potential embedded bitmaps, and so you can edit it like any vector graphics file. I’ve seen it done in Illustrator, and I guess some of the free software competitors like Inkscape or Scribus can do this kind of editing too. But using a command line tool would be far easier.
For a long while, I actually know how to change the margins of a PDF. (Turns out lawyers have essentially the same problem.) The trick is to use the pdfpages package with pdfLaTeX. You may recall that this package allows us to include specific pages of a PDF into our own document. Magically, it has a scale option (that is really inherited from graphicx)… This gives us the first batch file: pdf-rescale.bat. Execute
pdf-rescale.bat foo.pdf 0.8
and you will get foo-0.8.pdf, which is foo.pdf shrunk to 80%. I’ve found that 80% is a good default and so the third argument is actually optional. You can also specify a scale of larger than 1 for some journal articles formatted for smaller paper sizes. I can also imagine fancier applications in which you combine this idea with the geometry package (see this post) to control of the final outcome.
But since we are not changing the actual size of the paper, shrinking the content for a larger margin actually means, well, shrunk content. Conference proceedings are already typeset in a small enough font. Since the proceedings are in two columns, I had the idea to print each column on its own page. That will definitely give us ample space. After a lot of different attempts since last year, I finally managed to get the second batch file: pdf-1c.bat. Execute
pdf-1c.bat foo.pdf
and you will get foo-1c.pdf, which is foo.pdf but with one column per page. No kidding.
The following PNG illustrates these scripts using the title page of an old paper. The upper-left shows the original, and the upper-right is after shrinking to 80%. The lower-left and lower-right are the two pages from the one-column version. I have also attached the source PDF from which I generated the PNG. The key feature is that this PDF retains the text of the original—try search for the word “degree” and you will see. (At one point my solution was to assemble a bunch of PNGs representing each single column into a huge PDF. Although you can annotate on it electronically, you cannot search in it. It also prints slowly.)

Finally, I also note that it is in fact possible to prepare reflowable PDFs using pdfLaTeX or dvipdfm (there seems to be trouble if going through a PS), but I will save it for a later story. For now, you can experience reflowing a LaTeX PDF with this PracTeX article, which is actually on the use of the pdfpages package. Having played with reflowing for a while, I would say that the real deal-breaker for reflowable PDFs lies in the mathematical expressions. You can see this TUGboat article for some excellent macros on fine-tuning mathematical expressions. Now, try to reflow it…
P.S. If you write the corresponding bash scripts, please send them to me so that I can, with full acknowledgement, post them here. The only reason why I stick to batch files is to avoid extra dependencies.
Change PDF Margin Scripts: pdf-rescale.bat pdf-1c.bat
Update: Joshua Dunfield has ported the rescaling script to Linux. See the comments.
11:24 on November 14th, 2007
“The only reason why I stick to batch files is to avoid extra dependencies.”
Windows is itself a major dependency!
But really, this is very cool, though I expect to use it primarily to shrink margins. Here’s an attempt at a sh version:
pdfrescale
I don’t know batch file syntax, and didn’t even try to produce a faithful translation, but it works for me :-P. Modify as you like.
12:37 on January 28th, 2008
You might be interested in the Impose tool from Multivalent:
http://multivalent.sourceforge.net/Tools/pdf/Impose.html
9:29 on February 15th, 2008
Hi there,
What you post here is a real nice work.. However, I encounter specific problem that you maybe able to assist me on.
I have this problem with adjusting margins for PDF file. For my case, I have downloaded an e-book and find out that they are scanned version. But the contents are all very close to the left margin. What I would like to do is to be able to shift the whole page to right (or set more margin on the left).
Would you be able to provide me with some source on how to do that? I would really appreciate that.
Thank you.
7:01 on February 16th, 2008
Hi all,
Sorry for not stating it correctly on my previous postings.
I have a specific problem concerning on how to adjust/set margins for a PDF file - my paper size is A4 (i.e. how to specifically set the left, right, top, and bottom margin).
For my case, I have an e-book with 899 pages inside and they seem to be of scanned version (in other words, compilation of images).
But the contents of each page are so close to the left margin, that I am unable to bind them for the hard copy. What I would like to do is to be able to “SHIFT” or “MOVE” the whole page to right but keeping the same scaling for the content. (In other words adding more margin/space on the left).
I have googled for solutions for the last 2 days, but obtain no answers to my specific problem, except your website that gives me hint. I also found answers on how to SCALE pdf file (change margin for all 4 sides) like what you have in pdf-rescale.bat.
The problem is by scaling the documents into a smaller size, I obtain more spaces on the left margin. But at the same time, the contents shrink down to undesired reading context, which I want to avoid. So what I would like is to keep the content of the same size, and move the content slightly to the right. something like your “pdf-1c.bat”. (I tried using pdf-1c.bat, but it doesn’t really suit to my problem).
Intuitively, a couple of possible ways that I can think of are:
1. manipulating the printer setting (using PDFCreator or pdf2pdf). My aim is to override the standard A4 margins, which I believe the default margin is 0.8mm on the left, 0.5mm on the right, into something non-standard.
2. My second option is to write a program that does the followings:
- Read the PDF file
- Extract all the pages on the PDF file (possibly image)
- For each image
- Perform pixel-shifting to right accordingly
- Create a new one and write each content into the new PDF file
- Save the PDF file
May you be able to assist me with some sources on how to proceed with my problem. I would really appreciate for any helps.
Thank you,
Wilson
18:31 on February 16th, 2008
Wilson, you may have missed the
offsetoption in the manual of thepdfpages. As an example, the following LaTeX sources produces a “copy” of foo.pdf that is shifted 2cm to the right. (The second offset, currently set at 0cm, is the offset from the top.)\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=-,offset=2cm 0cm]{foo.pdf}
\end{document}
20:46 on February 16th, 2008
Maverick,
Thank you very much for the answer, it is just simple and elegant solution. I apologize for not reading it properly from the “pdfpages” documentation. And I really appreciate for your assistance :)..
Regards,
Wilson