I use graphicx to include pages of a PDF file. I want to know in LaTeX how many pages are in the file. How to do this?

  • @Mathew wouldn't a simplistic solution be to insert a counter variable just before the includegraphics and after and get the difference?
    – yannisl
    Commented Jan 5, 2011 at 13:19
  • @Yiannis, the topic starter is @fillieule. :-) Commented Jan 5, 2011 at 15:24
  • @xport Oops! yannis_was_sleeping!
    – yannisl
    Commented Jan 6, 2011 at 4:00

1 Answer 1


pdfpages is obviously somehow able to get the number of pages of an included pdf. It does it with the pdftex primitive \pdflastximagepages. E.g.


Update 2022

There is also an expl3 function which works with all backends:


enter image description here

  • What about LuaLaTeX and XeLaTeX?
    – Skillmon
    Commented Jun 20, 2018 at 13:06

You must log in to answer this question.