For HTML headers footer.setAreaHeight(-1) forces to allocate footer (or header) space, depending on an actual header height. The auto-computed height cannot change from page to page.

By inline header/footer definition (like ) it can auto-compute header/footer height as well as change the allocated header space if header definition changes from page to page.

If you do need an exact numeric height (in pixels) of a particular portion of HTML content, you may instantiate PD4ML, perform a dummy conversion of HTML portion to PDF and request the document height: