---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Image - Scoped, Global

# Image - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 4 minutes to read

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](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") to generate a
PDF.  
You can add an image to a PDF using one of the following methods:

* [Cell -- addImage(Image image)](https://servicenow-prod.fluidtopics.net/uii5Qv66Cr~ri3bGB3uEvw#Cell-addImage_O "Adds an image to a table cell.") -- Adds an image to a table cell
* [Table -- addImageCell(Image image)](https://servicenow-prod.fluidtopics.net/IaWzvxiBPOHtuTwBsfUUOg#Table-addImageCell_O "Adds a cell that contains an image to the table.") -- Adds a cell that contains an image to a table.
* [Document -- addImage(Image image)](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#Document-addImage_O "Adds an image to a document.") - Adds an image to a page
{#ImageBothAPI__ul_jkh_55q_s4b}

## Image - Image(String attachmentSysId) {#ariaid-title2}

Instantiates a new Image object. Used to verify if an image
attachment exists and is available for modification.
{#Image-Image_S__table_twm_hjk_34b__entry__3}

| Name | Type | Description |
|-|-|-|
| attachmentSysId | String | Sys_id of an image in the Attachments \[sys_attachment\] table. |
[Table 1. Parameters]

{#Image-Image_S__table_twm_hjk_34b}  
The following example shows how to create a Image object.

    var image = new sn_pdfgeneratorutils.Image("<sys_id>");

## Image -- scaleAbsolute(Number width, Number height) {#ariaid-title3}

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()](https://servicenow-prod.fluidtopics.net/ulntT09aQ0TR~gRUuuS2Eg#Image-scaleToFit_N_N "Scales an image to an absolute size while preserving the width-height ratio.") method.
{#Image-scaleAbsolute_N_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| width | Number | Image width in points. |
| height | Number | Image height in points. |
[Table 2. Parameters]

{#Image-scaleAbsolute_N_N__table_vv5_52h_44b} {#Image-scaleAbsolute_N_N__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 3. Returns]

{#Image-scaleAbsolute_N_N__table_wv5_52h_44b}  
The following example shows how to add an image to a PDF with absolute width and height
settings.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    var scaleAbsPic = new sn_pdfgeneratorutils.Image("<img_sys_id>");
    scaleAbsPic.scaleAbsolute(25,50);

    document.addImage(scaleAbsPic);

    document.saveAsAttachment("incident", "<record_sys_id>", "docWithImg.pdf");

## Image -- scaleToFit(Number width, Number height) {#ariaid-title4}

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.
{#Image-scaleToFit_N_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| width | Number | Maximum image width in points. |
| height | Number | Maximum image height in points. |
[Table 4. Parameters]

{#Image-scaleToFit_N_N__table_vv5_52h_44b} {#Image-scaleToFit_N_N__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 5. Returns]

{#Image-scaleToFit_N_N__table_wv5_52h_44b}  
The following example shows how to insert an image scaled to fit using the [Cell -- addImage()](https://servicenow-prod.fluidtopics.net/uii5Qv66Cr~ri3bGB3uEvw#Cell-addImage_O "Adds an image to a table cell.") method.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
     
    // add a table
    var table = new sn_pdfgeneratorutils.Table([1,3],false);

    // text for the left column
    var text = "sample image";

    // add a table cell for the image in the right column
    var imgCell = new sn_pdfgeneratorutils.Cell(1, 1);

    // add an image and set it scale-to-fit
    var scaleToFitPic = new sn_pdfgeneratorutils.Image("<img_sys_id>");
    scaleToFitPic.scaleToFit(90,175);

    // add the image to the cell
    imgCell.addImage(scaleToFitPic);
     
    table.addTextCell(text);
    table.addCell(imgCell);

    // Here's a paragraph
    var para = new sn_pdfgeneratorutils.Paragraph("The following table image uses scale to fit.");

    document.addParagraph(para);
    document.addTable(table);

    document.saveAsAttachment("incident", "<record_sys_id>", "imgScaleToFit.pdf");

## Image -- setAutoScale(Boolean value) {#ariaid-title5}

Enables scaling width and height to a page or cell while retaining
dimensions.
{#Image-setAutoScale_B__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| value | Boolean | Flag that indicates whether to automatically scale an image. Valid values: * true: Automatically scales the image * false: Image does not scale {#Image-setAutoScale_B__ul_drr_bbr_s4b} Default: false |
[Table 6. Parameters]

{#Image-setAutoScale_B__table_vv5_52h_44b} {#Image-setAutoScale_B__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 7. Returns]

{#Image-setAutoScale_B__table_wv5_52h_44b}  
The following example shows how to add an image to a PDF with automatic scaling. The image
is added using the [Table --
addImageCell()](https://servicenow-prod.fluidtopics.net/IaWzvxiBPOHtuTwBsfUUOg#Table-addImageCell_O "Adds a cell that contains an image to the table.") method.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    // Add a table
    var table = new sn_pdfgeneratorutils.Table([1,2],false);

    // Text in left column
    var text = "sample image";

    // Image in right column
    var autoScaledPic = new sn_pdfgeneratorutils.Image("<image_sys_id>");
    autoScaledPic.setAutoScale(true);

    table.addTextCell(text);
    table.addImageCell(autoScaledPic);

    document.addTable(table);
    document.saveAsAttachment("incident", "<record_sys_id>", "imgAutoScale.pdf");

## Image -- setColoredBorder(Color color, Number width) {#ariaid-title6}

Sets a border on a PDF in the specified color.
{#Image-setColoredBorder_O_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| color | [Color](https://servicenow-prod.fluidtopics.net/0EiXfws~5CY1d9dHdAL1UQ#ColorBothAPI "Creates a Color object used to define color attributes that you can apply to elements in a PDF; such as cells, tables, and lines.") | Image border color. |
| width | Number | Width of the border in points. |
[Table 8. Parameters]

{#Image-setColoredBorder_O_N__table_vv5_52h_44b} {#Image-setColoredBorder_O_N__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 9. Returns]

{#Image-setColoredBorder_O_N__table_wv5_52h_44b}  
The following example shows how to set a five-point red-colored border on an image.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    var borderColor = new sn_pdfgeneratorutils.Color([1.0,0.0,0.0]);
     
    // declare image using sys attachment
    var image = new sn_pdfgeneratorutils.Image("<imgAttachment_sys_id>");

    image.setColoredBorder(borderColor, 5);

    document.addImage(image);
    document.saveAsAttachment("incident", "<record_sys_id>", "docWithBorderedImage.pdf");

## Image -- setHorizontalAlignment(String alignment) {#ariaid-title7}

Sets the horizontal alignment of the image.
{#Image-setHorizontalAlignment_S__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| alignment | String | Positions image alignment on a page or block element. Valid values: * Center * Left * Right {#Image-setHorizontalAlignment_S__ul_rn3_wvq_s4b} Default: Left |
[Table 10. Parameters]

{#Image-setHorizontalAlignment_S__table_vv5_52h_44b} {#Image-setHorizontalAlignment_S__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 11. Returns]

{#Image-setHorizontalAlignment_S__table_wv5_52h_44b}  
The following example shows how to add a centered image on a PDF page.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
     
    // declare image using sys attachment
    var image = new sn_pdfgeneratorutils.Image("<imgAttachment_sys_id>");

    String alignment = "Center";
    image.setHorizontalAlignment(alignment);

    document.addImage(image);
    // save pdf as attachment to target record in the Incident table
    document.saveAsAttachment("incident", "<sys_id>", "docWithImageCentered.pdf");

## Image -- setNoBorder() {#ariaid-title8}

Sets an image to have no border.
{#Image-setNoBorder__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 12. Parameters]

{#Image-setNoBorder__table_vv5_52h_44b} {#Image-setNoBorder__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 13. Returns]

{#Image-setNoBorder__table_wv5_52h_44b}  
The following example shows how to add an image to a document without a border.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
     
    // declare image using sys attachment
    var image = new sn_pdfgeneratorutils.Image("<imgAttachment_sys_id>");

    image.setNoBorder();

    document.addImage(image);
    document.saveAsAttachment("incident", "<sys_id>", "docWithImgNoBorder.pdf");


