快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
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.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-document-scanner` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
bun add @capgo/capacitor-document-scannerbunx cap sync导入
“导入”章节import { DocumentScanner } from '@capgo/capacitor-document-scanner';快速入门
章节标题为“快速入门”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]);}示例:多页数据包
章节标题:“示例:多页文档包”const result = await DocumentScanner.scanDocument({ maxNumDocuments: 12, letUserAdjustCrop: true, reviewCapturedDocument: true,});原生扫描器支持每次会话最多 24 页。
示例:调优后的 Android 清理
章节标题:“示例:调整后的 Android 清理”import { ScannerMode } from '@capgo/capacitor-document-scanner';
await DocumentScanner.scanDocument({ scannerMode: ScannerMode.Full, brightness: 0.1, contrast: 1.2,});scannerMode 和 ML 清理选项仅支持 Android。请参阅 scanDocument 查看完整列表。
常见坑点
章节标题为“常见陷阱”- Web 端:请准备回退方案(文件选择器或手动拍照),因为扫描仅支持原生环境。
- 用户取消:
status可以cancel且无图像时,按其他关闭操作处理即可。 - 输出类型:选择
imageFilePath或通过 base64responseType在配置上传之前。
API 概览
章节标题:“API 概览”scanDocument
标题为 “scanDocument” 的章节打开设备摄像头并启动文档扫描体验。
import { DocumentScanner } from '@capgo/capacitor-document-scanner';
const result = await DocumentScanner.scanDocument();console.log(result);类型参考
“类型参考” 章节ScanDocumentOptions
标题为 “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
标题为 “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
标题为 “ResponseType” 的章节export enum ResponseType { /** * Return scanned images as base64-encoded strings. */ Base64 = 'base64',
/** * Return scanned images as file paths on disk. */ ImageFilePath = 'imageFilePath',}ScannerMode
标题为 “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
标题为 “ScanDocumentResponseStatus” 的章节export enum ScanDocumentResponseStatus { /** * The scan completed successfully. */ Success = 'success',
/** * The user cancelled the scan flow. */ Cancel = 'cancel',}单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-document-scanner 关于“使用 @capgo/capacitor-document-scanner”中的原生能力, API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。