API 参考

FDocumentImage

本 API 页面目前提供英文正文。代码签名与标识符不随界面语言变化。

Facade API for an image in a document.

Access

Access through:

Setup

Register @univerjs/docs-drawing or a preset that includes it. In plugin mode, import @univerjs/docs-drawing/facade. Additional methods below require their listed plugin packages. See Facade setup.

@univerjs/docs-drawing

FDocumentImage.getAngle

Gets the current clockwise rotation angle.

TypeScript
getAngle(): number | undefined

Returns

The rotation angle in degrees, or undefined when the image no longer exists.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  console.log(image.getAngle())}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.getId

Gets the drawing id of the image.

TypeScript
getId(): string

Returns

The drawing id.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  console.log(image.getId())}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.getImageData

Gets the current raw document image data.

TypeScript
getImageData(): IDocImage | null

Returns

The image data, or null when the image no longer exists.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  console.log(image.getImageData())}

Types: IDocImage

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.getPositionH

Gets the current horizontal position.

TypeScript
getPositionH(): IObjectPositionH | null

Returns

The horizontal position, or null when the image no longer exists.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  console.log(image.getPositionH())}

Types: IObjectPositionH

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.getPositionV

Gets the current vertical position.

TypeScript
getPositionV(): IObjectPositionV | null

Returns

The vertical position, or null when the image no longer exists.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  console.log(image.getPositionV())}

Types: IObjectPositionV

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.getSize

Gets the current image size.

TypeScript
getSize(): ISize | null

Returns

The width and height in pixels, or null when the image no longer exists.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  console.log(image.getSize())}

Types: ISize

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.getSource

Gets the image source supplied at insertion time.

TypeScript
getSource(): string | undefined

Returns

The image source, or undefined when the image no longer exists.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  console.log(image.getSource())}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.getSourceType

Gets the image source type supplied at insertion time.

TypeScript
getSourceType(): ImageSourceType | undefined

Returns

The image source type, or undefined when the image no longer exists.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  console.log(image.getSourceType())}

Types: ImageSourceType

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.getUnitId

Gets the id of the document containing the image.

TypeScript
getUnitId(): string

Returns

The document unit id.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  console.log(image.getUnitId())}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.remove

Removes the image and its document placeholder.

TypeScript
remove(): boolean

Returns

true when the remove command succeeds; otherwise, false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  const success = image.remove()  console.log(success)}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.setBack

Moves the image to the back of the drawing order.

TypeScript
setBack(): boolean

Returns

true when the arrange command succeeds; otherwise, false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  const success = image.setBack()  console.log(success)}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.setBackward

Moves the image backward by one level in the drawing order.

TypeScript
setBackward(): boolean

Returns

true when the arrange command succeeds; otherwise, false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  const success = image.setBackward()  console.log(success)}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.setForward

Moves the image forward by one level in the drawing order.

TypeScript
setForward(): boolean

Returns

true when the arrange command succeeds; otherwise, false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  const success = image.setForward()  console.log(success)}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.setFront

Moves the image to the front of the drawing order.

TypeScript
setFront(): boolean

Returns

true when the arrange command succeeds; otherwise, false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  const success = image.setFront()  console.log(success)}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.setPositionH

Sets the horizontal position of the image. Inline images are positioned by their document placeholder, so this has a visible effect only when the image wrapping style is not TextWrappingStyle.INLINE.

TypeScript
setPositionH(positionH: IObjectPositionH): boolean

Parameters

  • positionH — Required. The horizontal position relative to the document.

Returns

true when the update command succeeds; otherwise, false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  const success = image.setPositionH({    relativeFrom: univerAPI.Enum.DocsImageRelativeFromH.MARGIN,    posOffset: 100,  })  console.log(success)}

Types: IObjectPositionH

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.setPositionV

Sets the vertical position of the image. Inline images are positioned by their document placeholder, so this has a visible effect only when the image wrapping style is not TextWrappingStyle.INLINE.

TypeScript
setPositionV(positionV: IObjectPositionV): boolean

