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

How do I apply a different background image for each page? I have an array of pdf's to apply. I have used the watermark package. However, I do not like the idea of manually adding a different watermark for hundreds of pages, I prefer the idea of using perltex --love Perl! I guess the question is really, how do I access each page's data structure, just before it is written to a file?

Here is the perl code I have created so far:

\def\imgs{1 2 3 ... x}


  my $numpgs = $_[0];
  my @imgarray = split / /, $_[1];
  my $return = ();

  my $c = 1;
  for (0 .. $numpgs) {
    # Here I wish to modify each page's background to 
    $return .= WATERMARK[LATEXPAGE[$c]] $imgarray[$c]\.pdf;
  return $return;
share|improve this question
Welcome to TeX.sx. If you select your code and click {} button or press Ctrl-K the code is displayed correctly. (or you can introduce 4 whitespace characters at the beginning of each line manually) – percusse May 28 '12 at 21:59
Did you look at the package atbegshi? – egreg May 28 '12 at 22:31

I think your love for Perl is making you take the wrong path.

how do I access each page's data structure, just before it is written to a file?

This is normally done using one of the packages atbegshi, bophook, everyshi, eso-pic or \background The packages will enable you to hook into LaTeX's output routine and add a picture or text before shipment.

If all the documents use the same class, it is also possible to hook into every page using the header. This is my preferred way and here is a MWE as to how to do it.

%  \PassOptionsToPackage{strict}{changepage}
%  \RequirePackage{changepage}
%  }{}
   \put(\Xeven,\Yeven){\turnbox{90}{\Huge \textcolor{\watermark@textcolor}{\watermark@text}}}
%% Define a macro to print SAMPLE PAGE IN THE MARGIN
   \put(\Xodd,\Yodd){\turnbox{90}{\Huge \textcolor{\watermark@textcolor}{\watermark@text}}}
%  Define the watermark words
% redefine headings
%% We define two macros to position the watermark on the page
\watermarktext{SAMPLE PAGE}


% end of document
share|improve this answer

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.