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?
Asked
Active
Viewed 762 times
14
Martin Scharrer
- 262,582
-
@Mathew wouldn't a simplistic solution be to insert a counter variable just before the includegraphics and after and get the difference? – yannisl Jan 05 '11 at 13:19
-
@Yiannis, the topic starter is @fillieule. :-) – Display Name Jan 05 '11 at 15:24
-
@xport Oops! yannis_was_sleeping! – yannisl Jan 06 '11 at 04:00
1 Answers
21
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.
\documentclass{article}
\begin{document}
\pdfximage{test.pdf}%
\the\pdflastximagepages
\end{document}
Update 2022
There is also an expl3 function which works with all backends:
\documentclass{article}
\usepackage{l3graphics}
\begin{document}
\ExplSyntaxOn
\graphics_get_pagecount:nN{example-image-duck.pdf}\l_tmpa_tl
\l_tmpa_tl
\ExplSyntaxOff
\end{document}
Ulrike Fischer
- 327,261
