Dear community,
I would like to create a script that achieves the three steps:
- Some checks are performed, e.g. a) no two slides with the same title, b) checking for some certain titles are contained and if so, use a different slide for the table of contents.
- A PDF would be downloaded directly to the users Download folder.
- Ideally, a new menu item button would be created so that users can easily run the script.
Re 3: However, I tried using the following code and always get this error when running the code from Google App Script studio: Cannot call SlidesApp.getUi() from this context.
function onOpen() {
var ui = SlidesApp.getUi();
ui.createMenu('Custom Menu')
.addItem('Download PDF', 'downloadPDF')
.addToUi();
}
Re 2: Also, I tried using ChatGPT to come up with the code for downloading the PDF and also get the error "
Cannot call SlidesApp.getUi() from this context." for this:
function downloadPDF() {
const presentationId = 'XXX'; // Replace with your presentation ID
const presentation = SlidesApp.openById(presentationId);
// Export the entire presentation as PDF
const pdfBlob = DriveApp.getFileById(presentationId).getAs('application/pdf');
const pdfFile = DriveApp.createFile(pdfBlob).setName('presentation.pdf');
const pdfUrl = pdfFile.getUrl();
const htmlOutput = HtmlService.createHtmlOutput(`<a href="${pdfUrl}" download>Download PDF</a>`);
SlidesApp.getUi().showModalDialog(htmlOutput, 'Download PDF');
presentation.saveAndClose();
}
Do you have any ideas how to fix these issues? I am new to Google Apps Script so any help would be much appreciated!
Many thanks!