FPresentation
The facade class for a presentation.
Access
Access through:
FUniver.createPresentation()FUniver.getActivePresentation()FUniver.getPresentation()FUniver.getSlideCommandTarget()FCollaboration.loadSlideAsync()
Setup
Register @univerjs-pro/slides or a preset that includes it. In plugin mode, import @univerjs-pro/slides/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs-pro/slides
FPresentation.appendSlide
Append a new slide to the end of the presentation.
appendSlide(options?: Partial<ISlidePage>): FSlideParameters
options— Optional. Default:{}. The slide creation options.
Returns
The created slide.
Examples
const fPresentation = univerAPI.getActivePresentation()const slide = fPresentation.appendSlide({ name: 'Summary' })console.log(slide)Types: FSlide · Partial · ISlidePage
Package: @univerjs-pro/slides · Type definitions
FPresentation.applyTransitionToAll
Apply a slide transition to all slides that currently exist in the presentation.
The transition is visible during slide playback when moving between slides. Slides added after this call are not automatically assigned this transition; call this method again if newly added slides should use the same transition.
applyTransitionToAll(transition: ISlideTransition): thisParameters
transition— Required. The slide transition to apply.
Returns
This presentation, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()fPresentation.applyTransitionToAll({ type: univerAPI.Enum.SlideTransitionTypeEnum.Push, duration: 1000, direction: univerAPI.Enum.SlideTransitionDirectionEnum.Right,})Types: ISlideTransition
Package: @univerjs-pro/slides · Type definitions
FPresentation.clearPresentationBackgroundGraphics
Clear managed presentation background graphics.
clearPresentationBackgroundGraphics(options?: ISetPresentationBackgroundGraphicsOptions): thisParameters
options— Optional. Target master options.
Returns
This presentation, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()fPresentation.clearPresentationBackgroundGraphics({ target: univerAPI.Enum.SlidePresentationBackgroundGraphicsTargetEnum.ActiveMaster,})Types: ISetPresentationBackgroundGraphicsOptions
Package: @univerjs-pro/slides · Type definitions
FPresentation.deleteSlide
Delete a slide.
deleteSlide(slide: FSlide): booleanParameters
slide— Required. The slide facade or slide id to delete.
Returns
Whether the slide was deleted successfully.
Examples
const fPresentation = univerAPI.getActivePresentation()const slide = fPresentation.getSlideByIndex(1)if (slide) { fPresentation.deleteSlide(slide)}Types: FSlide
Package: @univerjs-pro/slides · Type definitions
FPresentation.getActiveSlide
Get the active slide.
getActiveSlide(): FSlide | nullReturns
The active slide, or null if no slide is active.
Examples
const fPresentation = univerAPI.getActivePresentation()const activeSlide = fPresentation.getActiveSlide()console.log(activeSlide)Types: FSlide
Package: @univerjs-pro/slides · Type definitions
FPresentation.getId
Get the presentation id.
getId(): stringReturns
The presentation id.
Examples
const fPresentation = univerAPI.getActivePresentation()console.log(fPresentation.getId())Package: @univerjs-pro/slides · Type definitions
FPresentation.getMasterElementPermission
Returns an Element permission facade for a Master or Layout page.
getMasterElementPermission(sourcePageType: PageTypeEnum.Master | PageTypeEnum.Layout, pageId: string, elementId: string): FSlideObjectPermissionParameters
sourcePageType— Required. Whether the element belongs to a Master or Layout page.pageId— Required. Stable source page id.elementId— Required. Stable element id.
Returns
Permission facade combining Presentation, Master View, and Element Edit points.
Examples
import { PageTypeEnum } from '@univerjs-pro/slides'const presentation = univerAPI.getActivePresentation()if (!presentation) throw new Error('No active Presentation.')const master = Object.values(presentation.save().masterPages ?? {})[0]const elementId = master?.elementOrder[0]if (!master || !elementId) throw new Error('Master element not found.')await presentation .getMasterElementPermission(PageTypeEnum.Master, master.id, elementId) .setReadOnly()Types: FSlideObjectPermission · PageTypeEnum.Master · PageTypeEnum.Layout
Package: @univerjs-pro/slides · Type definitions
FPresentation.getMasterViewPermission
Returns the shared Master and Layout edit permission facade.
getMasterViewPermission(): FSlideObjectPermissionReturns
Permission facade combining Presentation and Master View Edit points.
Examples
const presentation = univerAPI.getActivePresentation()if (!presentation) throw new Error('No active Presentation.')await presentation.getMasterViewPermission().setReadOnly()Types: FSlideObjectPermission
Package: @univerjs-pro/slides · Type definitions
FPresentation.getName
Get the presentation name.
getName(): stringReturns
The presentation name.
Examples
const fPresentation = univerAPI.getActivePresentation()console.log(fPresentation.getName())Package: @univerjs-pro/slides · Type definitions
FPresentation.getPageSize
Get the default page size of the presentation.
getPageSize(): ISlidePageSizeReturns
The page size.
Examples
const fPresentation = univerAPI.getActivePresentation()console.log(fPresentation.getPageSize())Types: ISlidePageSize
Package: @univerjs-pro/slides · Type definitions
FPresentation.getPermission
Returns the Presentation unit permission facade.
getPermission(): FPresentationPermissionReturns
Permission facade for Edit, Copy, Print, Export, and Comment.
Examples
const presentation = univerAPI.getActivePresentation()if (!presentation) throw new Error('No active Presentation.')await presentation.getPermission().setReadOnly()Types: FPresentationPermission
Package: @univerjs-pro/slides · Type definitions
FPresentation.getPresentation
Get the underlying presentation model.
getPresentation(): SlideModelReturns
The presentation model.
Examples
const fPresentation = univerAPI.getActivePresentation()const model = fPresentation.getPresentation()console.log(model)Types: SlideModel
Package: @univerjs-pro/slides · Type definitions
FPresentation.getPresentationBackgroundGraphics
Get managed presentation background graphics from a master page.
When masterPageId is omitted, the active slide's master is used.
getPresentationBackgroundGraphics(masterPageId?: string): ISlidePresentationBackgroundGraphic[]Parameters
masterPageId— Optional. Optional master page id to read from.
Returns
The managed deck background graphics.
Examples
const fPresentation = univerAPI.getActivePresentation()const graphics = fPresentation.getPresentationBackgroundGraphics()console.log(graphics)Types: ISlidePresentationBackgroundGraphic
Package: @univerjs-pro/slides · Type definitions
FPresentation.getSlideById
Get a slide by id.
getSlideById(id: string): FSlide | nullParameters
id— Required. The slide id.
Returns
The slide, or null if it does not exist.
Examples
const fPresentation = univerAPI.getActivePresentation()const slide = fPresentation.getSlideById('slide-1')console.log(slide)Types: FSlide
Package: @univerjs-pro/slides · Type definitions
FPresentation.getSlideByIndex
Get a slide by index.
getSlideByIndex(index: number): FSlide | nullParameters
index— Required. The zero-based slide index.
Returns
The slide, or null if the index is out of range.
Examples
const fPresentation = univerAPI.getActivePresentation()const firstSlide = fPresentation.getSlideByIndex(0)console.log(firstSlide)Types: FSlide
Package: @univerjs-pro/slides · Type definitions
FPresentation.getSlides
Get all slides in the presentation.
getSlides(): FSlide[]Returns
The slides in slide order.
Examples
const fPresentation = univerAPI.getActivePresentation()const slides = fPresentation.getSlides()console.log(slides)Types: FSlide
Package: @univerjs-pro/slides · Type definitions
FPresentation.insertSlide
Insert a new slide at the specified index.
insertSlide(index: number, options?: Partial<ISlidePage>): FSlideParameters
index— Required. The zero-based insert index.options— Optional. Default:{}. The slide creation options.
Returns
The created slide.
Examples
const fPresentation = univerAPI.getActivePresentation()const slide = fPresentation.insertSlide(0, { name: 'Opening' })console.log(slide)Types: FSlide · Partial · ISlidePage
Package: @univerjs-pro/slides · Type definitions
FPresentation.moveSlide
Move a slide to a new index.
moveSlide(slide: FSlide, toIndex: number): booleanParameters
slide— Required. The slide to move.toIndex— Required. The target zero-based index.
Returns
Whether the slide was moved successfully.
Examples
const fPresentation = univerAPI.getActivePresentation()const firstSlide = fPresentation.getSlideByIndex(0)if (firstSlide) { fPresentation.moveSlide(firstSlide, 1)}Types: FSlide
Package: @univerjs-pro/slides · Type definitions
FPresentation.save
Save and return the presentation snapshot.
save(): ISlideDataReturns
The presentation snapshot.
Examples
const fPresentation = univerAPI.getActivePresentation()const snapshot = fPresentation.save()console.log(snapshot)Types: ISlideData
Package: @univerjs-pro/slides · Type definitions
FPresentation.setActiveSlide
Set the active slide.
setActiveSlide(slide: FSlide): thisParameters
slide— Required. The slide facade or slide id to activate.
Returns
This presentation, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()const secondSlide = fPresentation.getSlideByIndex(1)if (secondSlide) { fPresentation.setActiveSlide(secondSlide)}Types: FSlide
Package: @univerjs-pro/slides · Type definitions
FPresentation.setName
Set the presentation name.
setName(name: string): thisParameters
name— Required. The new presentation name.
Returns
This presentation, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()fPresentation.setName('Quarterly Review')Package: @univerjs-pro/slides · Type definitions
FPresentation.setPageSize
Set the default page size of the presentation.
setPageSize(pageSize: Partial<ISlidePageSize>): thisParameters
pageSize— Required. The new default page size.
Returns
This presentation, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()fPresentation.setPageSize({ width: 1024, preset: univerAPI.Enum.SlidePageSizePresetEnum.WideScreen16By10,})Types: Partial · ISlidePageSize
Package: @univerjs-pro/slides · Type definitions
FPresentation.setPresentationBackgroundGraphics
Set managed presentation background graphics.
The call updates master pages through SetPresentationBackgroundGraphicsCommand.
setPresentationBackgroundGraphics(graphics: ISlidePresentationBackgroundGraphic[], options?: ISetPresentationBackgroundGraphicsOptions): thisParameters
graphics— Required. The managed background graphics.options— Optional. Default:{}. Target master options.
Returns
This presentation, for chaining.
Examples
const fPresentation = univerAPI.getActivePresentation()fPresentation.setPresentationBackgroundGraphics( [ { source: 'image-source-id', imageSourceType: univerAPI.Enum.ImageSourceType.UUID, fit: univerAPI.Enum.SlidePresentationBackgroundGraphicFitEnum.Cover, }, ], { target: univerAPI.Enum.SlidePresentationBackgroundGraphicsTargetEnum.ActiveMaster, },)const fPresentation = univerAPI.getActivePresentation()const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="960" height="540" viewBox="0 0 960 540"> <rect width="960" height="540" fill="#e0f2fe"/> <path d="M0 540 L960 0" stroke="#22c55e" stroke-width="90" opacity="0.45"/> <path d="M-120 420 L840 -120" stroke="#3b82f6" stroke-width="52" opacity="0.55"/> <circle cx="760" cy="150" r="90" fill="#f97316" opacity="0.65"/> <text x="64" y="455" font-size="54" font-family="Arial" fill="#0f172a">Deck background</text></svg>`const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`fPresentation.setPresentationBackgroundGraphics( [ { source: url, imageSourceType: univerAPI.Enum.ImageSourceType.BASE64, fit: univerAPI.Enum.SlidePresentationBackgroundGraphicFitEnum.Cover, }, ], { target: univerAPI.Enum.SlidePresentationBackgroundGraphicsTargetEnum.AllMasters, },)Types: ISlidePresentationBackgroundGraphic · ISetPresentationBackgroundGraphicsOptions
Package: @univerjs-pro/slides · Type definitions
How is this guide?