When using advice elsewhere here to place a watermark over every page of an \includepdf
, I'd like to vary the location of the watermarks on each page. One very laborious solution is to include the PDF one page at a time (see "This works" segment). I hoped to use this neat list-as-queue idea to queue up all of the co-ordinates, then pop them from within the pdfpages
pagecommand
on each page (see "This doesn't" segment; needs commenting-out for "This works" to complete).
Unfortunately my understanding of the underlying mechanisms fails me at this point: the error Missing \endcsname inserted
is completely opaque to me. I'm guessing that the \el{}
macro to pop co-ordinates can't be used in the context I'm using it in; would be grateful for suggestions for a fix..
Two support documents required; I'd suggest grabbing this for the PNG watermark image, alpha_noset.png
:
wget https://www.imagemagick.org/Usage/masking/alpha_noset.png
.. and copying in any two-or-more-page PDF you have handy as inclusion.pdf
.
\documentclass[10pt,a4paper]{letter}
\usepackage{tikz} % Watermark overlay
\usepackage{pdfpages} % Multi-page PDF inclusions
\usepackage{graphicx} % Graphical inclusions
\usepackage{xparse}
% Pull values out of a queue, from https://tex.stackexchange.com/questions/230618/iterator-like-command-where-each-use-expands-to-an-item-from-list-defined-earli
\ExplSyntaxOn
\NewDocumentCommand{\deflist}{O{,}m}
{
\seq_set_split:Nnn \l_narebski_list_seq { #1 } { #2 }
}
\NewDocumentCommand{\el}{}
{
\seq_item:Nn \l_narebski_list_seq { 1 }
\seq_pop_left:NN \l_narebski_list_seq \l_narebski_waste_tl
}
\seq_new:N \l_narebski_list_seq
\tl_new:N \l_narebski_waste_tl
\ExplSyntaxOff
\signature{x}
\address{Etc.}
\begin{document}
\begin{letter}{To whom it may concern,}
\opening{Dear sir/madam,}
Really.
\closing{Yours sincerely,}
\newpage
\pagenumbering{gobble}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This works: include PDF one page at a time, repositioning the
% watermark individually for each page.
% Integration of tikzpicture to every \includepdf taken from https://tex.stackexchange.com/questions/12838/can-i-add-tikzpictures-to-pages-included-with-pdfpages
\setkeys{pdfpages}{pagecommand={
\begin{tikzpicture}[remember picture, overlay]
\node[inner sep=0pt] at (\atx,\aty) {%
\includegraphics[width=8cm,angle=\ata]{alpha_noset.png}%
};%
\end{tikzpicture}
}}
% Co-ordinates are x=\atx, y=\aty and rotation angle=\ata.
\newcommand{\atx}{11} \newcommand{\aty}{3} \newcommand{\ata}{15}
\includepdf[pages={1}]{inclusion.pdf}
\renewcommand{\atx}{-2} \renewcommand{\aty}{-18} \renewcommand{\ata}{90}
\includepdf[pages={2}]{inclusion.pdf}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This doesn't, but I'd prefer it: queue up list of watermark co-
% ordinates and pop 'em off as needed.
% Here we line up the list of co-ordinates; in normal text, \el{}
% would retrieve them, one at a time (I could say "first: \el{},
% second: \el{}, third: \el{}", etc.). Within the pdfpages pagecommand,
% \el{} causes an error instead.
\deflist{11,3,15,-2,-18,90} % Same sequence of atx,aty,ata values as above.
\setkeys{pdfpages}{pagecommand={
\begin{tikzpicture}[remember picture, overlay]
\node[inner sep=0pt] at (\el{},\el{}) {%
\includegraphics[width=8cm,angle=\el{}]{alpha_noset.png}%
};%
\end{tikzpicture}
}}
%% COMMENT/UNCOMMENT THE NEXT LINE TO SUPPRESS/GENERATE THE FAIL:
\includepdf[pages={1,2}]{inclusion.pdf}
\end{letter}
\end{document}
\foreach \atx, \aty in {1/1,...,10/10} {\pgfmathparse{rnd}\pgfmathresult}
(there is better code code than this, look through the manual.)\seq_pop...
is not expandable. You need to get the values before executing the \node command.