Skip to content

Class: TsPptx ​

The runtime-agnostic entry: what a consumer gets from the bare pptx-ts specifier when neither the node nor the browser export condition resolves — Deno, Bun, edge workers. Node and browser consumers reach pptx-ts/node and pptx-ts/browser through those conditions without naming them, and get the same class backed by an adapter that can reach their host.

Authoring is identical on all three. The difference is only where the finished deck can go: write, stream and toParts hand the bytes back here as everywhere, while writeFile throws runtime/file-output-unavailable because there is no filesystem and no DOM to write to. Live-DOM tableToSlides is likewise absent — it is defined on the browser entry, and the DOM-agnostic form is the free tableToSlides on pptx-ts/html.

Extends ​

  • default

Constructors ​

Constructor ​

new TsPptx(): TsPptx

Returns ​

TsPptx

Overrides ​

PresentationCore.constructor

Accessors ​

author ​

Get Signature ​

get author(): string

Returns ​

string

Set Signature ​

set author(value): void

Parameters ​
ParameterType
valuestring
Returns ​

void

Inherited from ​

PresentationCore.author


company ​

Get Signature ​

get company(): string

Returns ​

string

Set Signature ​

set company(value): void

Parameters ​
ParameterType
valuestring
Returns ​

void

Inherited from ​

PresentationCore.company


firstSlideNum ​

Get Signature ​

get firstSlideNum(): number

Returns ​

number

Set Signature ​

set firstSlideNum(value): void

Parameters ​
ParameterType
valuenumber
Returns ​

void

Inherited from ​

PresentationCore.firstSlideNum


layout ​

Get Signature ​

get layout(): string

Returns ​

string

Set Signature ​

set layout(value): void

Parameters ​
ParameterType
valuestring | StandardLayout
Returns ​

void

Inherited from ​

PresentationCore.layout


presLayout ​

Get Signature ​

get presLayout(): PresLayout

Returns ​

PresLayout

Inherited from ​

PresentationCore.presLayout


revision ​

Get Signature ​

get revision(): string

Returns ​

string

Set Signature ​

set revision(value): void

Parameters ​
ParameterType
valuestring
Returns ​

void

Inherited from ​

PresentationCore.revision


rtlMode ​

Get Signature ​

get rtlMode(): boolean

Returns ​

boolean

Set Signature ​

set rtlMode(value): void

Parameters ​
ParameterType
valueboolean
Returns ​

void

Inherited from ​

PresentationCore.rtlMode


sections ​

Get Signature ​

get sections(): SectionProps[]

Returns ​

SectionProps[]

Inherited from ​

PresentationCore.sections


slideLayouts ​

Get Signature ​

get slideLayouts(): SlideLayout[]

Returns ​

SlideLayout[]

Inherited from ​

PresentationCore.slideLayouts


slides ​

Get Signature ​

get slides(): Slide[]

Returns ​

Slide[]

Inherited from ​

PresentationCore.slides


subject ​

Get Signature ​

get subject(): string

Returns ​

string

Set Signature ​

set subject(value): void

Parameters ​
ParameterType
valuestring
Returns ​

void

Inherited from ​

PresentationCore.subject


theme ​

Get Signature ​

get theme(): ThemeProps

Returns ​

ThemeProps

Set Signature ​

set theme(value): void

Parameters ​
ParameterType
valueThemeProps
Returns ​

void

Inherited from ​

PresentationCore.theme


title ​

Get Signature ​

get title(): string

Returns ​

string

Set Signature ​

set title(value): void

Parameters ​
ParameterType
valuestring
Returns ​

void

Inherited from ​

PresentationCore.title


version ​

Get Signature ​

get version(): string

Returns ​

string

Inherited from ​

PresentationCore.version

Methods ​

addSection() ​

addSection(section): void

Add a new Section to Presentation

Parameters ​

ParameterTypeDescription
sectionSectionPropssection properties

Returns ​

void

Example ​

