# Creating a mask with n empty pages for stamping

I want to use pdftk's multistamp feature to add annotations to a script of which I don't own the source code.

My goal is to create an empty pdf file of n empty pages (this would then serve as my mask for stamping), in such a way that I can, for any k, easily add some content to the k-th page.

I do not know how to do that and would appreciate any input!

-
TeX doesn't let you create n empty pages then go back to page k. Once page k is done it's gone. But you can put anything you want on page k when page k is being processed. Why don't you ask that instead? –  Matthew Leingang May 3 '11 at 17:00

\documentclass[a4paper]{article}

\newcommand{\multistamp}[1]{%
\loop\unless\ifnum\value{page}>#1
\dowhatsonthispage
\repeat}

\newcommand{\dowhatsonthispage}{%
\null\csname onthispage\thepage\endcsname\newpage}

\newcommand{\putonpage}[2]{%
\expandafter\def\csname onthispage#1\endcsname{#2}}

\begin{document}

\putonpage{1}{Hello world}
\putonpage{3}{\vspace*{\fill}Hello world\par\vspace{\fill}}

\multistamp{4}

\end{document}


This creates a four page document, with something on the first and third pages as decided by the commands \putonpage.

When producing page number 2, this code executes the macro \onthispage2 that's not defined, but it's with \csname onthispage2\endcsname so it's \relax. When at page 3, the macro \onthispage3 is defined and so its definition can be used.

-
Very clever! This seems to contradict my comment that it's impossible in TeX. But the output (indeed, the generation of any page) is delayed until the end so that page content can be put on them beforehand. –  Matthew Leingang May 3 '11 at 17:13
@Matthew: of course it's impossible to modify a page after it has been shipped out. So I define beforehand what should go in each page and then produce them. –  egreg May 3 '11 at 17:18
Thank you, this is fantastic! –  Felix Hoffmann May 3 '11 at 19:36