Appearance
Mobile Web Capture API Reference / MobileWebCapture
Class: MobileWebCapture
MobileWebCapture is the primary class of Mobile Web Capture: it owns the Views, the scanner, and the document library, and drives the workflow that scans, organizes, annotates, and exports multi-page documents.
Remarks
Instantiating the class builds the UI; MobileWebCapture.launch starts the workflow and MobileWebCapture.dispose tears it down. A single instance runs one workflow at a time — dispose it before launching again.
See
Example
javascript
const mobileWebCapture = new Dynamsoft.MobileWebCapture({
license: "YOUR_LICENSE_KEY_HERE",
});
const fileName = `New_Document_${Date.now().toString().slice(-5)}`;
await mobileWebCapture.launch(fileName);Constructors
Constructor
new MobileWebCapture(
config):MobileWebCapture
Creates a Mobile Web Capture instance and its UI.
Parameters
config
Settings for the instance. MobileWebCaptureConfig.license is required; everything else falls back to a default.
Returns
MobileWebCapture
Example
javascript
const mobileWebCapture = new Dynamsoft.MobileWebCapture({
license: "YOUR_LICENSE_KEY_HERE",
documentScannerConfig: {
showResultView: false,
showCorrectionView: false,
},
});Methods
dispose()
dispose():
Promise<void>
Closes this Mobile Web Capture instance and releases everything it holds.
Returns
Promise<void>
Remarks
Tears down every View and the scanner, deletes the documents held in memory, empties the container (removing it too, if MWC created it), and calls MobileWebCaptureConfig.onClose. The instance can be launched again afterwards.
Example
javascript
await mobileWebCapture.dispose();
console.log("MWC resources released.");initialize()
initialize():
Promise<void>
Loads the resources this instance needs — the scanner, the Document Viewer engine, and the Views.
Returns
Promise<void>
Remarks
MobileWebCapture.launch calls this itself, so it rarely needs calling directly. Doing so ahead of time moves the loading cost off the critical path. Repeat calls are no-ops.
launch()
launch(
file?,view?):Promise<void>
Starts the Mobile Web Capture workflow, initializing the instance first if needed.
Parameters
file?
string | File
An existing File to open as the initial document, or a name for a new empty one. Omitted, a new document is named Doc-<timestamp>.
view?
The View to open first. EnumMWCViews.Library is only honored when showLibraryView is enabled.
Returns
Promise<void>
Remarks
Which View opens first depends on the arguments and on MobileWebCaptureConfig.showLibraryView. Passing a file always opens the DocumentView on it, unless view explicitly asks for the LibraryView and the LibraryView is enabled. Passing nothing opens the LibraryView when it is enabled, and otherwise the DocumentView on a new document named Doc-<timestamp>.
From there the user builds the document by capturing page images or importing existing images and PDFs.
Throws
An error if this instance is already running — MobileWebCapture.dispose it first.
Examples
Launch with a new, empty document:
javascript
const fileName = `New_Document_${Date.now().toString().slice(-5)}`;
await mobileWebCapture.launch(fileName);Launch with a file the user picked, disposing first so a second pick reopens rather than throws:
javascript
let launched = false;
document.getElementById("initialFile").onchange = async function () {
const files = Array.from(this.files || []);
if (files.length) {
if (launched) await mobileWebCapture.dispose();
await mobileWebCapture.launch(files[0]);
launched = true;
}
};