|
| 1 | +# Dynamsoft Document Scanner for the Web |
| 2 | + |
| 3 | +**Dynamsoft Document Scanner (DDS)** is designed to handle the following use case: |
| 4 | + |
| 5 | +* Capturing a clear image of a physical document, such as a single-page patient intake form or the front side of a driver’s license. |
| 6 | + |
| 7 | + > DDS not only captures the document but also enhances its quality to meet professional standards. |
| 8 | +
|
| 9 | +## Key Features |
| 10 | + |
| 11 | +1. Capture single documents using mobile devices or webcams. |
| 12 | +2. Import a single local image of a document. |
| 13 | +3. Automatically detect document borders during image capture. |
| 14 | +4. Automatically capture and correct images to align with detected document boundaries. |
| 15 | +5. Export a single-page document as an image. |
| 16 | + |
| 17 | + > To deliver these features, DDS leverages the following Dynamsoft products: |
| 18 | + > |
| 19 | + > 1. **Dynamsoft Camera Enhancer (DCE)**: Focuses on image capture and video feed enhancement. |
| 20 | + > 2. **Dynamsoft Document Normalizer (DDN)**: Processes the captured document image, restoring its quality with cropping and perspective transformations. |
| 21 | +
|
| 22 | +## How to Use the SDK to Build a Web Page for Document Scanning |
| 23 | + |
| 24 | +### Step 1: Get a License |
| 25 | + |
| 26 | +DDS requires a license key to function. You can request a [30-day free trial license](https://www.dynamsoft.com/customer/license/trialLicense?product=mwc&source=readme) via our customer portal. |
| 27 | + |
| 28 | +### Step 2: Create a "Hello World" Page |
| 29 | + |
| 30 | +#### Option 1: Work with the GitHub Repository |
| 31 | + |
| 32 | +If you're **working with the [GitHub Repository](https://github.com/Dynamsoft/document-scanner-javascript)**, the "hello-world.html" page is available under the [`/samples`](https://github.com/Dynamsoft/document-scanner-javascript/tree/main/samples) directory. |
| 33 | + |
| 34 | +Find the following code snippet and replace `YOUR_LICENSE_KEY_HERE` with the license key you obtained in [Step 1](https://github.com/Dynamsoft/document-scanner-javascript/tree/main?tab=readme-ov-file#step-1-get-a-license). |
| 35 | + |
| 36 | +```js |
| 37 | +const documentScanner = new Dynamsoft.DocumentScanner({ |
| 38 | + license: "YOUR_LICENSE_KEY_HERE", |
| 39 | +}); |
| 40 | +``` |
| 41 | + |
| 42 | +#### Option 2: Create Your Own Page |
| 43 | + |
| 44 | +Alternatively, you can create an empty file named `hello-world.html`, paste the following code into it, and replace `YOUR_LICENSE_KEY_HERE` with the license key you obtained in [Step 1](https://github.com/Dynamsoft/document-scanner-javascript/tree/main?tab=readme-ov-file#step-1-get-a-license): |
| 45 | + |
| 46 | +```html |
| 47 | +<!DOCTYPE html> |
| 48 | +<html lang="en"> |
| 49 | + <head> |
| 50 | + <meta charset="utf-8" /> |
| 51 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 52 | + <title>Dynamsoft Document Scanner - Hello World</title> |
| 53 | + < script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/dbr.bundle.js"></ script> |
| 54 | + <style> |
| 55 | + html, |
| 56 | + body { |
| 57 | + margin: 0; |
| 58 | + padding: 0; |
| 59 | + box-sizing: border-box; |
| 60 | + font-family: Arial, sans-serif; |
| 61 | + background-color: #f9f9f9; |
| 62 | + } |
| 63 | + </style> |
| 64 | + </head> |
| 65 | + |
| 66 | + <body> |
| 67 | + <h1 style="font-size: large">Dynamsoft Document Scanner</h1> |
| 68 | + <div id="results"></div> |
| 69 | + |
| 70 | + <script> |
| 71 | + const resultContainer = document.querySelector("#results"); |
| 72 | +
|
| 73 | + // Initialize the Dynamsoft Document Scanner |
| 74 | + const documentScanner = new Dynamsoft.DocumentScanner({ |
| 75 | + license: "YOUR_LICENSE_KEY_HERE", |
| 76 | + }); |
| 77 | + (async () => { |
| 78 | + // Launch the scanner and wait for the result |
| 79 | + const result = await documentScanner.launch(); |
| 80 | + console.log(result); |
| 81 | +
|
| 82 | + // Clear the result container and display the scanned result as a canvas |
| 83 | + if (result?.correctedImageResult) { |
| 84 | + resultContainer.innerHTML = ""; // Clear placeholder content |
| 85 | + const canvas = result.correctedImageResult.toCanvas(); |
| 86 | + resultContainer.appendChild(canvas); |
| 87 | + } else { |
| 88 | + resultContainer.innerHTML = "<p>No image scanned. Please try again.</p>"; |
| 89 | + } |
| 90 | + })(); |
| 91 | + </script> |
| 92 | + </body> |
| 93 | +</html> |
| 94 | +``` |
| 95 | +
|
| 96 | +### Step 3: Run the "Hello World" Page |
| 97 | +
|
| 98 | +#### Option 1: Work with the GitHub Repository |
| 99 | +
|
| 100 | +If you're **working with the [GitHub Repository](https://github.com/Dynamsoft/document-scanner-javascript)**, follow these steps: |
| 101 | +
|
| 102 | +1. Install project dependencies: |
| 103 | +
|
| 104 | +```bash |
| 105 | +npm install |
| 106 | +``` |
| 107 | +
|
| 108 | +2. Build the project: |
| 109 | + |
| 110 | +```bash |
| 111 | +npm run build |
| 112 | +``` |
| 113 | +
|
| 114 | +3. Serve the project locally: |
| 115 | +
|
| 116 | +```bash |
| 117 | +npm run serve |
| 118 | +``` |
| 119 | +
|
| 120 | +4. Open the application: |
| 121 | +
|
| 122 | +After running `npm run serve`, the terminal will display the local address. Open the address in your browser to access the application. |
| 123 | +
|
| 124 | +> Notes on the Test Server (Development Only) |
| 125 | +> |
| 126 | +> This sample uses the web server provided by Express (https://expressjs.com/). It is intended solely for local development and testing purposes, and it lacks production-grade features like advanced security, scalability, and detailed logging. |
| 127 | +> |
| 128 | +> - The server is configured to run on **"localhost"** using port `3000` and on your computer's **local IP address** using port `3001` with SSL enabled via self-signed certificates. |
| 129 | +> - To access the application from a mobile device or another computer on your network, use your computer's **local IP address** and ensure the device is connected to the same Local Area Network (LAN). |
| 130 | +> - If there are multiple **local IP addresses**, choose one that works. |
| 131 | +> - You will get an security alert in the browser for "self-signed certificates", click "Advanced" to continue |
| 132 | +
|
| 133 | +#### Option 2: Run the Page You Created |
| 134 | +
|
| 135 | +If you created your own `hello-world.html` file (as described in [Step 2, Option 2](https://github.com/Dynamsoft/document-scanner-javascript/tree/main?tab=readme-ov-file#option-2-create-your-own-page)), follow these steps to run it: |
| 136 | +
|
| 137 | +1. Deploy to a web server: |
| 138 | +
|
| 139 | + - You can use a production server like IIS or Apache. |
| 140 | + - Alternatively, for local testing, use a simple server such as the [Five Server](https://marketplace.visualstudio.com/items?itemName=yandeu.five-server) extension for Visual Studio Code. |
| 141 | +
|
| 142 | +1. Access the file in your browser: |
| 143 | +
|
| 144 | + Once the server is running, open the URL where the file is served (e.g., http://localhost/hello-world.html). |
| 145 | +
|
| 146 | +## Contact us |
| 147 | +
|
| 148 | +If you encounter any issues, need assistance, or have suggestions, please don’t hesitate to reach out to us. You can: |
| 149 | +
|
| 150 | +- **Submit an issue** directly in this repository. |
| 151 | +- **Contact us through various channels** listed on our official [Contact Us](https://www.dynamsoft.com/contact/) page. |
| 152 | +
|
| 153 | +We’re here to help! |
0 commit comments