---
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


---

# Color - Scoped, Global

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

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

Creates a Color object used to define color attributes that you can apply to elements in a PDF; such as cells, tables, and lines.

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.

## Color - Color(Array colors) {#ariaid-title2}

Instantiates a new Color object with RGB values.
Color can be applied to the following scenarios:
{#Color-Color_A__table_twm_hjk_34b__entry__3}

| Name | Type | Description |
|-|-|-|
| colors | Array | Three numbers indicating RGB values using a decimal value from 0 through 1. For example, in `[0.1, 0.9, 0.5]`, the value of the first position is red, second is green, and third is blue. Also, `[0, 0, 0]` is solid black, `[0.5, 0.5, 0.5]` is solid gray, and `[1, 1, 1]` is solid white. |
[Table 1. Parameters]

{#Color-Color_A__table_twm_hjk_34b}  
The following example shows how to create a Color object.

    var color = new sn_pdfgeneratorutils.Color([0.1, 0.9, 0.5]); //given as object containing RGB values

## Color -- equals(Color color) {#ariaid-title3}

Indicates whether the values of two different color objects match.
{#Color-equals_O__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| color | Color | Color object to check for a match. |
[Table 2. Parameters]

{#Color-equals_O__table_vv5_52h_44b} {#Color-equals_O__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the values of two color objects match. Valid values: * true: The colors match. * false: The colors do not match. {#Color-equals_O__ul_grr_53x_r4b} |
[Table 3. Returns]

{#Color-equals_O__table_wv5_52h_44b}  
The following example shows how to create two color objects and determine if the colors
match.

    var color1 = new sn_pdfgeneratorutils.Color([1,0.5,0.5]);  // given as an array of RGB values
    var color2 = new sn_pdfgeneratorutils.Color([0.8,0.5,0.5]);         // given as an array of RGB values
    var isequal = color1.equals(color2);

## Color -- getGrayColor(Number grayScale) {#ariaid-title4}

Returns a black, gray, or white color object.
{#Color-getGrayColor_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| grayScale | Number | Decimal value in the range 0 through 1, in which 0 is black and 1 is white. |
[Table 4. Parameters]

{#Color-getGrayColor_N__table_vv5_52h_44b} {#Color-getGrayColor_N__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| Object | Color object reflecting the provided grayscale value. |
[Table 5. Returns]

{#Color-getGrayColor_N__table_wv5_52h_44b}  
The following example shows how to create a color object that is 50% grayscale.

    var grayColor = new sn_pdfgeneratorutils.Color.getGrayColor(0.5);

## Color -- setColorValue(Array colors) {#ariaid-title5}

Creates color with given values and enables you to change the values of an existing
color. Each of the values must be from 0 through 1.
{#Color-setColorValue_A__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| colors | Array | Three numbers indicating RGB values using a decimal value from 0 through 1. For example, in `[0.1, 0.9, 0.5]`, the value of the first position is red, second is green, and third is blue. Also, `[0, 0, 0]` is solid black, `[0.5, 0.5, 0.5]` is solid gray, and `[1, 1, 1]` is solid white. |
[Table 6. Parameters]

{#Color-setColorValue_A__table_vv5_52h_44b} {#Color-setColorValue_A__table_wv5_52h_44b__entry__2}

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

{#Color-setColorValue_A__table_wv5_52h_44b}  
The following example shows how to change the values of an existing color.

    var color = new sn_pdfgeneratorutils.Color([1,0.5,0.5]);   //given as array of RGB values;
    color.setColorValue(color);

## Color -- setOpacity(Number opacity) {#ariaid-title6}

Sets the level of color opacity.
{#Color-setOpacity_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| color | Color | Floating decimal value from 0 through 1, in which 0 is fully transparent and 1 is fully opaque. |
[Table 8. Parameters]

{#Color-setOpacity_N__table_vv5_52h_44b} {#Color-setOpacity_N__table_wv5_52h_44b__entry__2}

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

{#Color-setOpacity_N__table_wv5_52h_44b}  
The following example shows how to create a color object and set its opacity to 50
percent.

    var color = new Color([1,0.5,0.5]);
    color.setOpacity(0.5);


