I tried all the answers I could find about this topic, and can't get something to work.
This MWE works OK, but only in pdflatex, since \pdfximage do not work in lualatex.
\documentclass[12pt]{article}%
\usepackage{graphicx}
\begin{document}
\pdfximage{index.pdf}%
\the\pdflastximagepages
\end{document}
Answers in Get number of pages of external PDF
do not work, here is the code from the above link:
\documentclass{article}
\newcommand*{\pdfnumberofpages}[1]{%
\directlua{%
local doc = epdf.open("\luatexluaescapestring{#1}")
local pages
if (doc) then
pages = doc:getCatalog():getNumPages()
else
pages = 0
end
tex.write(pages)
}%
}
\begin{document}
Number of pages: \pdfnumberofpages{index.pdf}
\end{document}
Now, lulatex foo.tex gives
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size10.clo)) (./foo.aux)
! Undefined control sequence.
\pdfnumberofpages ...open("\luatexluaescapestring
{#1}") local pages if (doc...
l.17 Number of pages: \pdfnumberofpages{test.pdf}
What is the correct way to obtain the number of pdf pages of external PDF file using lualatex ?
Using TL 2019 on Linux.