Skip to content

Integrate scanning

Foxit PDF SDK for iOS provides the FoxitPDFScanUI module to scan documents with the device camera and convert them to PDF.

Prerequisites

  1. Add FoxitPDFScanUI.framework to the project (see Integrate SDK).
  2. Configure camera permission in Info.plist:
xml
<key>NSCameraUsageDescription</key>
<string>Camera access is required for document scanning</string>

Core classes

ClassDescription
PDFScanManagerScan module singleton: initialization, scan UI, and saving results
PDFScanToolbarManagerScan UI toolbar manager
PDFScanMenuViewManagerScan UI menu view manager

Initialize the scan module

The scan module requires its own serial numbers for initialization:

objc
#import <FoxitPDFScanUI/PDFScanManager.h>

// Initialize with serial numbers
FSErrorCode ret = [PDFScanManager initializeScanner:serial1 serial2:serial2];
if (ret != FSErrSuccess) {
    NSLog(@"扫描模块初始化失败");
}

Note

Scan serial numbers (serial1, serial2) differ from the main SDK license. Find scan license details in the SDK package.

Present the scan view

Get the singleton PDFScanManager, then present the scan view controller:

objc
PDFScanManager *scanManager = [PDFScanManager shareManager];
UIViewController *scanVC = [scanManager getPDFScanView];
[self presentViewController:scanVC animated:YES completion:nil];

Handle scan results

Set a callback to receive the output PDF path when scanning completes:

objc
// Set completion callback
[PDFScanManager setDoneCallBack:^(NSError *error, NSString *savePath) {
    if (!error && savePath) {
        NSLog(@"扫描完成,输出路径: %@", savePath);
        // Open the scanned PDF with FSPDFViewCtrl
        [self.pdfViewCtrl openDoc:savePath password:nil completion:nil];
    }
}];

Save as PDF

objc
PDFScanManager *scanManager = [PDFScanManager shareManager];

// Set Save As callback
[PDFScanManager setSaveAsCallBack:^(NSError *error, NSString *savePath) {
    if (!error) {
        NSLog(@"另存为成功: %@", savePath);
    }
}];

[scanManager saveAsPDF:@"path/to/output.pdf"];

Customize scan UI

Show or hide buttons on the camera screen:

objc
PDFScanManager *scanManager = [PDFScanManager shareManager];

// Hide flash button
[scanManager setItemHiddenWithType:FSScanCameraControllerItemTypeFlashLight hidden:YES];

// Hide photo library button
[scanManager setItemHiddenWithType:FSScanCameraControllerItemTypePhotos hidden:YES];

Hideable item types:

ConstantDescription
FSScanCameraControllerItemTypeFlashLightFlash
FSScanCameraControllerItemTypeSingleShootingSingle capture
FSScanCameraControllerItemTypePhotosPhoto library
FSScanCameraControllerItemTypeAutoDectionAuto detect
FSScanCameraControllerItemTypeFormatPageSizePage size

Important

Scanning requires a physical device; the iOS Simulator has no camera.

API reference

See the API reference for full PDFScanManager documentation.