# batch add header/footer to pdf files

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.

# 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]{===}

\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

• The pdfjam package provides a possibly more convenient interface to Latex's pdfpages functionality e.g. pdfjam --outfile newfile.pdf --pagecommand '{}' oldfile.pdf – steeldriver Dec 23 '15 at 13:47
• @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 '15 at 0:13
• 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 at 10:43

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!