Class: Color

PSPDFKit.Color

Color objects are used in annotations for defining colors. We're using an rgb representation internally with the r, g, b values clipped between 0 and 255 inclusive, and a transparent flag that can be used to indicate that the color is transparent, in which case the provided r, g, and b values are ignored and set to 0 in the instantiated Color.

It is an Immutable.Record and thus can be updated using set(key, value), for example: color.set("r", 255).

However, in order to obtain a transparent color the static TRANSPARENT value should be used instead.

The difference between using Color.TRANSPARENT and null as values for annotation color properties may depend on the context; if the annotation is being created or updated:

  • If an annotation with a non-transparent color value is updated to have a color value of Color.TRANSPARENT, the color value will be updated and be transparent.
  • But if that same annotation is updated to have a color value of null, the color change will not be saved to the document, although it may appear as transparent in the viewer.

To avoid inconsistencies, it is recommended to always use Color.TRANSPARENT instead of null when updating annotations.

Constructor

new PSPDFKit.Color(args)

A simple RGB color value.

Parameters:
Name Type Description
args object

An object used to initialize the color. If r, g or b is omitted, 0 will be used instead.

Default Value:
  • { r: 0, g: 0, b: 0, transparent: false }
Example

Create and update a color

var color = new PSPDFKit.Color({ r: 245, g: 0, b: 0 });
color = color.set("r", 255);
color.r; // => 255

Extends

  • Immutable.Record

Members

Methods




Members

b: number

The blue value of the color.

Type:
  • number
Default Value:
  • 0

g: number

The green value of the color.

Type:
  • number
Default Value:
  • 0

r: number

The red value of the color.

Type:
  • number
Default Value:
  • 0

transparent: boolean

Transparency of the color.

Type:
  • boolean
Default Value:
  • false

(static) BLACK: PSPDFKit.Color

Simple black (CSS: rgb(0, 0, 0))

Type:

(static) BLUE: PSPDFKit.Color

Blue (CSS: rgb(36, 131, 199))

Type:

(static) DARK_GREY: PSPDFKit.Color

Dark grey (CSS: rgb(64, 64, 64))

Type:

(static) GREEN: PSPDFKit.Color

Green (CSS: rgb(110, 176, 0))

Type:

(static) GREY: PSPDFKit.Color

Grey (CSS: rgb(128, 128, 128))

Type:

(static) LIGHT_BLUE: PSPDFKit.Color

Light blue (CSS: rgb(141, 184, 255))

Type:

(static) LIGHT_GREEN: PSPDFKit.Color

Light green (CSS: rgb(162, 250, 123))

Type:

(static) LIGHT_GREY: PSPDFKit.Color

Light grey (CSS: rgb(192, 192, 192))

Type:

(static) LIGHT_ORANGE: PSPDFKit.Color

Light orange (CSS: rgb(255, 139, 94))

Type:

(static) LIGHT_RED: PSPDFKit.Color

Light red (CSS: rgb(247, 141, 138))

Type:

(static) LIGHT_YELLOW: PSPDFKit.Color

Light yellow (CSS: rgb(252, 238, 124))

Type:

(static) ORANGE: PSPDFKit.Color

Orange (CSS: rgb(243, 149, 0))

Type:

(static) PINK: PSPDFKit.Color

Pink (CSS: rgb(255, 114, 147))

Type:

(static) PURPLE: PSPDFKit.Color

Purple (CSS: rgb(255, 0, 255))

Type:

(static) RED: PSPDFKit.Color

Red (CSS: rgb(248, 36, 0))

Type:

(static) TRANSPARENT: PSPDFKit.Color

Transparent (CSS: transparent)

Type:

(static) WHITE: PSPDFKit.Color

Simple white (CSS: rgb(255, 255, 255))

Type:

(static) YELLOW: PSPDFKit.Color

Yellow (CSS: rgb(255, 255, 0))

Type:

Methods

darker(percent) → {Color}

Returns a darker version of the current Color.

Parameters:
Name Type Description
percent number

The percentage of lightness between 0 and 100.

Returns:

A Color with the new values.

Type
Color
Example
const color = PSPDFKit.Color.RED.darker(50);

equals(color) → {boolean}

Returns true if the provided color or object and the current Color have the same RGB values.

Parameters:
Name Type Description
color Color | Object

Color instance or RGB object.

Returns:

True if equal, false otherwise.

Type
boolean
Example
const color = PSPDFKit.Color.RED.equals({ r: 248, g: 36, b: 0 });

lighter(percent) → {Color}

Returns a lighter version of the current Color.

Parameters:
Name Type Description
percent number

The percentage of lightness between 0 and 100.

Returns:

A Color with the new values.

Type
Color
Example
const color = PSPDFKit.Color.RED.lighter(50);

saturate(percent) → {Color}

Modifies the saturation of the Color and returns a new one.

Parameters:
Name Type Description
percent number

The percentage of saturation between 0 and 100.

Returns:

A Color with the new values.

Type
Color
Example
const color = PSPDFKit.Color.RED.saturate(50);

toCSSValue() → {string}

Converts the color to a CSS value (e.g. rgb(255, 0, 0)).

Returns:

A CSS color value in rgb format.

Type
string
Example
PSPDFKit.Color.RED.toCSSValue(); // => 'rgb(248, 36, 0)'

toHex() → {string}

Converts the color to a Hex value (e.g. #000000).

Returns:

A CSS color value in hex format.

Type
string
Example
PSPDFKit.Color.RED.toHex(); // => '#f82400'