/DocumentScannerView

Native document scanning in SwiftUI

Primary LanguageSwiftMIT LicenseMIT

DocumentScannerView

DocumentScannerView is a SwiftUI wrapper of VNDocumentCameraViewController. Use it for scanning documents using the native document scanner.

Example

To use DocumentScannerView, you can either:

Present it inside the ViewBuilder of a .fullScreenCover(isPresented:) ViewModifier:

...

@ViewBuilder
var body: some View {
    // {Other View Content}
        .fullScreenCover(isPresented: $showScanner) {
            DocumentScannerView { scanResult in
                switch scanResult {
                case .success(let pages): // pages can either be [UIImage] or a PDFDocument
                    // Do something with the scan
                case .failure(let error):
                    // Deal with error
                }
            }
        }
}

...

OR

You can use the provided ViewModifier:

...

@ViewBuilder
var body: some View {
    // {Other View Content}
        .documentScanner(isPresented: $showScanner) { scanResult in
            switch scanResult {
            case .success(let pages): // pages can either be [UIImage] or a PDFDocument
                // Do something with the scan
            case .failure(let error):
                // Deal with error
            }
        }
}

...