![我可以添加文件的下载日期作为水印吗?](https://linux22.com/image/479397/%E6%88%91%E5%8F%AF%E4%BB%A5%E6%B7%BB%E5%8A%A0%E6%96%87%E4%BB%B6%E7%9A%84%E4%B8%8B%E8%BD%BD%E6%97%A5%E6%9C%9F%E4%BD%9C%E4%B8%BA%E6%B0%B4%E5%8D%B0%E5%90%97%EF%BC%9F.png)
答案1
以下过程依赖于 2 个包并使用 来\pdffilemoddate{<file.ext>}
从 中提取文件修改日期<file.ext>
。原始下载文件包含在使用pdfpages
。并且,对于所包含的下载文件的每个页面,我们执行pagecommand
插入包含文件修改日期(应与下载日期相对应)的水印。水印插入到每个页面的顶部,F
使用G
eso-pic
的\AddToShipoutPictureFG*
。
\documentclass{article}
\usepackage{eso-pic,pdfpages,lipsum}
% https://tex.stackexchange.com/a/12310/5764
\newcommand*{\filedate}[1]{%
\expandafter\filedateX\pdffilemoddate{#1}\relax
}
\def\filedateX#1#2#3#4#5#6#7#8{%
\filedateXX{#3#4#5#6}{#7#8}%
}
\def\filedateXX#1#2#3#4#5#6#7#8{%
\filedateXXX{#1}{#2}{#3#4}{#5#6}{#7#8}%
}
\def\filedateXXX#1#2#3#4#5#6#7#8\relax{%
\formatdate{#1}{#2}{#3}{#4}{#5}{#6#7}%
}
\newcommand*{\formatdate}[6]{%
#1-#2-#3\ #4:#5:#6%
}
\begin{document}
\lipsum[1]% Text before the included/downloaded file (if it exists/is needed)
\includepdf[
pages=1-2,
pagecommand={
\thispagestyle{empty}% Remove header/footer
\AddToShipoutPictureFG*{%
\AtPageLowerLeft{%
\hspace{2em}% Move watermark into page
\rotatebox{90}{%
\makebox[\paperheight]{\Large Downloaded on \filedate{lipsum.pdf}}%
}%
}%
}%
}
]{lipsum}% Include downloaded file
\lipsum[2]% Text after the included/downloaded file (if it exists/is needed)
\end{document}
将输出转换\pdffilemoddate
为更易读的内容得益于文件创建日期。