> 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/edit-page-content/graphics-state.md).

# Graphics state using JavaScript

Learn how to extract data, do color conversion, and process changes in the graphics state with Apryse SDK. Explore PDF Data Extraction techniques and full code samples. The Apryse Web SDK streamlines

{% hint style="warning" %}
Make sure you have [Full API enabled in WebViewer.](/web/what-is-webviewer/full-api.md)
{% endhint %}

To traverse the list of changes in the graphics state.

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

```js
WebViewer({ fullAPI: true })
  .then(instance => {
    const { PDFNet } = instance.Core;
    await PDFNet.initialize();
    const reader = await PDFNet.ElementReader.create();
    const gs_itr = await reader.getChangesIterator();
    for ( ; gs_itr.hasNext(); gs_itr.next())
    {
      switch(gs_itr.current())
      {
        case GState.Attribute.e_transform :
          // Get transform matrix for this element. Unlike path.GetCTM() 
          // that return full transformation matrix gs.GetTransform() return 
          // only the transformation matrix that was installed for this element.
          //
          // await gs.getTransform();
          break;
        case GState.Attribute.e_line_width :
          // await gs.getLineWidth();
          break;
        case GState.Attribute.e_line_cap :
          // await gs.getLineCap();
          break;
        case GState.Attribute.e_line_join :
          // await gs.getLineJoin();
          break;
        case GState.Attribute.e_miter_limit :
          // await gs.getMiterLimit();
          break;
        case GState.Attribute.e_dash_pattern :
        {
          // await gs.GetDashPattern();
          // await gs.GetPhase();
          break;
        }
        // Etc.
      }
    }
  })
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [PDFNet.ElementReader.create](https://sdk.apryse.com/api/web/Core.PDFNet.ElementReader.html#.create__anchor) [PDFNet.ElementReader.getChangesIterator](https://sdk.apryse.com/api/web/Core.PDFNet.ElementReader.html#getChangesIterator__anchor) [PDFNet.GSState.Attribute](https://sdk.apryse.com/api/web/Core.PDFNet.GState.html#.Attribute__anchor)
{% endtab %}

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

```js
WebViewer({ fullAPI: true })
  .then(instance => {
    const { PDFNet } = instance;
    await PDFNet.initialize();
    const reader = await PDFNet.ElementReader.create();
    const gs_itr = await reader.getChangesIterator();
    for ( ; gs_itr.hasNext(); gs_itr.next())
    {
      switch(gs_itr.current())
      {
        case GState.Attribute.e_transform :
          // Get transform matrix for this element. Unlike path.GetCTM() 
          // that return full transformation matrix gs.GetTransform() return 
          // only the transformation matrix that was installed for this element.
          //
          // await gs.getTransform();
          break;
        case GState.Attribute.e_line_width :
          // await gs.getLineWidth();
          break;
        case GState.Attribute.e_line_cap :
          // await gs.getLineCap();
          break;
        case GState.Attribute.e_line_join :
          // await gs.getLineJoin();
          break;
        case GState.Attribute.e_miter_limit :
          // await gs.getMiterLimit();
          break;
        case GState.Attribute.e_dash_pattern :
        {
          // await gs.GetDashPattern();
          // await gs.GetPhase();
          break;
        }
        // Etc.
      }
    }
  })
```

{% endcode %}

[WebViewerInstance](https://sdk.apryse.com/api/web/WebViewerInstance.html) [PDFNet.ElementReader.create](https://sdk.apryse.com/api/web/Core.PDFNet.ElementReader.html#.create__anchor) [PDFNet.ElementReader.getChangesIterator](https://sdk.apryse.com/api/web/Core.PDFNet.ElementReader.html#getChangesIterator__anchor) [PDFNet.GSState.Attribute](https://sdk.apryse.com/api/web/Core.PDFNet.GState.html#.Attribute__anchor)
{% endtab %}
{% endtabs %}

[PDF Data Extraction (Images, Text, Paths)](/web/get-started/samples.md#elementreaderadv) Full code sample which illustrates how to extract data, do color conversion, image normalization, and how to process changes in the graphics state.

## About graphics state

After reading an Element using `ElementReader.Next()`, it is possible to access all graphical attributes of the Element through its graphics state. Some applications are more interested in *changes* in the graphics state than attribute values. For example, a transition from one Element to another may not involve changes in the graphics state. Or, perhaps, there may be changes only to a couple of attributes. In these cases, it isn't efficient to make memberwise comparisons between the old and current graphics states.

To make this easier and more efficient, Apryse SDK offers an API to enumerate the list of changes between subsequent Elements.


---

# 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/edit-page-content/graphics-state.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.
