Getting Started
此内容尚不支持你的语言。
-
Install the plugin
Terminal window npm i @capgo/capacitor-document-scannerTerminal window pnpm add @capgo/capacitor-document-scannerTerminal window yarn add @capgo/capacitor-document-scannerTerminal window bun add @capgo/capacitor-document-scanner -
Sync native platforms
Terminal window npx cap syncTerminal window pnpm cap syncTerminal window yarn cap syncTerminal window bunx 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
NSCameraUsageDescriptiontoios/App/App/Info.plistexplaining how you use the camera. - Android: Confirm that
CAMERApermission is declared (Capacitor adds it automatically) and adjustcroppedImageQuality,letUserAdjustCrop, andmaxNumDocumentsto match your UI. - Storage: When using
ResponseType.ImageFilePath, move or copy the scanned files to your desired storage location before the app session ends.