ts
pptx.addSection({ title:'Charts' });

Inherited from ​

PresentationCore.addSection


addSlide() ​

addSlide(options?): Slide

Add a new Slide to Presentation

Parameters ​

ParameterTypeDescription
options?AddSlidePropsslide options

Returns ​

Slide

the new Slide

Inherited from ​

PresentationCore.addSlide


defineLayout() ​

defineLayout(layout): void

Create a custom Slide Layout in any size

Parameters ​

ParameterTypeDescription
layoutPresLayoutlayout properties

Returns ​

void

Example ​

ts
pptx.defineLayout({ name:'A3', width:16.5, height:11.7 });

Inherited from ​

PresentationCore.defineLayout


defineSlideMaster() ​

defineSlideMaster(props): void

Create a new slide master [layout] for the Presentation

Parameters ​

ParameterTypeDescription
propsSlideMasterPropslayout properties

Returns ​

void

Inherited from ​

PresentationCore.defineSlideMaster


embedFont() ​

embedFont(opts): Promise<void>

Embed a font face so the deck renders with it even on machines that do not have it installed. The whole face is embedded (not glyph-subset) under /ppt/fonts/ and wired into presentation.xml (p:embeddedFontLst + embedTrueTypeFonts="1"), exactly as PowerPoint's "Embed fonts in the file" does. Call once per face/weight you use.

The declared typeface MUST match the family name used in your run/fontFace typefaces (e.g. addText('hi', { fontFace: 'Silkscreen' })) or PowerPoint will not bind the embedded bytes to the text. Repeated calls with the same typeface and different style accumulate into one p:embeddedFont entry.

Font licensing is the caller's responsibility: the bytes are embedded as handed over; OS/2.fsType embedding-permission bits are not enforced.

Parameters ​

ParameterTypeDescription
opts{ data?: string | ArrayBuffer | Uint8Array<ArrayBufferLike>; path?: string; style?: "bold" | "regular" | "italic" | "boldItalic"; typeface: string; }font source + identity
opts.data?string | ArrayBuffer | Uint8Array<ArrayBufferLike>raw font bytes, or a base64 string (bare or a whole data: URL), in lieu of path. Unlike registerFontMetrics, a string here is never a path.
opts.path?stringfont file path (Node) or URL (web) to a .ttf/.otf
opts.style?"bold" | "regular" | "italic" | "boldItalic"face slot; defaults to 'regular'
opts.typefacestringfamily name as referenced by run/fontFace typefaces

Returns ​

Promise<void>

Examples ​

ts
await pptx.embedFont({ path: '/fonts/Silkscreen-Regular.ttf', typeface: 'Silkscreen' })
ts
await pptx.embedFont({ path: '/fonts/Silkscreen-Bold.ttf', typeface: 'Silkscreen', style: 'bold' })

Inherited from ​

PresentationCore.embedFont


extractSlides() ​

extractSlides(opts?): Promise<ExtractedSlides>

Author + serialize this presentation's slides as injectable descriptors, WITHOUT producing a .pptx package. Runs the same media-encode, placeholder backfill, and measured-fit passes write() uses, then serializes each slide body and resolves its image media to decoded bytes — so a loaded deck can splice the slides in via Presentation.appendSlides() (see pptx-ts/read) while keeping its own masters/layouts/theme byte-identical.

Returns the deck's slide size (EMU, for the destination size check) and one descriptor per authored slide. Charts, audio/video media, online media, and internal slide-to-slide hyperlinks are surfaced as descriptors alongside the serialized body — this method does not resolve them into a package; the append path consumes each descriptor to reserve the parts and rebuild the rel graph.

Parameters ​

ParameterType
opts{ onMediaError?: "placeholder" | "throw"; }
opts.onMediaError?"placeholder" | "throw"

Returns ​

Promise<ExtractedSlides>

Inherited from ​

PresentationCore.extractSlides


measureText() ​

measureText(text, opts): TextMeasurement

