Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sathishvj/2901d707872c2e79c660d39db5b5b39b to your computer and use it in GitHub Desktop.
Save sathishvj/2901d707872c2e79c660d39db5b5b39b to your computer and use it in GitHub Desktop.
Google Apps Script to Center Selection Horizontally and Vertically on the Slide
/**
* @OnlyCurrentDoc
*/
/**
* Create a open translate menu item.
* @param {Event} event The open event.
*/
function onOpen(event) {
SlidesApp.getUi().createAddonMenu()
.addItem('Align Selection Centrally on Slide', 'alignSelectedCentrallyOnSlide')
.addToUi();
}
/**
* Open the Add-on upon install.
* @param {Event} event The install event.
*/
function onInstall(event) {
onOpen(event);
}
function alignSelectedCentrallyOnSlide() {
var selection = SlidesApp.getActivePresentation().getSelection();
if (selection == null) {
return;
}
per = selection.getPageElementRange();
if (per == null) {
return;
}
pes = per.getPageElements();
if (pes == null || pes.length == 0) {
return;
}
pes.forEach(function(f, i) {
pes[i].alignOnPage(SlidesApp.AlignmentPosition.HORIZONTAL_CENTER);
pes[i].alignOnPage(SlidesApp.AlignmentPosition.VERTICAL_CENTER);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment