> 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-pdf-viewer-mobile.md).

# PDF Viewer Mobile Showcase Demo Code Sample

Quickly enable PDF document viewing dimensions on mobile devices using our code sample.

{% 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/pdf-viewer-mobile" class="button primary">Live demo</a>
{% endhint %}

Quickly enable PDF document viewing dimensions on mobile devices, such as Galaxy S5, Pixel 2, iPhones, and iPads. Adjust to these preset screen dimensions or define your own customized size.

This demo allows you to:

* View documents on mobile screens using preset screen dimensions
* Define custom screen dimensions via typing the values in the text field (Width x Height in pixels)
* Upload your own PDF file

Looking for more mobile application support? Please check out all of our [Mobile SDK capabilities](/mobile/apryse-mobile-sdks.md).

### **Implementation steps**

To add PDF mobile viewing capability 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 Model - August 26, 2025
// File: pdf-viewer-mobile/index.js

import WebViewer from '@pdftron/webviewer';

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

const devices = [
  { label: 'Galaxy S5', value: 'galaxys5', checked: true, size: { width: 360, height: 640 } },
  { label: 'Pixel 2', value: 'pixel2', size: { width: 411, height: 731 } },
  { label: 'iPhone 6/7/8', value: 'iphone678', size: { width: 375, height: 667 } },
  { label: 'iPhone X', value: 'iphonex', size: { width: 375, height: 812 } },
  { label: 'iPad', value: 'iPad', size: { width: 768, height: 1024 } },
  { label: 'iPad Pro', value: 'iPadPro', size: { width: 1024, height: 1366 } },
];

function setViewerSize() {
  const width = parseInt(textWidth.value, 10);
  const height = parseInt(textHeight.value, 10);

  element.style.height = `${height}px`;
  const inner = document.getElementById('wc-viewer');
  inner.style.width = `${width}px`;
  inner.style.height = `${height}px`;
}

const element = document.getElementById('viewer');
const onLoad = async () => {
  element.style.display = 'flex';
  element.style.alignItems = 'center';
  element.style.justifyContent = 'center';

  setTimeout(() => {
    textWidth.value = devices[0].size.width;
    textHeight.value = devices[0].size.height;
    setViewerSize();
  }, 500);

};

// Initialize WebViewer and load default document
WebViewer(
  {
    path: '/lib',
    licenseKey: licenseKey, 
    initialDoc: 'https://apryse.s3.amazonaws.com/public/files/samples/magazine.pdf',
    enableFilePicker: true, // Enable file picker to open files. In WebViewer -> menu icon -> Open File
  },
  element
).then(() => {
  onLoad();
});

// UI section
//
// Helper code to add controls to the viewer holding the buttons and dropdown

// Create a container for all controls (labels, radio buttons and button)
const controlsContainer = document.createElement('div');

// Rotation state
let rotated = false;

// Create a radio group for devices
const deviceGroup = document.createElement('div');
deviceGroup.className = 'device-group';
devices.forEach(device => {
  const label = document.createElement('label');
  label.textContent = device.label;
  label.htmlFor = device.value;
  label.className = 'radio-label-class';

  const radio = document.createElement('input');
  radio.type = 'radio';
  radio.name = 'device';
  radio.id = device.value;
  radio.value = device.value;
  radio.checked = device.checked;


  radio.onchange = () => {
    const selectedDevice = devices.find(d => d.value === radio.value);
    if (selectedDevice) {
      let w = selectedDevice.size.width;
      let h = selectedDevice.size.height;
      if(rotated){
        [w, h] = [h, w];
      }
      textWidth.value = w;
      textHeight.value = h;
      setViewerSize();
    }
  };

  deviceGroup.appendChild(radio);
  deviceGroup.appendChild(label);
});
controlsContainer.appendChild(deviceGroup);

const labelWidth = document.createElement('label');
labelWidth.textContent = 'W:';
labelWidth.className = 'label-class';
controlsContainer.appendChild(labelWidth);

const textWidth = document.createElement('input');
textWidth.type = 'text';
textWidth.className = 'text-style';
textWidth.oninput = () => {
  setViewerSize();
};

controlsContainer.appendChild(textWidth);

const labelHeight = document.createElement('label');
labelHeight.textContent = 'H:';
labelHeight.className = 'label-class';
controlsContainer.appendChild(labelHeight);

const textHeight = document.createElement('input');
textHeight.type = 'text';
textHeight.className = 'text-style';

textHeight.oninput = () => {
  setViewerSize();
};

controlsContainer.appendChild(textHeight);

// Create a button to swap dimensions
const buttonSwap = document.createElement('button');
buttonSwap.className = 'btn-style';
buttonSwap.onclick = async () => {
  rotated = !rotated;
  [textWidth.value, textHeight.value] = [textHeight.value, textWidth.value];
  setViewerSize();
};

// button's image
const img = new Image(20, 20);
img.src = "images/mobile-rotate-blue6.svg";
img.style.width = "20px";
img.style.height = "20px";

buttonSwap.appendChild(img);

controlsContainer.appendChild(buttonSwap);

// Apply classes for styling using CSS
controlsContainer.className = 'control-container';

// Append elements to the controls container
element.parentElement.insertBefore(controlsContainer, element);

</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-pdf-viewer-mobile.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.
