> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/extraction/color-separation.md).

# PDF Color Separation in JavaScript Viewer

Unlock PDF color separation capabilities with WebViewer. Extract, enable, and disable color separations effortlessly using simple APIs. Experience a live demo now! The Apryse Web SDK streamlines secur

PDFs can be created in such a way that each color lives on its own "separation". Each separation refers to a particular ink or process that would be used as part of physically printing a document.

WebViewer has the capability to extract information from these separations, and also disable/enable them.

You can view a [demo of color separation process](https://showcase.apryse.com/color-separation) in action.

## API

Enabling color separation is done with a single API, [`enableColorSeparations`](https://sdk.apryse.com/api/web/Core.Document.html#enableColorSeparations__anchor). When this function is called, WebViewer will get the separations and pass the data through a [`colorSeparationAdded`](https://sdk.apryse.com/api/web/Core.Document.html#event:colorSeparationAdded__anchor) event.

{% hint style="info" %}
The colorSeparationAdded event will get triggered once per color.
{% endhint %}

Once you have the layer, you can disable/hide it with the [`enableSeparation`](https://sdk.apryse.com/api/web/Core.Document.html#enableSeparation__anchor) API.

Here is an example of the color separation APIs:

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  initialDoc: 'path/to/doc.pdf',
}, document.getElementById('viewer'))
  .then(instance => {
    const docViewer = instance.Core.documentViewer;

    // wait until the document has been loaded
    docViewer.addEventListener('documentLoaded', () => {
      const doc = docViewer.getDocument();
      // enable color separation
      doc.enableColorSeparations(true);

      // This callback will be fired once for each color in the document
      doc.addEventListener('colorSeparationAdded', (colorData) => {
        /***
        colorData = {
          color: [number, number, number, number], // CMYK value of the color
          enabled: boolean, // is the color enabled or not
          name: string, // name of the color
          rgb: [number, number, number] // RGB value of the color
        }
        ***/
        // To toggle the colors, use the `enableSeparation` API
        doc.enableSeparation(colorData.name, false); // disable this color
        doc.enableSeparation(colorData.name, true); // enable this color

        // Update the view after you're finished toggling
        docViewer.refreshAll();
        docViewer.updateView();
      });
    });
  });
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [DocumentViewer.refreshAll](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#refreshAll__anchor) [DocumentViewer.updateView](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#updateView__anchor) [Document.enableColorSeparations](https://sdk.apryse.com/api/web/Core.Document.html#enableColorSeparations__anchor) [Document.enableSeparation](https://sdk.apryse.com/api/web/Core.Document.html#enableSeparation__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v7.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  initialDoc: 'path/to/doc.pdf',
}, document.getElementById('viewer'))
  .then(instance => {
    const docViewer = instance.docViewer;
    docViewer.on('documentLoaded', () => {
      const doc = docViewer.getDocument();
      // enable color separation
      doc.enableColorSeparations(true);
    });
    docViewer.on('mouseMove', e => {
      const mouseLocation = docViewer.getToolMode().getMouseLocation(e);
      const displayMode = docViewer.getDisplayModeManager().getDisplayMode();
      const pageNumber = displayMode.getSelectedPages(mouseLocation, mouseLocation).first;
      if (pageNumber !== null) {
        const pageCoordinate = displayMode.windowToPage(mouseLocation, pageNumber);
        if (pageCoordinate) {
          const { x, y, pageIndex } = pageCoordinate;
          const results = docViewer.getColorSeparationsAtPoint(pageNumber, x, y);
          /***
            results = [
              {
                name: 'separation name',
                value: 'percentage of color at that point'
              },
              ...
            ]
          ***/
        }
      }
    });
  });
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [DocumentViewer.getDocument](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getDocument__anchor) [DocumentViewer.getDisplayModeManager](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getDisplayModeManager__anchor) [Document.enableColorSeparations](https://sdk.aprysecom/api/web/Core.Document.html#enableColorSeparations__anchor) [Document.getColorSeparationsAtPoint](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getColorSeparationsAtPoint__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  initialDoc: 'path/to/doc.pdf',
}, document.getElementById('viewer'))
  .then(instance => {
    const docViewer = instance.docViewer;
    // wait until the document has been loaded
    docViewer.on('documentLoaded', () => {
      const doc = docViewer.getDocument();
      // enable color separation
      doc.enableColorSeparations(true);
      // This callback will be fired once for each color in the document
      doc.on('colorSeparationAdded', (colorData) => {
        /***
        colorData = {
          color: [number, number, number, number], // CMYK value of the color
          enabled: boolean, // is the color enabled or not
          name: string, // name of the color
          rgb: [number, number, number] // RGB value of the color
        }
        ***/
        // To toggle the colors, use the `enableSeparation` API
        doc.enableSeparation(colorData.name, false); // disable this color
        doc.enableSeparation(colorData.name, true); // enable this color
        // Update the view after you're finished toggling
        docViewer.refreshAll();
        docViewer.updateView();
      });
    });
  });
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [DocumentViewer.refreshAll](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#refreshAll__anchor) [DocumentViewer.updateView](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#updateView__anchor) [Document.enableColorSeparations](https://sdk.apryse.com/api/web/Core.Document.html#enableColorSeparations__anchor) [Document.enableSeparation](https://sdk.apryse.com/api/web/Core.Document.html#enableSeparation__anchor)
{% endtab %}
{% endtabs %}

You can also get a list of color separations at a certain point on the document by using the [`getColorSeparationsAtPoint`](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getColorSeparationsAtPoint__anchor) API. You can see a live example [here.](https://sdk.apryse.com/samples/web/samples/pdf-manipulation/color-separation/)

In this example, we'll get a list of color separations under the users mouse by using the [`mouseMove`](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:mouseMove__anchor) event.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  initialDoc: 'path/to/doc.pdf',
}, document.getElementById('viewer'))
  .then(instance => {
    const docViewer = instance.Core.documentViewer;
    docViewer.addEventListener('documentLoaded', () => {
      const doc = docViewer.getDocument();
      // enable color separation
      doc.enableColorSeparations(true);
    });
    docViewer.addEventListener('mouseMove', e => {
      const mouseLocation = docViewer.getToolMode().getMouseLocation(e);
      const displayMode = docViewer.getDisplayModeManager().getDisplayMode();
      const pageNumber = displayMode.getSelectedPages(mouseLocation, mouseLocation).first;
      if (pageNumber !== null) {
        const pageCoordinate = displayMode.windowToPage(mouseLocation, pageNumber);
        if (pageCoordinate) {
          const { x, y, pageIndex } = pageCoordinate;
          const results = docViewer.getColorSeparationsAtPoint(pageNumber, x, y);
          /***
            results = [
              {
                name: 'separation name',
                value: 'percentage of color at that point'
              },
              ...
            ]
          ***/
        }
      }
    });
  });
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [DocumentViewer.getDocument](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getDocument__anchor) [DocumentViewer.getDisplayModeManager](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getDisplayModeManager__anchor) [Document.enableColorSeparations](https://sdk.apryse.com/api/web/Core.Document.html#enableColorSeparations__anchor) [Document.getColorSeparationsAtPoint](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getColorSeparationsAtPoint__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v7.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  initialDoc: 'path/to/doc.pdf',
}, document.getElementById('viewer'))
  .then(instance => {
    const docViewer = instance.docViewer;
    docViewer.on('documentLoaded', () => {
      const doc = docViewer.getDocument();
      // enable color separation
      doc.enableColorSeparations(true);
    });
    docViewer.on('mouseMove', e => {
      const mouseLocation = docViewer.getToolMode().getMouseLocation(e);
      const displayMode = docViewer.getDisplayModeManager().getDisplayMode();
      const pageNumber = displayMode.getSelectedPages(mouseLocation, mouseLocation).first;
      if (pageNumber !== null) {
        const pageCoordinate = displayMode.windowToPage(mouseLocation, pageNumber);
        if (pageCoordinate) {
          const { x, y, pageIndex } = pageCoordinate;
          const results = docViewer.getColorSeparationsAtPoint(pageNumber, x, y);
          /***
            results = [
              {
                name: 'separation name',
                value: 'percentage of color at that point'
              },
              ...
            ]
          ***/
        }
      }
    });
  });
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [DocumentViewer.getDocument](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getDocument__anchor) [DocumentViewer.getDisplayModeManager](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getDisplayModeManager__anchor) [Document.enableColorSeparations](https://sdk.aprysecom/api/web/Core.Document.html#enableColorSeparations__anchor) [Document.getColorSeparationsAtPoint](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getColorSeparationsAtPoint__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({
  initialDoc: 'path/to/doc.pdf',
}, document.getElementById('viewer'))
  .then(instance => {
    const docViewer = instance.docViewer;
    // wait until the document has been loaded
    docViewer.on('documentLoaded', () => {
      const doc = docViewer.getDocument();
      // enable color separation
      doc.enableColorSeparations(true);
      // This callback will be fired once for each color in the document
      doc.on('colorSeparationAdded', (colorData) => {
        /***
        colorData = {
          color: [number, number, number, number], // CMYK value of the color
          enabled: boolean, // is the color enabled or not
          name: string, // name of the color
          rgb: [number, number, number] // RGB value of the color
        }
        ***/
        // To toggle the colors, use the `enableSeparation` API
        doc.enableSeparation(colorData.name, false); // disable this color
        doc.enableSeparation(colorData.name, true); // enable this color
        // Update the view after you're finished toggling
        docViewer.refreshAll();
        docViewer.updateView();
      });
    });
  });
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [DocumentViewer#documentLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:documentLoaded__anchor) [DocumentViewer.getDocument](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getDocument__anchor) [DocumentViewer.getDisplayModeManager](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getDisplayModeManager__anchor) [Document.enableColorSeparations](https://sdk.apryse.com/api/web/Core.Document.html#enableColorSeparations__anchor) [Document.getColorSeparationsAtPoint](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#getColorSeparationsAtPoint__anchor)
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/extraction/color-separation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
