> 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/web/get-started/faq/webviewer-5.0-snippets.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
