Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Last active May 17, 2019 06:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tanaikech/c78087c647dc9b5547b580ccd3629974 to your computer and use it in GitHub Desktop.
Retrieving Total Page of Google Document using Google Apps Script

Retrieving Total Page of Google Document using Google Apps Script

This is a sample script for retrieving total page of Google Document using Google Apps Script. There are no methods for directly retrieving the total page of Google Document. This is one of several workarounds. In this workaround, the total page is retrieved by converting to PDF format.

var n =
  DriveApp.getFileById(id)
    .getBlob()
    .getDataAsString()
    .split("/Contents").length - 1;
Logger.log("totalPages: %s", n);
  • When you use this, please set the Google Document ID as id.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment