我有以下名为 addfooter.tex
的文件,用于在 pdf 文件中添加页眉和页脚。
\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}
这将创建一个名为 addfooter.pdf
的文件,其中包含所需的页眉和页脚。但我需要将页眉和页脚添加到文件夹中的所有文件中。如何使用 shell 脚本或类似的东西来做到这一点?
我正在使用 pdflatex 命令。您能否提供用于向文件夹中的所有文件添加页眉和页脚的 shell 脚本。
最佳答案
您可以从命令行将名称传递给您的 tex 文件,如下所示:
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}
然后你的 shell 脚本只需循环所有文件
关于shell - 如何为文件夹中的所有 pdf 添加页眉和页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62357936/