Erste Schritte
Kopiere einen Setup-Prompt mit den Installationsschritten und dem vollständigen Markdown-Guide für dieses Plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-document-scanner`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/document-scanner/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Installieren
Abschnitt mit dem Titel „Installation“Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge deinem KI-Tool die Capgo Skills mit folgendem Befehl hinzu:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsNutze anschließend diesen Prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-document-scanner` plugin in my project.Wenn du ein manuelles Setup bevorziehst, installiere das Plugin mit den folgenden Befehlen und befolge die plattformspezifischen Anweisungen unten:
bun add @capgo/capacitor-document-scannerbunx cap syncImportieren
Abschnitt mit dem Titel „Import“import { DocumentScanner } from '@capgo/capacitor-document-scanner';Quickstart
Abschnitt mit dem Titel „Quickstart“import { DocumentScanner, ResponseType } from '@capgo/capacitor-document-scanner';
const result = await DocumentScanner.scanDocument({ maxNumDocuments: 1, responseType: ResponseType.ImageFilePath,});
if (result.status === 'success' && result.scannedImages?.length) { await uploadReceipt(result.scannedImages[0]);}Beispiel: Mehrseitiges Paket
Abschnitt mit dem Titel „Beispiel: Mehrseitiges Paket“const result = await DocumentScanner.scanDocument({ maxNumDocuments: 12, letUserAdjustCrop: true, reviewCapturedDocument: true,});Die nativen Scanner unterstützen bis zu 24 Seiten pro Session.
Beispiel: Optimiertes Android Cleanup
Abschnitt mit dem Titel „Optimiertes Android Cleanup“import { ScannerMode } from '@capgo/capacitor-document-scanner';
await DocumentScanner.scanDocument({ scannerMode: ScannerMode.Full, brightness: 0.1, contrast: 1.2,});scannerMode und ML-Cleanup-Optionen sind nur für Android verfügbar. Siehe Plugin-Optionen in scanDocument für die vollständige Liste.
Häufige Fehlerquellen
Abschnitt mit dem Titel „Häufige Fehlerquellen“- Web: Plane einen Fallback (File Picker oder manuelles Foto) ein, da das Scannen nur nativ möglich ist.
- User cancel:
statuskanncancelohne Bilder erfolgen; behandle es wie jedes andere Dismiss-Event. - Ausgabetyp: Wähle
imageFilePathoder base64 viaresponseTypebevor du Uploads einrichtest.
API Übersicht
Abschnitt mit dem Titel „API Übersicht“scanDocument
Abschnitt mit dem Titel „scanDocument“Öffnet die Gerätekamera und startet den Dokumentenscan.
import { DocumentScanner } from '@capgo/capacitor-document-scanner';
const result = await DocumentScanner.scanDocument();console.log(result);Typ-Referenz
Abschnitt mit dem Titel „Type Reference“ScanDocumentOptions
Abschnitt mit dem Titel „ScanDocumentOptions“export interface ScanDocumentOptions { /** * Android only: quality of the cropped image from 0 - 100 (100 is best). * @default 100 */ croppedImageQuality?: number;
/** * Allow the user to adjust the detected crop before saving. * On iOS this forces the native VisionKit preview/editor after each capture using * the private VisionKit navigation hooks needed to keep the scanner flow alive. * On Android this enables ML Kit's crop adjustment flow. * @default true */ letUserAdjustCrop?: boolean;
/** * When enabled, shows the current scanned page before continuing so the user can * review it and explicitly continue or finish the flow. * On iOS this forces the native VisionKit preview/editor between captures. * On Android this switches to a one-page-at-a-time flow between ML Kit sessions. * The review/editor screen is still shown automatically when the scan limit is reached. * @default false */ reviewCapturedDocument?: boolean;
/** * Maximum number of documents to scan. * On iOS: VisionKit caps scans at 24 pages (system limit), and the hacked native flow * can still stop earlier when you pass a smaller limit. * On Android: customizable limit; defaults to 20 for performance (clamped 1-24). * Set to 1 for single-scan mode where the scanner stops after one document. * @default 20 on Android, 24 on iOS */ maxNumDocuments?: number;
/** * Format to return scanned images in (file paths or base64 strings). * @default ResponseType.ImageFilePath */ responseType?: ResponseType;
/** * Brightness adjustment applied to scanned images. * Range: -255 to 255 (0 = no change, positive = brighter, negative = darker) * Useful for compensating low-light scans. * @default 0 */ brightness?: number;
/** * Contrast adjustment applied to scanned images. * Range: 0.0 to 10.0 (1.0 = no change, >1 = more contrast, <1 = less contrast) * Helps improve text clarity in poorly lit scans. * @default 1.0 */ contrast?: number;
/** * Android only: scanner mode that controls ML Kit features and filters. * - 'base': Basic scan with crop/rotate, no filters or ML cleaning * - 'base_with_filter': Adds grayscale and auto-enhancement filters * - 'full': All features including ML-based image cleaning (erases stains, fingers, etc.) * @default ScannerMode.Full */ scannerMode?: ScannerMode;}ScanDocumentResponse
Abschnitt mit dem Titel „ScanDocumentResponse“export interface ScanDocumentResponse { /** * Scanned images in the requested response format. */ scannedImages?: string[];
/** * Indicates whether the scan completed or was cancelled. */ status?: ScanDocumentResponseStatus;
/** * Get the native Capacitor plugin version * * @returns {Promise<{ id: string }>} an Promise with version for this device * @throws An error if the something went wrong */ getPluginVersion(): Promise<{ version: string }>;}ResponseType
Abschnitt mit dem Titel „ResponseType“export enum ResponseType { /** * Return scanned images as base64-encoded strings. */ Base64 = 'base64',
/** * Return scanned images as file paths on disk. */ ImageFilePath = 'imageFilePath',}ScannerMode
Abschnitt mit dem Titel „ScannerMode“export enum ScannerMode { /** * Basic document scanning with crop and rotate features only. * No filters or ML-based enhancements. */ Base = 'base',
/** * Basic features plus automatic filters (grayscale, auto-enhancement). */ BaseWithFilter = 'base_with_filter',
/** * Full feature set including ML-based image cleaning. * Automatically removes stains, fingers, and other artifacts. */ Full = 'full',}ScanDocumentResponseStatus
Abschnitt mit dem Titel „ScanDocumentResponseStatus“export enum ScanDocumentResponseStatus { /** * The scan completed successfully. */ Success = 'success',
/** * The user cancelled the scan flow. */ Cancel = 'cancel',}Source of Truth
Abschnitt mit dem Titel „Source of Truth“Diese Seite wird aus dem Plugin- src/definitions.ts. Führe den Sync erneut aus, wenn sich der öffentliche API upstream ändert.
Weiter mit Getting Started
Abschnitt „Weiter mit Getting Started“Wenn Sie ... verwenden Erste Schritte Um Dashboard- und API-Operationen zu planen, verbinde es mit Mit @capgo/capacitor-document-scanner für die native Funktionalität bei der Nutzung von @capgo/capacitor-document-scanner, API Übersicht für Details zur Implementierung in der Übersicht zu API, Einführung für das Implementierungsdetail in der Einleitung, API Keys für die Implementierungsdetails in den API Keys und Geräte für die Implementierungsdetails bei Devices.