Images
Images add visual content to a document. They can illustrate a point, place a reference picture next to the text, or make key information stand out.
Text wrapping around an image
Switch layouts and follow the text beside and below the image.
Univer Docs
Univer Docs combines text, images, and page layout in an editable document. Use headings to organize ideas and images to explain details. The wrapping style controls how surrounding text flows. Choose a layout that keeps the reading order clear as the document changes.
Square wrapping lets text flow beside the rectangular image.
Plugin mode
Installation
pnpm add @univerjs/drawing @univerjs/drawing-ui @univerjs/docs-drawing @univerjs/docs-drawing-uinpm install @univerjs/drawing @univerjs/drawing-ui @univerjs/docs-drawing @univerjs/docs-drawing-uiyarn add @univerjs/drawing @univerjs/drawing-ui @univerjs/docs-drawing @univerjs/docs-drawing-uibun add @univerjs/drawing @univerjs/drawing-ui @univerjs/docs-drawing @univerjs/docs-drawing-uiUsage
import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import { UniverDocsDrawingPlugin } from '@univerjs/docs-drawing'import { UniverDocsDrawingUIPlugin } from '@univerjs/docs-drawing-ui'import DocsDrawingUIEnUS from '@univerjs/docs-drawing-ui/locale/en-US'import { UniverDrawingPlugin } from '@univerjs/drawing'import { UniverDrawingUIPlugin } from '@univerjs/drawing-ui'import DrawingUIEnUS from '@univerjs/drawing-ui/locale/en-US'import '@univerjs/drawing-ui/lib/index.css'import '@univerjs/docs-drawing-ui/lib/index.css'const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( DrawingUIEnUS, DocsDrawingUIEnUS, ), },})univer.registerPlugin(UniverDrawingPlugin)univer.registerPlugin(UniverDrawingUIPlugin)univer.registerPlugin(UniverDocsDrawingPlugin)univer.registerPlugin(UniverDocsDrawingUIPlugin)If the application uses Collaboration, add the override configuration:
univer.registerPlugin(UniverDrawingPlugin, { override: [[IImageIoService, null]], })Plugin configuration
UniverDrawingPlugin
override[DependencyIdentifier, Provider | null][]Dependency overrides used by the drawing plugin.[0]DependencyIdentifierDependency identifier. UseIImageIoServicefor image storage.[1]Provider | nullReplacement provider. Passnullto let collaboration supply this service.
Mobile support
Configure the mobile editor first. In the plugin-mode setup on this page, replace the desktop registrations below with the mobile exports from the same packages, and do so before opening a document. Keep the model plugins, styles, locales, and Facade imports, and do not register both variants.
| Package | Desktop registration | Mobile registration |
|---|---|---|
@univerjs/docs-drawing-ui | UniverDocsDrawingUIPlugin | UniverDocsDrawingMobileUIPlugin |
@univerjs/drawing-ui | UniverDrawingUIPlugin | UniverDrawingMobileUIPlugin |
Preset mode
Installation
pnpm add @univerjs/preset-docs-drawingnpm install @univerjs/preset-docs-drawingyarn add @univerjs/preset-docs-drawingbun add @univerjs/preset-docs-drawingUsage
import { UniverDocsCorePreset } from '@univerjs/preset-docs-core'import UniverPresetDocsCoreEnUS from '@univerjs/preset-docs-core/locales/en-US'import { UniverDocsDrawingPreset } from '@univerjs/preset-docs-drawing'import UniverPresetDocsDrawingEnUS from '@univerjs/preset-docs-drawing/locales/en-US'import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'import '@univerjs/preset-docs-core/lib/index.css'import '@univerjs/preset-docs-drawing/lib/index.css'const { univerAPI } = createUniver({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( UniverPresetDocsCoreEnUS, UniverPresetDocsDrawingEnUS, ), }, presets: [ UniverDocsCorePreset(), UniverDocsDrawingPreset(), ],})If the application uses Collaboration, pass collaboration: true to UniverDocsDrawingPreset:
UniverDocsDrawingPreset({ collaboration: true, })Preset configuration
UniverDocsDrawingPreset
collaborationbooleanDefault:falseRun image I/O through the collaboration service, which makes image storage collaborative.
Facade API
In plugin mode, import the Facade extension first:
import '@univerjs/docs-drawing/facade'FDocument inserts, queries, and manages document images:
const document = univerAPI.getActiveDocument()const image = await document?.insertImage({ source: 'https://example.com/image.png', imageSourceType: univerAPI.Enum.ImageSourceType.URL, width: 320, wrappingStyle: univerAPI.Enum.TextWrappingStyle.INLINE,})document?.getImage(image?.getId() ?? '')document?.getImages()The returned FDocumentImage resizes, rotates, repositions, rewraps, reorders, or removes the image.
How is this guide?