Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 4 down vote accepted
\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.

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 Hoffmann May 3 '11 at 19:36
add comment

Your Answer

 
discard

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.