Skip to content

Instantly share code, notes, and snippets.

@msbarry
Last active September 18, 2023 11:55
  • 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
Embed
What would you like to do?
Google App Script to create a doc with speaker notes from slides
var INPUT_PRESO_ID = "<id>";
var OUTPUT_DOC_ID = "<id>";
function createNotesDoc() {
var presentation = Slides.Presentations.get(INPUT_PRESO_ID)
var out = DocumentApp.openById(OUTPUT_DOC_ID)
out.getBody().clear();
table = out.getBody().appendTable();
var links = [];
for (var i = 0; i < presentation.slides.length; i++) {
Logger.log("Exporting page " + (i + 1) + "/" + presentation.slides.length);
var slide = presentation.slides[i];
var text = slide.slideProperties.notesPage.pageElements[1].shape.text;
var row = table.appendTableRow();
var url = "https://docs.google.com/presentation/d/" + INPUT_PRESO_ID + "/export/png?id=" + INPUT_PRESO_ID + "&pageid=" + slide.objectId;
var imageCell = row.appendTableCell();
imageCell.removeChild(imageCell.getChild(0)); // remove empty first paragraph
imageCell.appendImage(UrlFetchApp.fetch(url).getBlob()).setWidth(160).setHeight(90);
var noteCell = row.appendTableCell();
noteCell.removeChild(noteCell.getChild(0)); // remove empty first paragraph
table.setColumnWidth(0, 140);
var noteParagraph = noteCell.appendParagraph("");
if (text) {
var textElements = text.textElements;
var fullContent = "";
for (var j = 0; j < textElements.length; j++) {
if (textElements[j].textRun) {
fullContent += textElements[j].textRun.content;
}
}
if (fullContent.trim()) {
noteParagraph.appendText(fullContent.trim());
}
}
}
}
@jenarehorka
Copy link

Hello,
thank you for sharing your code. I'm trying to use your script but getting following error message.

Exception: Invalid image data.

If I comment out the section about image all works fine. So maybe there is any new update in app script reg images? Or should I include any other service in appscript?

Thank for your help

Jan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment