How to batch add header/footer to pdf files in Ubuntu?
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!
Related videos on Youtube
betty
Updated on September 18, 2022Comments
-
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 over 8 yearsThe
pdfjam
package provides a possibly more convenient interface to Latex'spdfpages
functionality e.g.pdfjam --outfile newfile.pdf --pagecommand '{}' oldfile.pdf
-
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 about 5 yearsthx, 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 almost 2 years@divramod here is the pdfpages manual