TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
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
up vote 4 down vote accepted


  \null\csname onthispage\thepage\endcsname\newpage}

  \expandafter\def\csname onthispage#1\endcsname{#2}}


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



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.

share|improve this answer
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 Z. Hoffmann May 3 '11 at 19:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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