In Google Apps Script, how can I determine the amount of unused space on the final page of a Google Docs document? I attempted the following code, but it fails to provide the correct blank space measurement for the last page.
function calculateEmptySpace(documentContent) {
var topMargin = documentContent.getMarginTop();
var bottomMargin = documentContent.getMarginBottom();
var totalHeight = documentContent.getPageHeight() - topMargin - bottomMargin;
return totalHeight;
}