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

# Convert image to PDF in JavaScript

Convert image to PDF in JavaScript effortlessly with WebViewer SDK. No server-side dependencies needed. Load various image formats and save as PDF with ease. The Apryse Web SDK streamlines secure, ser

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

## Using WebViewer

WebViewer supports loading images by default using [initialDoc](https://sdk.apryse.com/api/web/global.html#WebViewerOptions__anchor), or [loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor) API. After loading the document, you can get the document and [save](/web/open-save-document/save.md) it as a PDF or download it.

### WebViewer constructor

Load the image with the WebViewer constructor and it will load with the Viewer.

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

```js
WebViewer({
  ...,
  initialDoc: 'https://myserver.com/myfile.png',
}, document.getElementById('viewer'));
```

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

[WebViewer](https://sdk.apryse.com/api/web/global.html#WebViewer__anchor)

[Display & view documents using JavaScript](/web/get-started/guides/samples/viewing.md#viewing) Full sample code shows how to call WebViewer constructor to instantiate and load document. You can load local/remote files of your choice.

### Load document

Load the image with the load document method after WebViewer is initalized.

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

```js
WebViewer(...)
  .then(instance => {
    instance.UI.loadDocument('https://myserver.com/myfile.png', { filename: 'myfile.png' });
  });
```

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

[WebViewer](https://sdk.apryse.com/api/web/global.html#WebViewer__anchor) [WebViewerInstance.UI.loadDocument](https://sdk.apryse.com/api/web/UI.html#loadDocument__anchor)

[Display & view documents using JavaScript](/web/get-started/guides/samples/viewing.md#viewing) Full sample code shows how to call WebViewer constructor to instantiate and load document. You can load local/remote files of your choice.

### Load TIFF

WebViewer allows loading TIFF, TIF files in the sample below.

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

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

    await PDFNet.runWithoutCleanup(async () => { 
        const doc = await PDFNet.PDFDoc.create();
        doc.initSecurityHandler();
        doc.lock();

        const tiffFile = await PDFNet.Filter.createURLFilter("./files/test.tif");
        await PDFNet.Convert.fromTiff(doc, tiffFile);
        doc.unlock();
        UI.loadDocument(doc);
    });
});
```

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

## Without WebViewer UI

This code sample demonstrates how to convert image to PDF without initializing WebViewer UI.

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

```js
<html>
  <body>
    <script src="../lib/core/webviewer-core.min.js"></script>
    <script src="../lib/core/PDFNet.js"></script>
    <script>
    (async function() {
      Core.setWorkerPath('../lib/core');
      const doc = await Core.createDocument('https://myserver.com/myfile.png', { filename: 'myfile.png' });
      const data = await doc.getFileData();
      const arr = new Uint8Array(data);
      const blob = new Blob([arr], { type: 'application/pdf' });
    })()
    </script>
  </body>
</html>
```

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