Measure how tall text wraps at a given width, using the same calibrated wrap model the export-time autofit bake uses — so a layout-time prediction matches the value fit:'shrink'/'resize' would bake. Synchronous: register the face's metrics first with TsPptx.registerFontMetrics (lookup is sync).

Lets a consumer size its own geometry before export — grow a card to fit its text, reflow a grid, or detect overflow at layout time. Heights err tall (conservative), so the returned height is ≥ what PowerPoint/LibreOffice render.

Parameters ​

ParameterTypeDescription
textstring | TextProps[]a string or run array (per-run options override the defaults in opts)
optsMeasureTextOptionswidth (inches), font size/face (points), and spacing

Returns ​

TextMeasurement

laid-out height + line count + fit helpers

Examples ​

ts
const m = pptx.measureText('Long heading…', { wIn: 3, fontSize: 18, fontFace: 'Aptos' })
ts
if (pptx.measureText(runs, { wIn, fontSize, fontFace }).heightIn > cardHeightIn) growCard()

Inherited from ​

PresentationCore.measureText


overflowsBox() ​

overflowsBox(text, opts): boolean

Convenience overflow check: true if text does not fit a box of inner size wIn×hIn (inches) at full size. Because the model errs tall, this is a conservative (slightly over-reporting) check — appropriate for a build-time warning, not a hard gate. An unmeasurable (unnamed theme-default) face reports false (no overflow) so the linter does not false-positive on faces it cannot measure.

Parameters ​

ParameterTypeDescription
textstring | TextProps[]a string or run array
optsOverflowBoxOptionsMeasureTextOptions plus the box inner height hIn

Returns ​

boolean

true if the text overflows the box

Inherited from ​

PresentationCore.overflowsBox


registerFontMetrics() ​

registerFontMetrics(face, source, opts?): Promise<void>

Register a font's metrics so fit:'shrink' and fit:'resize' text is measured at export time: 'shrink' bakes a real fontScale and 'resize' a real box height, so the text renders fitted in headless renderers and on plain file-open, with no manual edit/resize.

Without registered metrics, both write the bare flag (<a:normAutofit/> or <a:spAutoFit/>) that only PowerPoint recomputes on edit. Register the same face once per weight/style you use; bold/italic advances differ.

Font collections (.ttc/.otc, how MS Gothic, Yu Gothic, SimSun, Microsoft YaHei and Cambria ship on Windows) hold several fonts in one file, so one has to be chosen. With no font option, face is used as the selector, which is usually what you meant; a face that names no font in the collection throws rather than falling back to the first, since measuring the wrong member is invisible downstream. Pass font when the deck-side name differs from the name inside the file, and use listFontFaces from pptx-ts/measure to see what a file holds.

Parameters ​

ParameterTypeDescription
facestringfont family name as used in fontFace (e.g. 'Aptos')
sourcestring | ArrayBuffer | Uint8Array<ArrayBufferLike>font file path/URL (Node/web) or raw TTF/OTF/TTC bytes. A string is always a path or URL here; base64 text is embedFont's data, not this.
opts?{ bold?: boolean; font?: string | number; italic?: boolean; }variant flags (advances differ per weight/style) and collection selection
opts.bold?booleanthese are the bold advances
opts.font?string | numberwhich font inside a collection: 0-based index, or a name
opts.italic?booleanthese are the italic advances

Returns ​

Promise<void>

Examples ​

ts
await pptx.registerFontMetrics('Aptos', '/usr/share/fonts/Aptos.ttf')
ts
await pptx.registerFontMetrics('Aptos', aptosBoldBytes, { bold: true })
ts
await pptx.registerFontMetrics('MS PGothic', 'C:/Windows/Fonts/msgothic.ttc')
ts
await pptx.registerFontMetrics('Cambria Math', 'C:/Windows/Fonts/cambria.ttc', { font: 1 })

Inherited from ​

PresentationCore.registerFontMetrics


setCustomProperty() ​

