跳转到内容

Getting Started

此内容尚不支持你的语言。

  1. Install the plugin

    Terminal window
    npm i @capgo/capacitor-document-scanner
  2. Sync native platforms

    Terminal window
    npx cap sync

Trigger a scan

import {
DocumentScanner,
ResponseType,
ScanDocumentResponseStatus,
} from '@capgo/capacitor-document-scanner';
const result = await DocumentScanner.scanDocument({
croppedImageQuality: 90,
letUserAdjustCrop: true,
maxNumDocuments: 10,
responseType: ResponseType.ImageFilePath,
});
if (result.status === ScanDocumentResponseStatus.Success) {
console.log('Scanned files:', result.scannedImages);
} else {
console.log('Scan cancelled by user');
}

Return base64 data

const result = await DocumentScanner.scanDocument({
responseType: ResponseType.Base64,
});
const [firstPage] = result.scannedImages ?? [];
if (firstPage) {
const dataUrl = `data:image/jpeg;base64,${firstPage}`;
// Display preview or upload to server
}

Platform requirements

  • iOS: Add NSCameraUsageDescription to ios/App/App/Info.plist explaining how you use the camera.
  • Android: Confirm that CAMERA permission is declared (Capacitor adds it automatically) and adjust croppedImageQuality, letUserAdjustCrop, and maxNumDocuments to match your UI.
  • Storage: When using ResponseType.ImageFilePath, move or copy the scanned files to your desired storage location before the app session ends.