> 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/samples/showcase-demo-image-to-pdf.md).

# Image to PDF Showcase Demo Code Sample

Easily convert image formats to PDF, completely client-side.

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="/web/get-started/readme.md" class="button primary">Web SDK</a><a href="https://showcase.apryse.com/image-to-pdf" class="button primary">Live demo</a>
{% endhint %}

Easily convert images to PDF, entirely on the client side, with no server required. This follows the Image to PDF demo on showcase.

This demo allows you to:

* Upload your own image format file (such as PNG, JPG, GIF, PNG, BMP, etc.)
* Add customized annotations
* Edit the layout and content
* Download the updated PDF

### **Implementation steps**

To add image format conversion to PDF with WebViewer: Step 1: [Get started with WebViewer](/web/get-started/readme.md) in your preferred web stack Step 2: Add the ES6 JavaScript sample code provided in this guide

Once you generate your license key, it will automatically be included in your sample code below.

{% @apryse-license-key/apryse-license-key platform="WEB\_VIEWER" variant="compact" %}

<pre class="language-js" data-line-numbers><code class="lang-js">// ES6 Compliant Syntax
// GitHub Copilot - GPT-4 - July 21, 2025
// File: index.js

import WebViewer from '@pdftron/webviewer';
import saveAs from 'file-saver';

const licenseKey = '<code class="expression">visitor.claims.wvKey || "YOUR_WEBVIEWER_LICENSE_KEY"</code>';

// Customize the WebViewer UI
const customizeUI = (instance) => {
  const { UI } = instance;

  // Set the toolbar group to the annotate tools
  UI.setToolbarGroup('toolbarGroup-Annotate');

  // Convert button
  const convertButton = new UI.Components.CustomButton({
    dataElement: 'convertToPdfButton',
    className: 'custom-button-class',
    label: 'Image to PDF',
    onClick: () => convert(instance), // convert the image to PDF
    style: {
      padding: '10px 10px',
      backgroundColor: 'blue',
      color: 'white',
    }
  });

  const defaultHeader = UI.getModularHeader('default-top-header');
  defaultHeader.setItems([...defaultHeader.items, convertButton]);
};

// convert the image to PDF
const convert = async (instance) => {

  // Get the document
  const document = instance.Core.documentViewer.getDocument();

  // Get the filename
  let fileName = document.getFilename();

  // Ensure it ends with .pdf. If not, replace it with .pdf extension
  if (!fileName.endsWith('.pdf'))
    fileName = fileName.replace(/\.[^/.]+$/, '') + '.pdf';

  try {
    const data = await document.getFileData({
      downloadType: 'pdf',
    });

    const arr = new Uint8Array(data);
    const blob = new Blob([arr], { type: 'application/pdf' });

    // Save the image as a PDF
    saveAs(blob, fileName);

  } catch (e) {
    console.error('❌ Conversion failed:', e);
  }
};

WebViewer(
  {
    path: '/lib',
    initialDoc: 'https://apryse.s3.us-west-1.amazonaws.com/public/files/samples/Vancouver_komal-brar.jpg',
    enableFilePicker: true, // Enable file picker to open files. In WebViewer -> menu icon -> Open File
    licenseKey: licenseKey, 
  },
  document.getElementById('viewer')
).then((instance) => {

  // customize WebViewer UI
  customizeUI(instance);

  console.log('✅ WebViewer loaded successfully.');
}).catch((error) => {
  console.error('❌ Failed to initialize WebViewer:', error);
});
</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/get-started/samples/showcase-demo-image-to-pdf.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.
