Unfortunately, the browsers have still very poor support for CSS-paged media.
So we typically solve such problems as you describe with pdf utils or with javascript.
Here is an example of how you can make the footer on the last page different.
https://playground.jsreport.net/w/anon/h3amrdZK
The first-page header content could be just moved to the main content to avoid problems with different header sizes.
Hopefully this helps.