> 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/get-started/faq/webviewer-5.0-snippets.md).

# Where can I find code snippets for WebViewer 5.0 or earlier?

World's #1 PDF SDK Library for Web, Mobile, Server, Desktop

With the release of WebViewer 6.0, code snippets of all the guides have been updated to include only `v6.0+` and `v5.1+`. If you are still using WebViewer 5.0.x, you can use `v5.1+` snippets with a few tweaks.

The biggest difference between WebViewer 5.1 and 5.0 is how it is instantiated. The promisified instantiation isn't available in 5.0 so you need to listen to the `ready` event instead. Also, objects and namespaces such as `Annotations`, `Tools`, `CoreControls` aren't attached to the `instance` object in 5.0 so you need to grab them from the iframe window.

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
// v5.1+
WebViewer({
  ...
}, document.getElementById('viewer'))
  .then(instance => {
    const {
      docViewer,
      annotManager,
      Tools,
      Annotations,
      CoreControls,
      PartRetrievers,
      Actions,
      PDFNet,
    } = instance;

    // call instance APIs here
  });
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
// v5.0
const viewerElement = document.getElementById('viewer');
const viewer = new PDFTron.WebViewer({
  ...
}, viewerElement);

viewer.addEventListener('ready', () => {
  const instance = viewer.getInstance();
  
  const docViewer = instance.docViewer;
  const annotManager = docViewer.getAnnotationManager();
  const {
    Tools,
    Annotations,
    CoreControls,
    PartRetrievers,
    Actions,
    PDFNet,
  } = document.querySelector('iframe').contentWindow;
  
  // call instance APIs here
});
```

{% endcode %}
{% 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/get-started/faq/webviewer-5.0-snippets.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.
