How to batch add header/footer to pdf files in Ubuntu?

6,242

Solution 1

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

Solution 2

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!

Share:
6,242

Related videos on Youtube

betty
Author by

betty

Updated on September 18, 2022

Comments

  • betty
    betty over 1 year

    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.

  • steeldriver
    steeldriver over 8 years
    The pdfjam package provides a possibly more convenient interface to Latex's pdfpages functionality e.g. pdfjam --outfile newfile.pdf --pagecommand '{}' oldfile.pdf
  • Admin
    Admin over 8 years
    @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)
  • divramod
    divramod about 5 years
    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!
  • Admin
    Admin almost 2 years
    @divramod here is the pdfpages manual