Skip to content

PPTX API ​

PPTX APIs are called through the app returned by widget.render():

ts
const { widget } = await OfficeSdk.openfile({ docId: "demo-pptx", fileName: "demo.pptx", file });
const app = await widget.mount("#office-container").render();

Components ​

ComponentDescription
DocumentPage number, zoom, layout, export, and read-only state
ParagraphText font, color, size, bold, italic, underline, strikethrough, and horizontal paragraph alignment
TextBoxText box vertical alignment
PlayerSlide playback and full-screen playback
SelectionSelection type, text style queries, and selection change events
ViewerCurrent active target in the thumbnail area
UndoRedoUndo, redo, and availability state

Quick Example ​

ts
app.Document.setZoom(120);
app.Document.goToSlide(2);

app.Paragraph.setFontName("Arial");
app.Paragraph.setBold(true);
app.Paragraph.setAlignment(2);

app.TextBox.setVerticalAlignment(1);
app.Player.play(1);

Event example:

ts
function onSelectionChange(info) {
  console.log(info.selectType);
}

app.Selection.addEventListener("SELECTION_CHANGE", onSelectionChange);

Document ​

MethodSignatureReturnsDescription
getSlideInfo(): { total: number; current: number }{ total; current }Gets total slide count and current slide. Page numbers start from 1.
getCurrentSlideIndex(): numbernumberGets current page number. Page numbers start from 1.
getSlideCount(): numbernumberGets total slide count.
getZoom(): numbernumberGets zoom percentage.
setZoom(value: number): voidvoidSets zoom percentage. Common values include 80, 100, and 120.
autoZoom(): voidvoidAdjusts the zoom automatically.
focusEditor(): voidvoidCurrently a no-op in the PPTX implementation.
updateVisibleArea(): voidvoidRecalculates the visible area.
goToSlide(slideNum: number): voidvoidGoes to a slide. slideNum starts from 1.
deleteSlides(slides?: number[]): voidvoidDeletes specified slide indexes. If omitted, deletes the currently selected slide. slides uses zero-based indexes.
addSlide(layout?: SlideLayoutRef, position?: number): voidvoidInserts a new slide. layout uses layout indexes, and position is the zero-based insert position. If layout is omitted, the layout near the current selection is reused.
getSlideLayouts(force?: boolean): SlideLayoutItem[][]SlideLayoutItem[][]Gets layouts grouped by slide master. When force = true, refreshes the cache.
exportDocument(): Promise<void>Promise<void>Exports the original PPTX file.
exportPdf(printOptions?: unknown): Promise<void>Promise<void>Exports PDF with print options.
copy(): Promise<void>Promise<void>Copies the current selection.
cut(): Promise<void>Promise<void>Cuts the current selection.
paste(): Promise<void>Promise<void>Pastes into the current selection.
getColorPalette(): { theme: unknown[]; standard: unknown[] }{ theme; standard }Gets theme colors and standard colors.
startReadOnly(): voidvoidEnters read-only state.
endReadOnly(): voidvoidExits read-only state.
isReadOnly(): booleanbooleanWhether the current state is read-only.
isDisable(): booleanbooleanWhether the current editor is disabled.
ts
type SlideLayoutRef = {
  masterIndex: number;
  layoutIndex: number;
};

type SlideLayoutItem = {
  img: unknown;
  name: string;
  xmlName: string;
  id: string | number;
  layoutIndex: number;
  slideMasterIndex: number;
};

goToSlide(slideNum) uses display page numbers starting from 1; deleteSlides(slides) and addSlide(layout, position) use zero-based underlying indexes.

Document example:

ts
const pages = app.Document.getSlideInfo();
console.log(pages.current, pages.total);

app.Document.goToSlide(1);
const layoutGroups = app.Document.getSlideLayouts();
const layout = layoutGroups[0][0];
app.Document.addSlide(
  {
    masterIndex: layout.slideMasterIndex,
    layoutIndex: layout.layoutIndex
  },
  1
);
app.Document.deleteSlides([0]);

await app.Document.exportDocument();
await app.Document.exportPdf();

Document component events:

Event NamePayloadDescription
DOCUMENT_READYRaw event parametersDocument ready.
DOCUMENT_EXPORT_READYRaw event parametersExport completed.
DOCUMENT_EDITING_ENABLEDNoneThe document entered editable state.
DOCUMENT_EDITING_DISABLEDNoneThe document exited editable state.
PPTX_SLIDES_CHANGED(currentPage: number, totalPages: number)Current page or page count changed.
PPTX_ZOOM_CHANGE(zoom: number)Zoom changed.
PPTX_FIRST_PAGE_LOADEDNoneFirst page loaded.
PPTX_START_LOADINGNoneLoading started.

exportPdf(...) requires a secure context (normally HTTPS or localhost), window.queryLocalFonts, and permission to access local fonts. If these requirements are not met, the current implementation does not perform the PDF export.

Paragraph ​

MethodSignatureReturnsDescription
setFontName(value: string): voidvoidSets font family.
setFontColor(value: string | { hex: string; [key: string]: unknown }): voidvoidSets font color. Prefer an object containing hex; the current string parser has a known limitation when any color channel is 0.
setFontSize(value: number | string): voidvoidSets font size.
setBold(value: boolean): voidvoidSets bold.
setItalic(value: boolean): voidvoidSets italic.
setUnderline(value: boolean): voidvoidSets underline.
setStrikeThrough(value: boolean): voidvoidSets strikethrough.
setAlignment(value: 0 | 1 | 2 | 3 | 4): voidvoidSets horizontal paragraph alignment.
decreaseFontSize(): voidvoidDecreases font size.
increaseFontSize(): voidvoidIncreases font size.

