> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Document scanner

> Scan documents with the device camera, with automatic edge detection, cropping, and enhancement, and get the result as a base64 JPEG.

Scan documents using the device camera with automatic image enhancement and cropping. The Median Document Scanner plugin enables document uploads and improves scan quality by using native image processing.

## Key features

* Detects document edges and outlines in real time
* Automatically corrects angle, perspective, and aspect ratio
* Enhances text clarity and sharpness
* Crops and exports the document as a clean final scan
* Supports JPEG output in base64 format

The scanned image is made available as a base64 JPEG file through the Median JavaScript Bridge where it can be attached to a form or uploaded to your server asynchronously.

> [!TIP]
>
> **Test  with our demo page**
>
> We host a ready-made demo page at
>
> that calls the  features through the Median JavaScript Bridge.
> Load it inside your Median app during development, either by setting it
> as your app's website URL in App Studio or by navigating to it from your
> own site, and use it to confirm  works on a real device before
> you add it to your own pages.
>
> The demo page only works inside a Median app with  enabled.
> Opened in a regular mobile or desktop browser, the native features
> won't respond. Remember to switch your app back to your own URL before
> release.

## iOS scan and crop preview

| iOS - Scan | iOS - Crop |
| :-: | :-: |
| ![Document scanner detecting document edges on iOS](https://mintcdn.com/median-co/dZQPJ_0wlG7WNBTy/images/docs/0833226-iOSScan.jpeg?fit=max\&auto=format\&n=dZQPJ_0wlG7WNBTy\&q=85\&s=7566dc9c92dd57c3fb835a66f70fc876) | ![Document scanner crop screen on iOS](https://mintcdn.com/median-co/dZQPJ_0wlG7WNBTy/images/docs/427d326-iOSCrop.jpeg?fit=max\&auto=format\&n=dZQPJ_0wlG7WNBTy\&q=85\&s=770dcbe180ffc0463250cf15ecc8bc49) |

## Android scan and crop preview

| Android - Scan | Android - Crop |
| :-: | :-: |
| ![Document scanner detecting document edges on Android](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/aae07ab-AndroidScan.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=396b44287e93016b9f48463d805c575a) | ![Document scanner crop screen on Android](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/8d21431-AndroidCrop.png?fit=max\&auto=format\&n=7LCOHMhgIef7ewYE\&q=85\&s=d550ea9135df08c81e03887f56b08df7) |

## Implementation guide

### Initiate a document scan

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.documentScanner.scanPage({'callback':CALLBACKFUNCTION});
```

**Note:** Replace `CALLBACKFUNCTION` with your JavaScript function name.

### Handle the scanned image

Your callback function will receive an object with the following structure:

```javascript JavaScript theme={null}
{
  image: "base64-encoded string", // Scanned JPEG image
  mimeType: "image/jpeg",
  encoding: "base64"
}
```

#### Example implementation

Here's a sample code snippet that displays the scanned image output.

Median JavaScript Bridge

```html HTML theme={null}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Document Scanner Test</title>
<script>
  function cb(data) {
    document.getElementById('page').setAttribute('src', 'data:' + data.mimeType +
    ';' + data.encoding + ', ' + data.image);
  }
</script>
  <style>
  img
  {
      max-width: 100%;
      min-width: 300px;
      height: auto;
  }
  </style>
</head>
  <body>

    <h1>Document Scanner test</h1>

    <p>
      <a onclick="median.documentScanner.scanPage({'callback':cb});">Scan page</a>
    </p>

    <p>
      <img id="page" src="" />
    </p>

  </body>

</html>
```


## Related topics

- [Scanning](https://docs.median.co/docs/scanning.md)
- [Changelog archive](https://docs.median.co/docs/changelog-archive.md)
- [QR / barcode scanner](https://docs.median.co/docs/qr-barcode-scanner.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.