FPdfImage
Facade for one editable managed PDF image.
Access
Access through:
Inheritance
Extends FPdfPageElement. Its inherited members are available on this object.
Example
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.
getCrop(): Readonly<IPdfImageCrop> | nullReturns
The crop offsets, or null when uncropped.
Examples
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.
getImageSourceType(): ImageSourceTypeReturns
The image source type.
Examples
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.
getOpacity(): numberReturns
The opacity from 0 through 1.
Examples
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.
getSource(): stringReturns
The URL, UUID, or base64 image source.
Examples
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.
remove(): voidThrows
If the image is stale or the durable command is rejected.
Examples
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.
setCrop(crop: IPdfImageCrop): thisParameters
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
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.
setOpacity(opacity: number): thisParameters
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
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.
setSource(source: string, imageSourceType?: ImageSourceType): thisParameters
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
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.
toBuilder(): FPdfImageBuilderReturns
A detached builder for this image.
Examples
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
你觉得这篇文档如何?