> 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/conversion/convert-pdf-to-image.md).

# Convert PDF to image in JavaScript

Convert PDF to image formats like PNG, JPG, BMP, and TIFF using WebViewer SDK in the browser. No server-side dependencies needed. Learn how to rasterize PDF pages to images with ease. The Apryse Web S

Convert PDF to PNG, JPG, BMP, TIFF using WebViewer SDK in the browser without server-side dependencies. (You can also check out our [online PDF to Image demo](https://showcase.apryse.com/pdf-to-image) now.)

## Using WebViewer

You can rasterize PDF pages to an image and then save the resulting buffer to your database, file storage, or simply download it. The sample below demonstrates how to generate images with `FullAPI` enabled, you can also [generate images](/web/generate/thumbnail.md) using a lean build of WebViewer which should result in better performance.

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

```js
Webviewer({
    fullAPI: true,
}, viewerRef).then((instance) => {
    const { Core } = instance;
    const { documentViewer, PDFNet } = Core;
    
    await PDFNet.initialize();

    documentViewer.addEventListener('documentLoaded', async () => {
        const doc = await documentViewer.getDocument().getPDFDoc();
        const pdfdraw = await PDFNet.PDFDraw.create(92);
        const itr = await doc.getPageIterator(1);
        const currPage = await itr.current();

        const pngBuffer = await pdfdraw.exportBuffer(currPage, 'PNG');
        const tifBuffer = await pdfdraw.exportBuffer(currPage, 'TIFF');
    });
});
```

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

## Without WebViewer UI

This code sample demonstrates how to convert PDF to image without initializing WebViewer UI. The sample below demonstrates how to generate images with `FullAPI` enabled, you can also [generate images](/web/generate/thumbnail.md) using a lean build of WebViewer which should result in better performance.

<pre class="language-js" data-line-numbers><code class="lang-js">&#x3C;html>
  &#x3C;body>
    &#x3C;script src="../lib/core/webviewer-core.min.js">&#x3C;/script>
    &#x3C;script>
    (async function() {
      Core.setWorkerPath('../lib/core');
      Core.enableFullPDF();
      const licenseKey = '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>';
      await PDFNet.initialize();

      const doc = await PDFNet.PDFDoc.createFromURL('url_to_pdf');
      const pdfdraw = await PDFNet.PDFDraw.create(92);
      const itr = await doc.getPageIterator(1);
      const currPage = await itr.current();  
      const pngBuffer = await pdfdraw.exportBuffer(currPage, 'PNG');
      const tifBuffer = await pdfdraw.exportBuffer(currPage, 'TIFF');
    })()
    &#x3C;/script>
  &#x3C;/body>
&#x3C;/html>
</code></pre>


---

# 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/conversion/convert-pdf-to-image.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.
