Posts

How to add page numbers to a PDF

10 Feb 2020

We've all been there. You've received the PDF of a draft report, a manuscript to review or a thesis. But there are no page numbers! If you print it out, all the pages will get mixed up when you add it to the pile of paperwork on your desk. And you won't be able to cross-reference your comments to pages in the file.

What can you do? Of course, you could send it back and ask whoever made it to send you a new version with page numbers . But maybe that isn't an option due to a pressing deadline.

Here is a simple solution to the problem for LaTeX users, courtesy of Brian Hunt at stackoverflow.

  1. Rename your PDF to example.pdf.
  2. Wrap a latex file around the PDF using \includepdf, and use the \includepdfset command to add page numbers.
  3. The wrapper file is below:

 

\documentclass[8pt]{article}
\usepackage[final]{pdfpages}
\usepackage{fancyhdr}

\topmargin 70pt
\oddsidemargin 70pt

\pagestyle{fancy}
\rfoot{\Large\thepage}
\cfoot{}
\renewcommand {\headrulewidth}{0pt}
\renewcommand {\footrulewidth}{0pt}

\begin{document}
\includepdfset{pagecommand=\thispagestyle{fancy}}
\includepdf[fitpaper=true,scale=0.98,pages=-]{example.pdf}
% fitpaper & scale aren't always necessary - depends on the paper being submitted.
\end{document}

 

Then you just need to run the command from the Windows command line:

 

pdflatex addpages

 

Your new, page-numbered PDF will appear as "example.PDF".

I haven't tried, but I expect that this will also work on overleaf.com for those who do not want to install LaTeX.

The full description and discussion is available at stackoverflow.

Electricity and Environment Laboratory

Renewable energy and land-atmosphere interactions research

Top