Parameters

  • positionV — Required. The vertical position relative to the document.

Returns

true when the update command succeeds; otherwise, false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  const success = image.setPositionV({    relativeFrom: univerAPI.Enum.DocsImageRelativeFromV.MARGIN,    posOffset: 100,  })  console.log(success)}

Types: IObjectPositionV

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.setRotate

Sets the clockwise rotation angle.

TypeScript
setRotate(angle: number): boolean

Parameters

  • angle — Required. The rotation angle in degrees.

Returns

true when the update command succeeds; otherwise, false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  const success = image.setRotate(45)  console.log(success)}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.setSize

Sets the image size.

TypeScript
setSize(width: number, height: number): boolean

Parameters

  • width — Required. The width in pixels.
  • height — Required. The height in pixels.

Returns

true when the update command succeeds; otherwise, false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  const success = image.setSize(400, 300)  console.log(success)}

Package: @univerjs/docs-drawing · Type definitions

FDocumentImage.setWrappingStyle

Sets the image wrapping style.

Use INLINE to place the image in the text flow, WRAP_SQUARE to flow text beside it, or WRAP_TOP_AND_BOTTOM to keep text above and below it. BEHIND_TEXT and IN_FRONT_OF_TEXT do not reserve space in the text layout and can overlap text.

When switching from inline to a floating style in a UI environment, the current visual position is preserved.

TypeScript
setWrappingStyle(wrappingStyle: TextWrappingStyle): boolean

Parameters

  • wrappingStyle — Required. The wrapping style to apply.

Returns

true when the update command succeeds; otherwise, false.

Examples

TypeScript
const fDocument = univerAPI.getActiveDocument()const image = fDocument.getImages()[0]if (image) {  // Float the image beside body text without covering it.  const success = image.setWrappingStyle(univerAPI.Enum.TextWrappingStyle.WRAP_SQUARE)  console.log(success)}

Types: TextWrappingStyle

Package: @univerjs/docs-drawing · Type definitions

@univerjs-pro/shape-thread-comment

FDocumentImage.createCommentAsync

Creates a comment anchored to this document image.

TypeScript
createCommentAsync(content: ThreadComment.ThreadCommentContent, options?: ElementComment.IFloatingElementCommentCreateOptions): Promise<boolean>

Parameters

  • content — Required. Plain text or a Univer document body for rich comment content.
  • options — Optional. Default: {}. Optional stable IDs, author, attachments, and creation time.

Returns

true when the create command succeeds; otherwise, false.

Throws

If the content is empty.

Examples

TypeScript
const image = univerAPI.getActiveDocument()?.getImages()[0]await image?.createCommentAsync('Add alternative text.')

Types: Promise · ThreadComment.ThreadCommentContent · ElementComment.IFloatingElementCommentCreateOptions

Package: @univerjs-pro/shape-thread-comment · Type definitions

FDocumentImage.getComments

Returns locally loaded comments anchored to this image's drawing ID.

TypeScript
getComments(): ThreadComment.IFacadeThreadCommentInfo[]

Returns

Matching comment threads in the current document.

Examples

TypeScript
const image = univerAPI.getActiveDocument()?.getImages()[0]console.log(image?.getComments().length ?? 0)

Types: ThreadComment.IFacadeThreadCommentInfo

Package: @univerjs-pro/shape-thread-comment · Type definitions

FDocumentImage.listCommentsAsync

Synchronizes known threads and returns comments anchored to this image's drawing ID.

TypeScript
listCommentsAsync(): Promise<ThreadComment.IFacadeThreadCommentInfo[]>

Returns

A promise resolving to matching synchronized comment threads.

Examples

TypeScript
const image = univerAPI.getActiveDocument()?.getImages()[0]const comments = image ? await image.listCommentsAsync() : []console.log(comments.length)

Types: ThreadComment.IFacadeThreadCommentInfo · Promise

Package: @univerjs-pro/shape-thread-comment · Type definitions

你觉得这篇文档如何?

© 2026 DreamNum Co., Ltd.