shell - 如何为文件夹中的所有 pdf 添加页眉和页脚

标签 shell latex pdflatex

我有以下名为 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/

相关文章:

python - request.params 中的关键错误

shell - 使用 Django shell 实例化具有外键属性的对象

r - 如果小于 10,则将数字打印为单词

latex - 无法启动命令 pdflatex -synctex=1 -interaction=nonstopmode %.tex 错误

shell - Makefile 中 shell 脚本行输出的重定向

c++ - C++ 中长字符串的 Perl 风格引号

user-interface - 如何防止 MATLAB GUI 中的 LATEX 标签变得模糊?

java - 从 Java 执行时 Pdflatex 运行崩溃(在 Windows 上)

jupyter-notebook - 如何将Jupyter/IPython笔记本转换为LaTex?

regex - sed 扩展正则表达式的替代方法