0

If I specify the option page of \newwatermark using \pageref, I get the following error:

Package xwatermark Error: No page specifier for watermark:

How to fix that?

\documentclass{article}
\usepackage{afterpage}
\usepackage{xwatermark} %[printwatermark]{xwatermark}
\usepackage{pdfpages}

\begin{document}

\verb|\pageref{sec:foo}| \pageref{sec:foo}  % 3, as expected

\newwatermark*[
% TODO replace
page=3
% by:
% \pageref{sec:foo} %  Package xwatermark Error: No page specifier for watermark:
]{Watermark}

\tableofcontents

\clearpage

\vspace*{\fill}
{\LARGE \begin{center}Bar\end{center}}
\vspace*{\fill}

\clearpage

\csname phantomsection \endcsname % hyperref
%\afterpage{
  \addcontentsline{toc}{section}{Foo}
%}
\label{sec:foo}
\includepdf[pages={1-}]{/home/er/Documents/essential/dev/LaTeX/toy/misc/huge/Foo.pdf} % Foo.pdf is a one page pdf


\end{document}
0

\pageref doesn't give a number, it only prints one. You can use the refcount package:

\documentclass{article}

\usepackage{xwatermark} %[printwatermark]{xwatermark}
\usepackage{pdfpages}
\usepackage{refcount}
\begin{document}

\verb|\pageref{sec:foo}| \pageref{sec:foo}  % 3, as expected

\newwatermark*[
page=\getpagerefnumber{sec:foo}
]{Watermark}

\newpage

\section{blub}\label{sec:foo}

\end{document}
  • Compiling the suggested code: ERROR: Undefined control sequence. --- TeX said --- <argument> ...e \@tempdima \@parboxrestore \color {\wmk@textcolor }\cptdimde...l.18 \end{document}. It works without the wm. Any suggestion? – Erwann Sep 11 '18 at 19:43
  • 1
    @Erwann I shortened too much. You need a color package, e.g. xcolor (or pdfpages which would load it too). – Ulrike Fischer Sep 11 '18 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.