id: powerpoint-create-presentation
name: Create presentation
description: Creates a new, empty presentation and creates a new presentation by copying an existing one.
author: OfficeDev
host: POWERPOINT
api_set:
PowerPointApi: '1.1'
script:
content: |-
document.getElementById("create-new-blank-presentation").addEventListener("click", () => tryCatch(createBlankPresentation));
document.getElementById("file").addEventListener("change", () => tryCatch(createPresentationFromExisting));
function createBlankPresentation() {
PowerPoint.createPresentation();
}
function createPresentationFromExisting() {
const myFile = document.getElementById("file") as HTMLInputElement;
const reader = new FileReader();
reader.onload = (event) => {
// Remove the metadata before the Base64-encoded string.
const startIndex = reader.result.toString().indexOf("base64,");
const copyBase64 = reader.result.toString().substr(startIndex + 7);
PowerPoint.createPresentation(copyBase64);
};
// Read in the file as a data URL so we can parse the Base64-encoded string.
reader.readAsDataURL(myFile.files[0]);
}
/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
}
}
language: typescript
template:
content: |-
This sample shows how to create a new, empty presentation and how to create a new presentation by copying an existing one.
Try it out
Create empty presentation
Copy existing presentation
Select a PowerPoint presentation to copy and open in a new instance of PowerPoint.