setAlignment(value) enum:

ValueDescription
0Right
1Left
2Center
3Justified
4Distributed

Paragraph example:

ts
app.Paragraph.setFontName("Microsoft YaHei");
app.Paragraph.setFontColor({ hex: "#4472C4" });
app.Paragraph.setFontSize(18);
app.Paragraph.setBold(true);
app.Paragraph.setItalic(false);
app.Paragraph.setUnderline(true);
app.Paragraph.setStrikeThrough(false);
app.Paragraph.setAlignment(2);
app.Paragraph.increaseFontSize();

TextBox ​

MethodSignatureReturnsDescription
setVerticalAlignment(value: 0 | 1 | 2 | 3 | 4): voidvoidSets text box vertical alignment.

setVerticalAlignment(value) enum:

ValueDescription
0Top
1Center
2Bottom
3Justified distribution
4Distributed

Example:

ts
app.TextBox.setVerticalAlignment(1);

Player ​

MethodSignatureReturnsDescription
playFirst(): voidvoidPlays from the first slide.
playLast(): voidvoidPlays the last slide.
play(fromType: 1 | 2): voidvoidStarts slide playback.
playPrevious(): voidvoidPlays the previous slide.
playNext(): voidvoidPlays the next slide.
enterFullScreen(fromType: 1 | 2): voidvoidEnters full-screen playback.
exitFullScreen(): voidvoidExits full screen.

fromType:

ValueDescription
1From beginning
2From current slide

Example:

ts
app.Player.play(2);
app.Player.enterFullScreen(1);
app.Player.exitFullScreen();

Selection ​

MethodSignatureReturnsDescription
isTextSelected(): booleanbooleanWhether text is currently selected.
isTableSelected(): booleanbooleanWhether a table is currently selected.
isShapeSelected(): booleanbooleanWhether a shape is currently selected.
isSmartArtSelected(): booleanbooleanWhether SmartArt is currently selected.
isChartSelected(): booleanbooleanWhether a chart is currently selected.
isUnderline(): booleanbooleanWhether the current text has single underline.
isStrikeThrough(): booleanbooleanWhether the current text has single strikethrough.
getFontSize(): stringstringGets current font size. For mixed font sizes, returns the minimum font size plus +.
getFontName(): string | nullstring | nullGets current font family. For mixed fonts, returns an empty string.
isBold(): boolean | 0 | nullboolean | 0 | nullGets bold state. Returns 0 for mixed states.
isItalic(): boolean | 0 | nullboolean | 0 | nullGets italic state. Returns 0 for mixed states.
getFontColor(): stringstringGets font color as an rgba(...) string. The alpha value comes from underlying data and must not be assumed to be CSS-normalized to 0 through 1.
getAlignment(): "default" | "right" | "left" | "center" | "justify" | "distribute" | "nil"stringGets horizontal paragraph alignment.
getVerticalAlignment(): "top" | "center" | "bottom" | "default" | "NIL" | undefinedstring | undefinedGets text box vertical alignment.

Selection example:

ts
if (app.Selection.isTextSelected()) {
  console.log(app.Selection.getFontName());
  console.log(app.Selection.getFontColor());
}

getAlignment() return values:

ValueDescription
"default"Default alignment.
"right"Right.
"left"Left.
"center"Center.
"justify"Justified.
"distribute"Distributed.
"nil"Multiple selected contents do not share one horizontal alignment value.

getVerticalAlignment() return values:

ValueDescription
"top"Top.
"center"Center.
"bottom"Bottom.
"default"Default vertical alignment.
"NIL"Multiple selected contents do not share one vertical alignment value.
undefinedNo recognizable vertical alignment value currently.

Selection component events:

Event NamePayload
SELECTION_CHANGEPptxSelectionChange
ts
type PptxSelectionChange = {
  selectType: number;
  bold?: boolean | 0 | null;
  italic?: boolean | 0 | null;
  fontName?: string | null;
  fontSize?: string;
  fontColor?: string;
  underline?: boolean;
  strikeout?: boolean;
  alignHorizontal?: string;
  alignVertical?: string;
  canCopy: boolean;
};

selectType is a bit flag and can be combined with bitwise OR:

ValueDescription
0No stable selection
1Table
2Shape
4Text
6Shape + text
8SmartArt
16Chart
32Image

Common combined values:

ValueDescription
6Shape + text

Viewer ​

MethodSignatureReturnsDescription
getActiveZoom(): null | "" | "Thumbnail" | "ThumbnailGapLine"string | nullGets the current active target in the thumbnail area. Returns null before the first active-target event.

Return values:

ValueDescription
nullNo active-target event has been received yet.
""No stable target currently.
"Thumbnail"Thumbnail.
"ThumbnailGapLine"Gap line between thumbnails.

UndoRedo ​

MethodSignatureReturnsDescription
undo(): voidvoidUndo.
redo(): voidvoidRedo.
canUndo(): booleanbooleanWhether undo is available.
canRedo(): booleanbooleanWhether redo is available.

UndoRedo component events:

Event NamePayload
UNDO_REDO_STATE_CHANGERaw event parameters

Example:

ts
if (app.UndoRedo.canUndo()) {
  app.UndoRedo.undo();
}