How do I know what pageSize I've got?
as the linked post in the topic says, it is a magic number, which means that you will need to try different values until some fits better. you can start with 1024 and increase or decrease the value depending on your machine.
Does document.height include header and footer?
no, standard header and footer are outside of the DOM so it won't be present in document.height. so this assumes that you won't use standard header of footer at all, but instead position some elements to emulate the same functionality.