How to get number of pages of external pdf file in Lualatex?

The epdf library (based on poppler) has been replaced by the pdfe library (based on pplib). Further you did not define \luatexluaescapestring, you must have meant \luaescapestring.

\documentclass{article}

\newcommand*{\pdfnumberofpages}[1]{%
  \directlua{%
    local pages = 0
    local doc = pdfe.open("\luaescapestring{#1}")
    if doc then
      pages = pdfe.getnofpages(doc)
      pdfe.close(doc)
    end
    tex.write(pages)
  }%
}

\begin{document}
Number of pages: \pdfnumberofpages{index.pdf}
\end{document}

The pdftex primitives are not gone, they have only been renamed: \pdfximage is \saveimageresource, and \pdflastximagepages is \lastsavedimageresourcepages. So:

\documentclass[12pt]{article}%
\usepackage{graphicx}
\begin{document}
\saveimageresource{index.pdf}%
\the\lastsavedimageresourcepages
\end{document}

Or you could load the luatex85 package, and then use the pdftex primitives, so that the document compiles with both pdflatex and lualatex.

Tags:

Pdf

Luatex