FPdfImageBuilder
Detached builder for creating or updating a PDF image.
Access
Access through:
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') .setAbsolutePosition(36, 72) .setSize(240, 135) .setRotation(15) .setCrop({ left: 0, top: 0, right: 100, bottom: 100 }) .setOpacity(0.75) .build()page.insertImage(imageInfo)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
FPdfImageBuilder.build
Build detached image information without modifying the PDF.
build(): IPdfImageBuilderInfoReturns
Detached information for insertImage or updateImage.
Throws
If no image source has been set.
If a placement, crop, or opacity value is invalid.
If the image source does not match its source type.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const imageInfo = page .newImage() .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4') .setAbsolutePosition(36, 72) .setSize(240, 135) .setRotation(15) .setCrop({ left: 0, top: 0, right: 100, bottom: 100 }) .setOpacity(0.75) .build()page.insertImage(imageInfo)Types: IPdfImageBuilderInfo
Package: @univerjs-pro/pdfs · Type definitions
FPdfImageBuilder.setAbsolutePosition
Set the absolute position in PDF points.
setAbsolutePosition(left: number, top: number): thisParameters
left— Required. The left position in points.top— Required. The top position in points.
Returns
This builder for chaining.
Throws
If either position is not finite.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const imageInfo = page .newImage() .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4') .setAbsolutePosition(36, 72) .build()page.insertImage(imageInfo)Package: @univerjs-pro/pdfs · Type definitions
FPdfImageBuilder.setCrop
Set the detached crop descriptor.
setCrop(crop: IPdfImageCrop): thisParameters
crop— Required. The crop offsets.
Returns
This builder for chaining.
Throws
If a crop value is not finite or the crop rectangle is empty.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const imageInfo = page .newImage() .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4') .setCrop({ left: 0, top: 0, right: 100, bottom: 100 }) .build()page.insertImage(imageInfo)Types: IPdfImageCrop
Package: @univerjs-pro/pdfs · Type definitions
FPdfImageBuilder.setOpacity
Set the detached image opacity.
setOpacity(opacity: number): thisParameters
opacity— Required. The opacity from 0 through 1.
Returns
This builder for chaining.
Throws
If opacity is outside the inclusive 0-through-1 range.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const imageInfo = page .newImage() .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4') .setOpacity(0.75) .build()page.insertImage(imageInfo)Package: @univerjs-pro/pdfs · Type definitions
FPdfImageBuilder.setRotation
Set image rotation in degrees.
setRotation(rotation: number): thisParameters
rotation— Required. The rotation in degrees.
Returns
This builder for chaining.
Throws
If the rotation is not finite.
Examples
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) .setRotation(15) .build()page.insertImage(imageInfo)Package: @univerjs-pro/pdfs · Type definitions
FPdfImageBuilder.setSize
Set image width and height in PDF points.
setSize(width: number, height: number): thisParameters
width— Required. The width in points.height— Required. The height in points.
Returns
This builder for chaining.
Throws
If either size is non-finite or not positive.
Examples
const pdf = univerAPI.getActivePdf()const builder = pdf?.getPageByIndex(0)?.newImage().setSize(288, 162)Package: @univerjs-pro/pdfs · Type definitions
FPdfImageBuilder.setSource
Set the URL, UUID, or base64 image source.
setSource(source: string, imageSourceType?: ImageSourceType): thisParameters
source— Required. The image source.imageSourceType— Optional. The explicit source type, or omit it to infer the type.
Returns
This builder for chaining.
Examples
const pdf = univerAPI.getActivePdf()const page = pdf.getPageByIndex(0)const imageInfo = page .newImage() .setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4') .build()page.insertImage(imageInfo)Types: ImageSourceType
Package: @univerjs-pro/pdfs · Type definitions
How is this guide?