Skip to main content

KSPowerPoint Reference

KSPowerPoint is the class to extend when your LWC component needs to read or write content in Microsoft PowerPoint. All methods are async and return when the PowerPoint operation completes.

Requirements:

  • Keelstone Pro plan
  • Keelstone PowerPoint Add-in open and connected in Microsoft PowerPoint

Import

import { KSPowerPoint } from 'kstone/api';

Slides

ksGetSlideCount()

Returns the total number of slides in the active presentation.

async ksGetSlideCount()Promise<{ count: number }>

ksAddSlide()

Appends a new blank slide to the end of the presentation.

async ksAddSlide()Promise<object>

ksDeleteSlide(slideIndex)

Deletes the slide at the specified index.

async ksDeleteSlide(slideIndex)Promise<object>
ParamTypeDescription
slideIndexnumberZero-based slide index

ksGetSlideText(slideIndex?)

Returns all text content from a slide, concatenated.

async ksGetSlideText(slideIndex = 0)Promise<string>

ksExportSlide(slideIndex)

Exports a slide as a base64-encoded image.

async ksExportSlide(slideIndex)Promise<{ base64: string }>

ksGetSlideImage(slideIndex, options?)

Returns a slide as a base64-encoded image with optional resolution and format settings.

async ksGetSlideImage(slideIndex, options = {})Promise<{ base64: string }>
ParamTypeDescription
slideIndexnumberZero-based slide index
options.formatstringImage format (default 'png')
options.widthnumberOutput width in pixels
options.heightnumberOutput height in pixels

ksInsertSlides(base64, sourceSlideIds?)

Inserts slides from a base64-encoded .pptx file into the active presentation.

async ksInsertSlides(base64, sourceSlideIds = [])Promise<object>
ParamTypeDefaultDescription
base64stringrequiredBase64-encoded .pptx file
sourceSlideIdsstring[][]Specific slide IDs to insert. Empty array inserts all slides.

Shapes

ksGetShapes(slideIndex?)

Returns all shapes on a slide.

async ksGetShapes(slideIndex = 0)Promise<{ name: string, type: string, text?: string }[]>
const shapes = await this.ksGetShapes(0);
// [{ name: 'Title 1', type: 'placeholder', text: 'Slide title' }, ...]

ksAddTextBox(slideIndex, text, options?)

Adds a text box to a slide.

async ksAddTextBox(slideIndex, text, options = {})Promise<object>
ParamTypeDescription
slideIndexnumberZero-based slide index
textstringText content
options.leftnumberLeft position in points
options.topnumberTop position in points
options.widthnumberWidth in points
options.heightnumberHeight in points
options.fontSizenumberFont size in points
options.boldbooleanBold text
options.colorstringFont colour as hex, e.g. '#032D60'

ksAddImage(slideIndex, base64, options?)

Adds an image to a slide.

async ksAddImage(slideIndex, base64, options = {})Promise<object>
ParamTypeDescription
slideIndexnumberZero-based slide index
base64stringBase64-encoded image (PNG, JPG, etc.)
options.leftnumberLeft position in points
options.topnumberTop position in points
options.widthnumberWidth in points
options.heightnumberHeight in points

ksSetShapeText(slideIndex, shapeName, text)

Replaces the text content of a named shape on a slide.

async ksSetShapeText(slideIndex, shapeName, text)Promise<object>
ParamTypeDescription
slideIndexnumberZero-based slide index
shapeNamestringName of the shape as shown in the Selection Pane
textstringNew text content
const shapes = await this.ksGetShapes(0);
const title = shapes.find(s => s.name === 'Title 1');
if (title) await this.ksSetShapeText(0, title.name, 'Updated Title');

ksDeleteShape(slideIndex, shapeName)

Deletes a named shape from a slide.

async ksDeleteShape(slideIndex, shapeName)Promise<object>

Slide tags

Slide tags are key/value strings stored in the presentation XML. They are not visible to end users and are useful for tracking metadata such as Salesforce record IDs or template versions.

ksAddTag(slideIndex, key, value)

Sets a tag on a slide.

async ksAddTag(slideIndex, key, value)Promise<object>

ksGetTags(slideIndex)

Returns all tags on a slide.

async ksGetTags(slideIndex)Promise<{ [key: string]: string }>

Presentation generation

ksGeneratePresentation(slides, options?)

Generates a fully formatted PowerPoint presentation server-side and inserts it into the open file.

async ksGeneratePresentation(slides, options = {})Promise<{ base64: string }>
ParamTypeDescription
slidesobject[]Array of slide definition objects — see POST /api/powerpoint/generate
options.footerstringFooter text shown on every slide
options.themeobjectColour overrides — see API reference
await this.ksGeneratePresentation(
[
{ type: 'cover', title: 'Acme Corp — Q3 Review', subtitle: 'Sales Operations' },
{ type: 'bullets', title: 'Pipeline', bullets: ['$2.1M open', '14 active deals'] },
],
{ footer: 'Confidential' }
);

See POST /api/powerpoint/generate for the full slide type reference.


Notes

ksGetNotes(slideIndex?)

