Skip to content

Instantly share code, notes, and snippets.

@khrome
Created December 19, 2011 18:29
Show Gist options
  • Save khrome/1498296 to your computer and use it in GitHub Desktop.
Save khrome/1498296 to your computer and use it in GitHub Desktop.
XeLaTeX watermarking environment macro
\usepackage{everypage}
\newenvironment{water}{\AddEverypageHook{\waterb}}{
\AddThispageHook{\waterb}\AddEverypageHook{\watere}
}
\makeatletter
\newcommand{\waterb}{
\AddToShipoutPicture*{%
\setlength{\@tempdimb}{.5\paperwidth}%
\setlength{\@tempdimc}{.5\paperheight}%
\setlength{\unitlength}{1pt}%
\put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
\makebox(0,0){\rotatebox{45}{\textcolor[gray]{0.75}%
{\fontsize{6cm}{6cm}\selectfont{DRAFT}}}}%
}%
}}
\makeatother
\makeatletter
\newcommand{\watere}{
\AddToShipoutPicture*{%
\setlength{\@tempdimb}{.5\paperwidth}%
\setlength{\@tempdimc}{.5\paperheight}%
\setlength{\unitlength}{1pt}%
\put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
\makebox(0,0){\rotatebox{45}{\textcolor[gray]{1}%
{\fontsize{6cm}{6cm}\selectfont{DRAFT}}}}%
}%
}}
\makeatother
\usepackage{everypage}
\newenvironment{water}{\AddEverypageHook{\waterb}}{
\AddThispageHook{\waterb}\AddEverypageHook{\watere}
}
\makeatletter
\newcommand{\waterb}{
\AddToShipoutPicture*{%
\setlength{\@tempdimb}{.3\paperwidth}%
\setlength{\@tempdimc}{.4\paperheight}%
\setlength{\unitlength}{1pt}%
\put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
\includegraphics[height=100mm]{watermark.png}
}%
}}
\makeatother
\makeatletter
\newcommand{\watere}{
\AddToShipoutPicture*{%
\setlength{\@tempdimb}{.3\paperwidth}%
\setlength{\@tempdimc}{.4\paperheight}%
\setlength{\unitlength}{1pt}%
\put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
\includegraphics[height=100mm]{watermark.png}
}%
}}
\makeatother
\begin{water}
% watermarked pages here
\end{water}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment