What is the best way to get the total number of pages in a document and insert in the document?

Yes, but you can optimize/simplify it like this:

#context counter(page).final().first()

The key part here is “sometimes”. This does not apply to your example, but does for this:

#context here().position()

image

1 Like