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

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?

share|improve this question
@Mathew wouldn't a simplistic solution be to insert a counter variable just before the includegraphics and after and get the difference? – Yiannis Lazarides Jan 5 '11 at 13:19
@Yiannis, the topic starter is @fillieule. :-) – xport Jan 5 '11 at 15:24
@xport Oops! yannis_was_sleeping! – Yiannis Lazarides Jan 6 '11 at 4:00
up vote 17 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.