Returns the speaker notes text for a slide.

async ksGetNotes(slideIndex = 0)Promise<{ notes: string }>

Requires PowerPoint API set 1.5 or later.


ksSetNotes(notes, slideIndex?)

Sets the speaker notes for a slide. Replaces existing notes.

async ksSetNotes(notes, slideIndex = 0)Promise<{ ok: true }>

Requires PowerPoint API set 1.5 or later.


Slide background

ksSetSlideBackground(color, slideIndex?)

Sets a solid colour background on a slide by inserting a full-slide rectangle named ks-background behind all other shapes. Calling this again replaces the previous background.

async ksSetSlideBackground(color, slideIndex = 0)Promise<{ ok: true }>
ParamTypeDescription
colorstringCSS hex colour, e.g. '#032D60'
slideIndexnumberZero-based slide index
await this.ksSetSlideBackground('#032D60');  // Salesforce dark navy
note

This method adds a shape rather than modifying the slide theme. If you need theme-level background changes, modify the PPTX XML directly using ksGetFile().


Shape formatting & positioning

ksFormatShape(slideIndex, shapeIdentifier, format)

Applies fill, border, and text formatting to a shape identified by name or index.

async ksFormatShape(slideIndex, shapeIdentifier, format)Promise<{ ok: true }>
ParamTypeDescription
slideIndexnumberZero-based slide index
shapeIdentifierstring | numberShape name (string) or index (number)
format.fillColorstringFill colour hex
format.lineColorstringBorder colour hex
format.lineWeightnumberBorder weight in points
format.lineVisiblebooleanShow or hide the border
format.fontColorstringText font colour hex
format.fontSizenumberText font size in points
format.boldbooleanBold text
format.italicbooleanItalic text
await this.ksFormatShape(0, 'Title 1', { bold: true, fontColor: '#FFFFFF', fillColor: '#032D60' });

ksResizeShape(slideIndex, shapeIdentifier, options)

Repositions or resizes a shape on a slide.

async ksResizeShape(slideIndex, shapeIdentifier, options)Promise<{ ok: true }>
options fieldTypeDescription
leftnumberLeft edge in points
topnumberTop edge in points
widthnumberWidth in points
heightnumberHeight in points

All fields are optional — only provided values are updated.


ksGetSelection()

Returns the shapes currently selected in the presentation.

async ksGetSelection()Promise<{ selection: { id: string, name: string, type: string, left: number, top: number, width: number, height: number }[] }>

Requires PowerPoint API set 1.5 or later.


Tables

ksAddTable(slideIndex, rows, columns, options?)

Adds a table shape to a slide.

async ksAddTable(slideIndex, rows, columns, options = {})Promise<{ ok: true }>
ParamTypeDefaultDescription
slideIndexnumber0Zero-based slide index
rowsnumberNumber of rows
columnsnumberNumber of columns
options.leftnumber72Left position in points
options.topnumber72Top position in points
options.widthnumber400Width in points
options.heightnumber200Height in points
options.valuesany[][]2D array to pre-populate table cells
await this.ksAddTable(0, 3, 4, {
left: 72, top: 144, width: 576, height: 200,
values: [
['Region', 'Q1', 'Q2', 'Q3'],
['AMER', '$1M', '$1.2M', '$1.4M'],
['EMEA', '$0.8M', '$0.9M', '$1M'],
]
});

Slide reordering

ksDuplicateSlide(slideIndex?)

Duplicates a slide and inserts the copy immediately after the original.

async ksDuplicateSlide(slideIndex?)Promise<{ ok: true }>

Requires PowerPoint API set 1.5 or later.


ksMoveSlide(fromIndex, toIndex)

Moves a slide to a new position. Other slides shift accordingly.

async ksMoveSlide(fromIndex, toIndex)Promise<{ ok: true }>

Requires PowerPoint API set 1.5 or later.


ksCall(endpoint, body?)

Low-level method inherited from DocumentAPI. Call this when you need to reach a server endpoint not covered by a named method.

async ksCall(endpoint, body = {})Promise<any>

Minimal example

import { KSPowerPoint } from 'kstone/api';
import { api, track } from 'lwc';
import getOpportunityData from '@salesforce/apex/OpportunityController.getData';

export default class SalesDeckBuilder extends KSPowerPoint {
@api keelstoneSessionId;
@api recordId;
@track status = '';

async handleGenerate() {
try {
const data = await getOpportunityData({ opportunityId: this.recordId });
await this.ksGeneratePresentation(
[
{ type: 'cover', title: data.name, subtitle: data.accountName },
{ type: 'bullets', title: 'Overview', bullets: [
`Stage: ${data.stageName}`,
`Amount: $${data.amount}`,
`Close Date: ${data.closeDate}`,
]},
],
{ footer: `Prepared ${new Date().toLocaleDateString()}` }
);
this.status = 'Deck inserted into PowerPoint.';
} catch (err) {
this.status = `Error: ${err.message}`;
}
}
}

Flow Wiring

Wire KeelstoneSessionId from the flow to your component's keelstoneSessionId property. See Flow Wiring.