Skip to content

Instantly share code, notes, and snippets.

@mogsdad
Created December 12, 2015 03:30
Show Gist options
  • Save mogsdad/e65826da9974650e2abc to your computer and use it in GitHub Desktop.
Save mogsdad/e65826da9974650e2abc to your computer and use it in GitHub Desktop.
Google Apps Script demo of new PositionedImages. See https://mogsdad.wordpress.com.
/**
* Demo of PositionedImages.
* From: gist.github.com/mogsdad/e65826da9974650e2abc
* See: stackoverflow.com/a/20661113/1677912
**/
function DemoPositionedImage() {
// Get handle on active document
var doc = DocumentApp.getActiveDocument();
// Find desired image file
var matchedFiles = DriveApp.getFilesByName('apple-touch-icon.png');
if (matchedFiles.hasNext()) {
// Get image object from file
var image = matchedFiles.next().getBlob();
// Add image as a PositionedImage.
var positionedImage = doc.getBody().getParagraphs()[0].addPositionedImage(image);
// Adjust layout, etc. here
// Log the ID of the new image
Logger.log( positionedImage.getId() );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment