I wish to insert all pages of myFigures.pdf in a row with:

\foreach \i in {1,...,6} {%

How do I make this code adaptive to the actual number of pages in .pdf file, which may be more or less than 6 one day? I am looking for something like:

% How to retrieve that information?

\foreach \i in {1,...,\nbPages} {%
  • 1
    you can use \includepdf from the pdfpages package to include the whole file Jan 17 '17 at 13:54
  • @DavidCarlisle The truth is that I need to include them on differents slides in a tikz / beamer, with something like \foreach \i in {1,...,\nbPages} {\node<\i> at \myCoords{\i} {\includegraphics[page=\i]{myFigures.pdf}};}. Would \includepdf really help then? I just need \nbPages.
    – iago-lito
    Jan 17 '17 at 14:52
  • 1
  • @UlrikeFischer Yes! This is what I needed, thanks :)
    – iago-lito
    Jan 17 '17 at 17:39

pdftex has the following primitive to return the page count (from the manual, page 34)

\pdflastximagepages (read--only integer)

This read--only register returns the highest page number from a file previously accessed via the \pdfximage command. This is useful only for pdf files; it always returns 1 for png, jpeg, or jbig2 files.

It might be easier to look at the usage in the pdfpages and see how it uses its last key, but this is the basic primitive.

In a nutshell, the command you miss is:


see this post.

  • Yeah.. so, once I have retrieved this read--only integer with \def\nbp{\pdfximage{myFigures.pdf}\pdfrefximage\pdflastximagepages}, how may I use it as an actual number? Using it in {1,...,\nbp} leads to Missing number. Using it as plain text in plain \LaTeX \nbp{} text produces.. a little book icon?! .. I am still missing \def\nbPages{\THISCOMMAND{\nbp}}.
    – iago-lito
    Jan 17 '17 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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