PowerPoint Functions
Use the PowerPoint adapter functions to generate .pptx files from a template stored in your Epicenter project. The adapter populates the template's charts, tables, pictures, and text placeholders with data you supply, then returns the result either as encoded binary data or as a streaming HTTP response.
To learn more about generating a PowerPoint slide-deck from your Epicenter app, read the PowerPoint conceptual topic.
Importing the adapter
import { powerpointAdapter } from 'epicenter-libs';
The powerpointAdapter namespace exports functions that make calls to the PowerPoint API.
For descriptions of the objects used by the PowerPoint adapter functions, read PowerPoint Entities.
Generate a PowerPoint file
Generate as binary data
The generate() function renders a .pptx file from a template and returns the result as JSON-encoded binary data.
Use generate() when you need to store, re-encode, or further process the generated file in your application. To download the file directly in the browser, use stream() instead.
Permissions
Requires a role of FACILITATOR or higher.
Function description
The generate() function:
- Sends a
PUTrequest to/powerpoint/{TEMPLATE_DIRECTORY}/{TEMPLATE_PATH}. - Accepts a
DocumentShadowbody that defines the output filename, document-wide environment, and any per-slide overrides. - Returns the generated file as a
BinaryDataobject.
export async function generate(
templateDirectory: TemplateDirectory,
templatePath: string,
document: DocumentShadow,
optionals: RoutingOptions = {},
): Promise<BinaryData>
Parameters
templateDirectory(TemplateDirectory): The folder where the template is stored — either'DATA'or'MODEL'.templatePath(string): The path to the template file within the directory (for example,'en-US-debrief-template.pptx').document(DocumentShadow): The document definition, including:output?(string): The filename for the generated file.environment?(EnvironmentShadow): Document-wide parameters, charts, tables, and pictures.slides?(SlideShadow[]): Per-slide data overrides.
optionals(RoutingOptions, optional): Network and routing overrides.
Return value
A promise that resolves to a BinaryData object containing the generated PowerPoint file encoded as HEX or BASE_64.
Usage example
import { powerpointAdapter } from 'epicenter-libs';
const binaryData = await powerpointAdapter.generate(
'MODEL',
'en-US-debrief-template.pptx',
{
output: 'debrief-slides.pptx',
environment: {
parameters: { title: 'Q3 Debrief' },
},
slides: [
{
number: 1,
environment: {
tables: [
{
name: 'Leaderboard',
data: [
['Rank', 'Name', 'Score'],
[1, 'Alice', 980],
[2, 'Bob', 875],
],
},
],
},
},
{
number: 2,
environment: {
charts: [
{
name: 'ScoreChart',
categories: ['Alice', 'Bob'],
series: [
{ objectType: 'bar', name: 'Score', data: [{ n: 980 }, { n: 875 }] },
],
},
],
},
},
],
}
);
// binaryData.data contains the encoded .pptx content
console.log(binaryData.encoding); // 'BASE_64' or 'HEX'
Generate as a streaming response
The stream() function renders a .pptx file from a template and returns a raw Response object, allowing the file to be downloaded directly in the browser or piped to a file.
Use stream() when you want to offer users a direct file download. To receive the generated file as encoded data for further processing, use generate() instead.
Permissions
Requires a role of FACILITATOR or higher.
Function description
The stream() function:
- Sends a
POSTrequest directly to/powerpoint/{TEMPLATE_DIRECTORY}/{TEMPLATE_PATH}usingfetch, bypassing the standard Router in order to return the raw HTTP response. - Accepts a
DocumentShadowbody that defines the output filename, document-wide environment, and any per-slide overrides. - Automatically attaches the current session's authorization token unless
includeAuthorizationis set tofalseinoptionals. - Returns the raw
Responseobject, allowing callers to call.blob(),.arrayBuffer(), or.bodydirectly.
export async function stream(
templateDirectory: TemplateDirectory,
templatePath: string,
document: DocumentShadow,
optionals: RoutingOptions = {},
): Promise<Response>
Parameters
templateDirectory(TemplateDirectory): The folder where the template is stored — either'DATA'or'MODEL'.templatePath(string): The path to the template file within the directory (for example,'en-US-debrief-template.pptx').document(DocumentShadow): The document definition, including:output?(string): The filename for the generated file.environment?(EnvironmentShadow): Document-wide parameters, charts, tables, and pictures.slides?(SlideShadow[]): Per-slide data overrides.
optionals(RoutingOptions, optional): Network and routing overrides, includingserver,accountShortName,projectShortName,query,headers,authorization, andincludeAuthorization.
Return value
A promise that resolves to a native Response object. Call .blob() to obtain the file as a Blob for use with a download link, or .arrayBuffer() for binary processing.
Usage example
import { powerpointAdapter } from 'epicenter-libs';
// Generate and trigger a browser download
const response = await powerpointAdapter.stream(
'MODEL',
'en-US-debrief-template.pptx',
{
output: 'debrief-slides.pptx',
environment: {
parameters: { title: 'Q3 Debrief' },
},
slides: [],
}
);
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'debrief-slides.pptx';
link.click();
URL.revokeObjectURL(url);