API 参考

FPdfImage

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

Facade for one editable managed PDF image.

Access

Access through:

Inheritance

Extends FPdfPageElement. Its inherited members are available on this object.

Example

TypeScript
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const imageInfo = page  .newImage()  .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4')  .setSize(240, 135)  .build()const image = page.insertImage(imageInfo)console.log(image.getSource())console.log(image.getImageSourceType())image  .setPosition(36, 72)  .setRotation(15)  .setCrop({ left: 0, top: 0, right: 100, bottom: 100 })  .setOpacity(0.75)

Setup

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

@univerjs-pro/pdfs

FPdfImage.getCrop

Return a detached crop descriptor.

TypeScript
getCrop(): Readonly<IPdfImageCrop> | null

Returns

The crop offsets, or null when uncropped.

Examples

TypeScript
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const image = page.getImages()[0]console.log(image?.getCrop())

Types: Readonly · IPdfImageCrop

Package: @univerjs-pro/pdfs · Type definitions

FPdfImage.getImageSourceType

Return the durable image source kind.

TypeScript
getImageSourceType(): ImageSourceType

Returns

The image source type.

Examples

TypeScript
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const image = page.getImages()[0]console.log(image?.getImageSourceType())

Types: ImageSourceType

Package: @univerjs-pro/pdfs · Type definitions

FPdfImage.getOpacity

Return the current image opacity.

TypeScript
getOpacity(): number

Returns

The opacity from 0 through 1.

Examples

TypeScript
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const image = page.getImages()[0]console.log(image?.getOpacity())

Package: @univerjs-pro/pdfs · Type definitions

FPdfImage.getSource

Return the durable image source string.

TypeScript
getSource(): string

Returns

The URL, UUID, or base64 image source.

Examples

TypeScript
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const image = page.getImages()[0]console.log(image?.getSource())

Package: @univerjs-pro/pdfs · Type definitions

FPdfImage.remove

Remove this placement and release its managed resource when unreferenced.

TypeScript
remove(): void

Throws

If the image is stale or the durable command is rejected.

Examples

TypeScript
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const image = page.getImages()[0]if (image) {  image.remove()}

Package: @univerjs-pro/pdfs · Type definitions

FPdfImage.setCrop

Set the visible image crop window.

TypeScript
setCrop(crop: IPdfImageCrop): this

Parameters

  • crop — Required. The crop offsets.

Returns

This image Facade for chaining.

Throws

If a crop value is not finite or the crop rectangle is empty.

If the image is stale or the durable command is rejected.

Examples

TypeScript
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const image = page.getImages()[0]if (image) {  image.setCrop({ left: 0, top: 0, right: 100, bottom: 100 })}

Types: IPdfImageCrop

Package: @univerjs-pro/pdfs · Type definitions

FPdfImage.setOpacity

Set image opacity from zero through one.

TypeScript
setOpacity(opacity: number): this

Parameters

  • opacity — Required. The opacity from 0 through 1.

Returns

This image Facade for chaining.

Throws

If opacity is outside the inclusive 0-through-1 range.

If the image is stale or the durable command is rejected.

Examples

TypeScript
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const image = page.getImages()[0]if (image) {  image.setOpacity(0.75)}

Package: @univerjs-pro/pdfs · Type definitions

FPdfImage.setSource

Replace the managed image source atomically.

TypeScript
setSource(source: string, imageSourceType?: ImageSourceType): this

Parameters

  • source — Required. The new URL, UUID, or base64 source.
  • imageSourceType — Optional. The explicit source type, or omit it to infer the type.

Returns

This image Facade for chaining.

Throws

If the image source does not match its source type.

If the image is stale or the durable command is rejected.

Examples

TypeScript
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const image = page.getImages()[0]if (image) {  image.setSource('https://example.com/new-image.png')}

Types: ImageSourceType

Package: @univerjs-pro/pdfs · Type definitions

FPdfImage.toBuilder

Return a detached builder initialized from this live image.

TypeScript
toBuilder(): FPdfImageBuilder

Returns

A detached builder for this image.

Examples

TypeScript
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const image = page.getImages()[0]const info = image?.toBuilder().setSize(320, 180).build()

Types: FPdfImageBuilder

Package: @univerjs-pro/pdfs · Type definitions

你觉得这篇文档如何?

© 2026 DreamNum Co., Ltd.