Skip to content

Instantly share code, notes, and snippets.

@michaelos02
Created November 30, 2019 20:29
Show Gist options
  • Save michaelos02/ba2ecb9d50c4a4a6019351856dde3018 to your computer and use it in GitHub Desktop.
Save michaelos02/ba2ecb9d50c4a4a6019351856dde3018 to your computer and use it in GitHub Desktop.
Counting Pages in Google Doc - can't be done BUT if you make it a PDF you can. Here is link: https://stackoverflow.com/questions/36432487/how-to-get-the-number-of-pages-in-google-docs-via-google-script
function getNumPages() {
var blob = DocumentApp.getActiveDocument().getAs("application/pdf");
var data = blob.getDataAsString();
var pages = parseInt(data.match(/ \/N (\d+) /)[1], 10);
Logger.log("pages = " + pages);
return pages;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment