I am attempting to get the total number of pages of an external PDF document as a lua variable through


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

However, when i call the lua code, the returned value is nil.

token.get_macro('lastsavedimageresourcepages') returns nil

I also tried tex.count['lastsavedimageresourcepages'] but it throws an error.

  • 1
    \directlua{tex.print(tex.lastsavedimageresourcepages)} Commented Oct 10, 2023 at 19:10

1 Answer 1


You want


to access the value from Lua

  • Thank you. Is there a function like tex.saveimageresource also? The luatex manual does not seem to make this clear. Commented Oct 10, 2023 at 20:01
  • @likethevegetable I think that's img.write(img.scan{ file = "foo.pdf" }) (luatex manual section 11.1.8) Commented Oct 10, 2023 at 20:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .