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
@univerjs-pro/slides-ui
FPresentation.endTextEditingAsync
Commits the current text draft in this presentation and closes its editor.
endTextEditingAsync(): Promise<boolean>Returns
Whether editing ended successfully, or there was no active editor. Returns false if the draft could not be committed or IME input is in progress.
Examples
import '@univerjs-pro/slides-ui/facade'const presentation = univerAPI.getActivePresentation()if (presentation && (await presentation.endTextEditingAsync())) { const snapshot = presentation.save()}Types: Promise
Package: @univerjs-pro/slides-ui Ā· Type definitions
FPresentation.isTextEditing
Whether a shape or table cell text editor is active in this presentation. An active editor may contain a draft that has not reached the presentation model yet.
isTextEditing(): booleanPackage: @univerjs-pro/slides-ui Ā· Type definitions
How is this guide?