I need to add annotations to large PDF file. The method suggested in this answer does not scale well:

{\begin{tikzpicture}[remember picture,overlay]
 \node at (current page.center) {overlayed text};

My PDF file is 700 pages long. I annotate the file at random pages (50+ annotations). Now my source has the following structure:

annotationion of page X


annotationion of page Y


annotationion of page Z

The extra \includepdf are both annoying and error prone. Is there a way to automate this procedure?

  • 1
    For the future casual reader: if you just need to overlay text, tikz is overkill. You are better off with textpos. Commented Apr 4, 2018 at 7:54

2 Answers 2


Update: Package now released on CTAN

I finally got around to tidying up my pdfoverlay package and releasing it on to CTAN. It's also in TeXLive and MikTeX. See https://ctan.org/pkg/pdfoverlay.

I re-implemented it in expl3 and wrote some proper documentation. The syntax is slightly different taking into account some of the feedback from the comments below.

The MWE example below now becomes:

Annotation on page 1.
Annotation on page 10.
Annotation on page 50.

Original Answer

I have written a package that is exactly for this kind of thing. It's not documented except with a few comments and isn't in CTAN. (I could add it, though not for a couple of weeks.) It probably also needs some error checking to be a bit more robust.

It allows for this kind of thing:

Annotation on page 1.
Annotation on page 10.
Annotation on page 50.

Just save this as pdfoverlay.sty and put it in the same directory as your tex file.

%% This file is pdfoverlay.sty'
%% Copyright (c) 2017-2018
%% by David Purton <[email protected]>
%% This work may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3c of this license
%% or (at your option) any later version. The latest version of this
%% license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% This work is "maintained" (as per the LPPL maintenance status)
%% by David Purton.
%% This work consists of the file pdfoverlay.sty.
  [2018/04/04 Package for overlaying text on an existing PDF document (DCP)]




         {No PDF file set}
         {Set a PDF file using \protect\pdfoverlaySetPDF}}
         \ifnum \thepdfoverlay@page>\z@
           \unless\ifnum \thepdfoverlay@page>\pdfoverlay@pagecount


% set the PDF to output in the background
% \pdfoverlaySetPDF{filename.pdf}
       {PDF file #1 not found}


% jump to page in background PDF without outputting pages in between
% \pdfovrlaySetPage{n}
% where n is an integer
% NOTE: The page will not actually be outputted
%       unless there is some text overlayed on it

% Move through the PDF to the specified page
% \pdfoverlayMoveToPage{n}
% where n is an integer
% NOTE: The page will not actually be outputted
%       unless there is some text overlayed on it
    {test {\ifnumcomp{\value{pdfoverlay@page}}<{#1-1}}}

% Move through the PDF to the last page
% NOTE: Any further text will be output on the next page
    {test {\ifnumcomp{\value{pdfoverlay@page}}<{\pdfoverlay@pagecount-1}}}

% Toggle outputting the PDF

% Resume outputting the PDF

% Pause outputting the PDF

% Set page style to empty

  • It works very well! Commented Apr 4, 2018 at 7:51
  • I tested your package for a couple of days. It works smoothly. A minor comment if you decide to put it on CTAN. Adding \setcounter{page}{#1} to the definition of \pdfoverlaySetPage helps when you skip many pages of the original file (requires hyperref). Commented Apr 6, 2018 at 16:32
  • An even lesser comment: I find the names \pdfoverlaySetPage and \pdfoverlayMoveToPage counter-intuitive. What you really mean is\pdfoverlaySkipToPage and \pdfoverlayIncludeUptoPage or something like that. Commented Apr 6, 2018 at 16:57
  • @david-purton, If you are indeed the creator of pdfoverlay, first, thank you. Secondly there's a question I could use your help for here : tex.stackexchange.com/questions/615617/…
    – LMT-PhD
    Commented Sep 17, 2021 at 8:27

Assuming that your statement about scalability refers only to the fact that it is tedious and error prone to do it by hand and not to the efficiency on large pdf files, I propose you an idea that can be used to implement your own commands for your specific case.

In words, it is about taking advantage of a counter to keep track of which page was annotated and build a command that make an annotation on a given page, printing all the previous not annotated ones.

Disadvantage: You have to put the \makeAnnotation commands in order (with respect to the annotated page), but it should not be a big deal and I think you will do it anyway.



            \thePageOfPdf-\the\numexpr #1-1 \\
    annotate on #1 \\
    \addtocounter{PageOfPdf}{\numexpr #1-\thePageOfPdf}
    {\the\numexpr #1 +1}- \\


enter image description here

Few additional remarks:

  • The external if clause in the \makeAnnotation command is necessary in case you need to annotate the first page of your pdf file
  • The internal if clause, instead, is needed to avoid to print the range of unannotated pdf pages in case two following annotations are on consecutive pages
  • The \lastAnnotation command should print the remaining bunch of pages

And few more remarks:

  • Here I added later the etoolbox package for the if clauses; it is very powerful and it could be used to improve the code
  • It could be that there are additional cases I did not consider, but the main idea is here and you should be able to cope with them in case
  • Better ideas/approaches probably exist and feel free to suggest them :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .