1

I wanted to know how I can export the active slide on the presentation as a PDF. I was able to figure it out for google sheets but nothing for google slides.

Thank you!

3
  • Can I ask you about your question? 1. I cannot understand about I was able to figure it out for google sheets but nothing for google slides.. Can I ask you about the detail of it? 2. About exporting PDF, where do you want to export it? Commented Jun 25, 2020 at 22:11
  • Hi! Google sheets exports the entire workbook – so i was able to get the relevant sheet by hiding others, exporting, and then unhiding them. Couldn't find a similar hack for slides. For exporting, I'd like to export to a folder within the drive using the folder's ID. Commented Jun 25, 2020 at 23:21
  • Thank you for replying. From your replying, I proposed a sample script as an answer. Could you please confirm it? If I misunderstood your question and that was not the direction you expect, I apologize. Commented Jun 25, 2020 at 23:45

1 Answer 1

1

I believe your goal as follows.

  • You want to export the current active slide on Google Slides as a PDF file to the specific folder in Google Drive using Google Apps Script.

For this, how about this answer? In this answer, I use the following flow.

  1. Retrieve the active slide.
  2. Create a temporal Google Slides.
  3. Copy the active slide to the temporal Google Slides.
  4. Delete the initial slide in the temporal Google Slides.
  5. Export the temporal Google Slides as a PDF file.
  6. Delete the temporal Google Slides.

Sample script:

Please copy and paste the following script to the container-bound script of Google Slides. And, please open a slide in the Google Slide and run this script. By this, the PDF file of the active slide is created in the folder of destinationFolderId.

function myFunction() {
  const destinationFolderId = "###";  // Please set the destination folder ID.

  // 1. Retrieve the active slide.
  const s = SlidesApp.getActivePresentation();
  const activeSlide = s.getSelection().getCurrentPage().asSlide();

  // 2. Create a temporal Google Slides.
  const temporalSlides = SlidesApp.create("temporalSlides");

  // 3. Copy the active slide to the temporal Google Slides.
  temporalSlides.insertSlide(0, activeSlide);

  // 4. Delete the initial slide in the temporal Google Slides.
  temporalSlides.getSlides()[1].remove();
  temporalSlides.saveAndClose();

  // 5. Export the temporal Google Slides as a PDF file.
  const file = DriveApp.getFileById(temporalSlides.getId());
  DriveApp.getFolderById(destinationFolderId).createFile(file.getBlob().setName(`${s.getName()}.pdf`));

  // 6. Delete the temporal Google Slides.
  file.setTrashed(true);
}

References:

Sign up to request clarification or add additional context in comments.

2 Comments

Works perfectly! Thank you! I just replaced [const activeSlide = s.getSelection().getCurrentPage().asSlide();] with s.getSlides()[1];
@Nikhil Jain Thank you for your response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.