How add header and footer to all pdf in a folder

I have following file called addfooter.tex to add header and footer in a pdf file.

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

\usepackage{url}
\usepackage{hyperref}
\usepackage{lmodern}
\usepackage{pdfpages}
\usepackage{fancyhdr}
\begin{document}
\setcounter{page}{1}

\fancyfoot[RO]{\url{https://myddomain.com}}
\fancyfoot[LO]{\url{https://www.facebook.com/myddomain}}
\fancyfoot[CO]{\thepage}

\fancyhead[LO]{\url{http://myddomain}}
\fancyhead[RO]{\url{https://test.myddomain.com}}


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

\end{document}

This will create a file called addfooter.pdf with required header and footer. But I need to add header and footer to all my file in a folder. How to do it using a shell script or something like that? I am using pdflatex command. Can you give shell script for adding header and footer to all files in a folder.

Answers

You can pass the name to your tex file from the command line like this:

pdflatex "\def\foo{ee}\input{addfooter.tex}"


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

%\usepackage{url}
\usepackage{lmodern}
\usepackage{pdfpages}
\usepackage{fancyhdr}
\usepackage{hyperref}
\begin{document}
\setcounter{page}{1}

\fancyfoot[RO]{\url{https://myddomain.com}}
\fancyfoot[LO]{\url{https://www.facebook.com/myddomain}}
\fancyfoot[CO]{\thepage}

\fancyhead[LO]{\url{http://myddomain}}
\fancyhead[RO]{\url{https://test.myddomain.com}}


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

\end{document}

Then your shell script will just have to loop over all files

Posted on by samcarter_is_at_topanswers.xyz