![如何使用 xwatermark 在奇数页面上添加不同的水印?](https://linux22.com/image/439698/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20xwatermark%20%E5%9C%A8%E5%A5%87%E6%95%B0%E9%A1%B5%E9%9D%A2%E4%B8%8A%E6%B7%BB%E5%8A%A0%E4%B8%8D%E5%90%8C%E7%9A%84%E6%B0%B4%E5%8D%B0%EF%BC%9F.png)
我想要一个透明的前景水印,该水印对于偶数页和奇数页会有所不同,并且不会渲染底层内容(例如文本和图像),这是无效的。可以吗?
梅威瑟:
\documentclass[]{article}
\usepackage[printwatermark]{xwatermark}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{pdfpages}
\pagestyle{empty}
\usepackage{hyperref}
\hypersetup{
colorlinks=true, %set true if you want colored links
linktoc=all, %set to all if you want both sections and subsections linked
linkcolor=blue, %choose some color if you want links to stand out
}
\newsavebox\mybox
\savebox\mybox{\tikz[color=red,opacity=0.3]\node{BSFU};}
\newwatermark*[
allpages,
angle=45,
scale=12,
xpos=-20,
ypos=15
]{\usebox\mybox}
\begin{document}
\includepdf[pages=-,pagecommand={\mybox}]{output}
\end{document}
答案1
下面将使用 LaTeX 的内置 shipout 钩子为您的水印放置两个不同的框,基于 -counterpage
是偶数还是奇数。
\documentclass[]{article}
\usepackage{tikz}
\AddToHook{shipout/foreground}
{%
\put(0.5\paperwidth,-0.5\paperheight){\mywatermark}%
}
\newcommand*\mywatermark
{%
\ifodd\value{page}%
\usebox\mywatermarkboxODD
\else
\usebox\mywatermarkboxEVEN
\fi
}
\newsavebox\mywatermarkboxEVEN
\newsavebox\mywatermarkboxODD
\tikzset{mywatermark/.style={color=red,opacity=0.3,font=\huge,rotate=#1}}
\AtBeginDocument
{%
\sbox\mywatermarkboxODD
{\makebox[0pt]{\tikz\node[mywatermark=45]{BSFU};}}%
\sbox\mywatermarkboxEVEN
{\makebox[0pt]{\tikz\node[mywatermark=-45]{BSFU};}}%
}
\usepackage{duckuments}
\begin{document}
\duckument
\end{document}