setCustomProperty(name, value): void

Set a custom document property stored in docProps/custom.xml. Calling with the same name replaces the existing value.

Parameters ​

ParameterTypeDescription
namestringproperty name
valueCustomPropertyValuestring, integer/float number, boolean, or Date

Returns ​

void

Inherited from ​

PresentationCore.setCustomProperty


tableLayout() ​

tableLayout(rows, opts): TableLayoutResult

Compute the per-cell geometry of a table laid out at opts.x/y/w, without adding it to a slide — so a consumer can place images or shapes precisely over cells. Column widths (cell x/w) are exact, derived from the same logic the writer uses. Row heights (y/h) are exact when pinned by rowH (array or scalar) or table h; an auto-height row is estimated with the same conservative (tall) text model as TsPptx.measureText and flagged heightExact:false (register the cell font via TsPptx.registerFontMetrics for an exact estimate). Geometry is for a single, un-paginated table — autoPage paging is not modeled.

Parameters ​

ParameterTypeDescription
rowsTableRow[]the same rows passed to slide.addTable
optsTablePropsthe same table options (x, y, w, colW, rowH, h, …)

Returns ​

TableLayoutResult

per-cell rectangles (inches) plus overall table bounds

Example ​

ts
const g = pptx.tableLayout(rows, { x: 1, y: 1, w: 8, colW: [2, 3, 3] })
const c = g.cells.find(c => c.row === 0 && c.col === 2)
slide.addImage({ path: 'logo.png', x: c.xIn, y: c.yIn, w: c.wIn, h: c.hIn })

Inherited from ​

PresentationCore.tableLayout


toBytes() ​

toBytes(props?): Promise<Uint8Array<ArrayBufferLike>>

Export the current presentation as portable ZIP bytes. Unlike the former stream() method, this does not imply incremental output or convert the archive to a Node Buffer: package assembly is synchronous and the returned Uint8Array works unchanged in Node, browsers, and workers.

Parameters ​

ParameterTypeDescription
props?WriteBasePropsoutput properties

Returns ​

Promise<Uint8Array<ArrayBufferLike>>

complete .pptx archive bytes

Inherited from ​

PresentationCore.toBytes


toParts() ​

toParts(props?): Promise<PackagePart[]>

Assemble the current Presentation into its OOXML package parts WITHOUT zipping — the raw path → bytes contents write() would compress into the .pptx. Use this to stream parts into a custom container, inspect individual parts, or feed a pipeline that does its own archiving. To produce a real .pptx file, use write / writeFile instead.

The returned parts are byte-identical, per part, to what write() emits for the same deck, and their order is the package's emission order. Both are a stability-guaranteed observable contract: adding a new part in a later release is backward-compatible as long as existing part paths and their relative order do not shift; renaming or reordering an existing part is a breaking change. Each call returns fresh Uint8Array views over per-call buffers (a new assembly runs each time), so callers may retain or transfer them without defensive copying.

Parameters ​

ParameterTypeDescription
props?PartsPropsassembly options (onMediaError only; compression/output shape are zip concerns that do not apply to unzipped parts)

Returns ​

Promise<PackagePart[]>

the package parts in emission order

Inherited from ​

PresentationCore.toParts


write() ​

write(props?): Promise<string | ArrayBuffer | Uint8Array<ArrayBufferLike> | Blob>

Export the current Presentation as ZIP content with the selected type

Parameters ​

ParameterTypeDescription
props?WritePropsoutput properties

Returns ​

Promise<string | ArrayBuffer | Uint8Array<ArrayBufferLike> | Blob>

file content in selected type

Inherited from ​

PresentationCore.write


writeFile() ​

writeFile(props?): Promise<string>

Export the current Presentation. Write the generated presentation to disk (Node) or trigger a download (browser).

Parameters ​

ParameterTypeDescription
props?WriteFilePropsoutput file properties

Returns ​

Promise<string>

the presentation name

Inherited from ​

PresentationCore.writeFile