6

Is there a command or script that would help me ease the process of adding page numbers to a PDF with hundreds of pages? Thanks.

2 Answers 2

5

Using LaTeX!

0) Install LaTeX if necessary

1) In the following latex document replace x.pdf by your file.pdf

\documentclass{article}
\RequirePackage[a4paper,top=3cm,left=3cm,right=3cm,bottom=3cm]{geometry}

\usepackage{pdfpages}
\usepackage{fancyhdr}
\begin{document}

\fancyfoot[RO]{Braga}
\fancyfoot[LO]{2015}
\fancyfoot[CO]{===}

\fancyhead[LO]{Lecture notes of askubuntu}
\fancyhead[RO]{\thepage}

  \includepdf[pagecommand={\thispagestyle{empty}},pages=1 ]{x.pdf}
  \includepdf[pagecommand={\thispagestyle{fancy}},pages=2-]{x.pdf}

\end{document}

3) run pdflatex addfooter.tex and a addfooter.pdf will be created.

4) adapt the headers, footer (left,center, right), tune margin's sizes, etc.

Update:

Although LaTeX version give us more control over the details, as @steeldriver, pointed out, in some situations a pdfjam command line is the best choice. Typical use:

pdfjam --outfile newfile.pdf --pagecommand '{}' oldfile.pdf
4
  • 3
    The pdfjam package provides a possibly more convenient interface to Latex's pdfpages functionality e.g. pdfjam --outfile newfile.pdf --pagecommand '{}' oldfile.pdf Dec 23, 2015 at 13:47
  • 1
    @steeldriver, thank you! pdfjam is always a good idea, but in this case I believe we will need to tune several details, (define margins, page size, header and footer details, and probably some unnumbered pages, etc)
    – user216043
    Dec 24, 2015 at 0:13
  • 1
    thx, that helped me. can someone maybe give a hint on how to move the output of --pagecommand to the top, or more in general where can i find documentation about what is possible with --pagecommand? maybe bold text or colors are interesting too. thx in advance!
    – divramod
    Mar 14, 2019 at 10:43
  • @divramod here is the pdfpages manual May 21, 2022 at 14:24
1

I actually found a much better solution myself. Rather than doing it manually as suggested above, and wasting time on figuring it out, the easiest way is to simply install jpdftweak package. It does this and more with a couple of mouse clicks. Enjoy!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .