Image - Scoped, Global
-
- UpdatedJan 30, 2025
- 3 minutes to read
- Yokohama
- API reference
Creates an Image object representing an image and its layout insert in a PDF. Enables defining attributes such as scale, alignment, and border color.
This API is part of the ServiceNow PDF
Generation Utilities plugin (com.snc.apppdfgenerator) and is provided within the
sn_pdfgeneratorutils
namespace. The plugin is activated by default.
This API is a component used with the Document API to generate a PDF.
- Cell – addImage(Image image) – Adds an image to a table cell
- Table – addImageCell(Image image) – Adds a cell that contains an image to a table.
- Document – addImage(Image image) - Adds an image to a page
Image - Image(String attachmentSysId)
Instantiates a new Image object. Used to verify if an image attachment exists and is available for modification.
Name | Type | Description |
---|---|---|
attachmentSysId | String | Sys_id of an image in the Attachments [sys_attachment] table. |
Example
The following example shows how to create a Image object.
Image – scaleAbsolute(Number width, Number height)
Scales an image to absolute width and height sizes. This setting does not preserve the width-height ratio of the image and might result in undesired stretching if settings are not precise.
To scale to an absolute size that preserves width-height ratio of an image, use the scaleToFit() method.
Name | Type | Description |
---|---|---|
width | Number | Image width in points. |
height | Number | Image height in points. |
Type | Description |
---|---|
None |
Example
The following example shows how to add an image to a PDF with absolute width and height settings.
Image – scaleToFit(Number width, Number height)
Scales an image to an absolute size while preserving the width-height ratio.
Resulting output varies by image aspect ratio. If the width and height parameter values do not match the image aspect ratio, one value renders smaller in output than the value given.
Name | Type | Description |
---|---|---|
width | Number | Maximum image width in points. |
height | Number | Maximum image height in points. |
Type | Description |
---|---|
None |
Example
The following example shows how to insert an image scaled to fit using the Cell – addImage() method.
Image – setAutoScale(Boolean value)
Enables scaling width and height to a page or cell while retaining dimensions.
Name | Type | Description |
---|---|---|
value | Boolean | Flag that indicates whether to automatically scale an image. Valid values:
Default: false |
Type | Description |
---|---|
None |
Example
The following example shows how to add an image to a PDF with automatic scaling. The image is added using the Table – addImageCell() method.
Image – setColoredBorder(Color color, Number width)
Sets a border on a PDF in the specified color.
Name | Type | Description |
---|---|---|
color | Color | Image border color. |
width | Number | Width of the border in points. |
Type | Description |
---|---|
None |
Example
The following example shows how to set a five-point red-colored border on an image.
Image – setHorizontalAlignment(String alignment)
Sets the horizontal alignment of the image.
Name | Type | Description |
---|---|---|
alignment | String | Positions image alignment on a page or block element. Valid values:
Default: Left |
Type | Description |
---|---|
None |
Example
The following example shows how to add a centered image on a PDF page.
Image – setNoBorder()
Sets an image to have no border.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
None |
Example
The following example shows how to add an image to a document without a border.