Creating and Managing Presentations

This page describes how to perform certain high-level tasks involving presentations such as:

  • Create a new presentation
  • Copy an existing presentation

The following paragraphs describe these tasks in detail.

Creating a blank presentation

To create a new presentation, use the create method on the presentations collection, as shown in the following example. This example creates a blank presentation with a specified title.

Apps Script

slides/api/Snippets.gs
var presentation = Slides.Presentations.create({
  title: title
});
console.log('Created presentation with ID: %s', presentation.presentationId);

Go

slides/snippets/presentations.go
// Create a presentation and request a PresentationId.
p := &slides.Presentation{
	Title: "Title",
}
presentation, err := slidesService.Presentations.Create(p).Fields(
	"presentationId",
).Do()
if err != nil {
	log.Fatalf("Unable to create presentation. %v", err)
}
fmt.Printf("Created presentation with ID: %s", presentation.PresentationId)

Java

slides/snippets/src/main/java/Snippets.java
Presentation presentation = new Presentation()
        .setTitle(title);
presentation = slidesService.presentations().create(presentation)
        .setFields("presentationId")
        .execute();
System.out.println("Created presentation with ID: " + presentation.getPresentationId());

JavaScript

slides/snippets/snippets.js
gapi.client.slides.presentations.create({
  title: title
}).then((response) => {
  console.log(`Created presentation with ID: ${response.result.presentationId}`);
});

Node.js

slides/snippets/snippets.js
this.slidesService.presentations.create({
  title,
}, (err, presentation) => {
  console.log(`Created presentation with ID: ${presentation.presentationId}`);
});

PHP

slides/snippets/src/SlidesSnippets.php
<?php
$presentation = new Google_Service_Slides_Presentation(array(
    'title' => $title
));

$presentation = $slidesService->presentations->create($presentation);
printf("Created presentation with ID: %s\n", $presentation->presentationId);

Python

slides/snippets/slides_snippets.py
body = {
    'title': title
}
presentation = slides_service.presentations() \
    .create(body=body).execute()
print('Created presentation with ID: {0}'.format(
    presentation.get('presentationId')))

Ruby

slides/snippets/lib/file_snippets.rb
body = Google::Apis::SlidesV1::Presentation.new
body.title = title
presentation = slides_service.create_presentation(body)
puts "Created presentation with ID: #{presentation.presentation_id}"

Copying an existing presentation

To copy a presentation, use the Google Drive API's files().copy method.

The following example copies an existing presentation, using a provided string for both the presentation title and the name of the new drive file.

Apps Script

slides/api/Snippets.gs
var copyFile = {
  title: copyTitle,
  parents: [{id: 'root'}]
};
copyFile = Drive.Files.copy(copyFile, presentationId);
var presentationCopyId = copyFile.id;

Go

slides/snippets/presentations.go
// Copy a presentation.
file := drive.File{
	Title: title,
}
presentationCopyFile, err := driveService.Files.Copy(id, &file).Do()
if err != nil {
	log.Fatalf("Unable to copy presentation. %v", err)
}
presentationCopyId := presentationCopyFile.Id

Java

slides/snippets/src/main/java/Snippets.java
File copyMetadata = new File().setName(copyTitle);
File presentationCopyFile =
        driveService.files().copy(presentationId, copyMetadata).execute();
String presentationCopyId = presentationCopyFile.getId();

JavaScript

slides/snippets/snippets.js
var request = {
  name: copyTitle
};
gapi.client.drive.files.copy({
  fileId: presentationId,
  resource: request
}).then((driveResponse) => {
  var presentationCopyId = driveResponse.result.id;
});

Node.js

slides/snippets/snippets.js
let request = {
  name: copyTitle,
};
this.driveService.files.copy({
  fileId: presentationId,
  resource: request,
}, (err, driveResponse) => {
  let presentationCopyId = driveResponse.id;
});

PHP

slides/snippets/src/SlidesSnippets.php
<?php
$copy = new Google_Service_Drive_DriveFile(array(
    'name' => $copyTitle
));
$driveResponse = $driveService->files->copy($presentationId, $copy);
$presentationCopyId = $driveResponse->id;

Python

slides/snippets/slides_snippets.py
body = {
    'name': copy_title
}
drive_response = drive_service.files().copy(
    fileId=presentation_id, body=body).execute()
presentation_copy_id = drive_response.get('id')

Ruby

slides/snippets/lib/file_snippets.rb
body = Google::Apis::SlidesV1::Presentation.new
body.title = copy_title
drive_response = drive_service.copy_file(presentation_id, body)
puts drive_response
presentation_copy_id = drive_response.id

Note that you need to use an appropriate Drive API scope to make this call.