If the total number of PDF pages is not known, it is a bit tricky.

tag supports scope attribute to define a page scope, where particular footer definition is supposed to go. For example scope=”2+,skiplast” There is a reason, why “skiplast” option is supported, but “lastpage” option is not.

See html-pdf-faq-f1/scope-lastpage-t356.html for brief explanation and a workaround.