How to Enable Scanning to PDF in your iPhone App

It’s the mobile age. Users tend to do everything via mobile devices for its convenience.

So how do we make document scanning mobile? How to turn your iPhone camera into a scanner? In this post, we will talk about how to create a new iOS app for scanning documents to PDF using iPhone with Dynamsoft Camera SDK iOS Edition, a document scanning library for iOS.

Key Features of Dynamsoft Camera SDK for iOS

  • Automatic edge detection and perspective correction
  • Image enhancement which includes image cleanup, removal of noise, shadows, distortions etc.
  • Export images as JPEG, PNG or PDF to local or web server
  • Customizable UI


  • Dynamsoft Camera SDK for iOS
  • Xcode 6.0 or above

Embed Document Scan in your iPhone APP

  1. Activate your app in the Dynamsoft portal.
  2. Install Dynamsoft Camera SDK for iOS using CocoaPods or install it manually.
  3. Add document capture to your app. Here we use Swift as an example.Please open ViewController.swift file and add the following code:
    class ViewController: UIViewController {
        var openVideoViewButton:UIButton!
        var dcsView:DcsView!
        override func viewDidLoad() {
            // Do any additional setup after loading the view, typically from a nib.
            dcsView = DcsView.self.init(frame:CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height));
            //Show VideoView when DcsView is loaded
            ///////////////////video view settting//////////////////
            //Set the videoview capture mode to document mode
            dcsView.videoView.mode = DME_DOCUMENT
            //Set the next view after the cancel or capture button is clicked.
            dcsView.videoView.nextViewAfterCancel = DVE_IMAGEGALLERYVIEW
            dcsView.videoView.nextViewAfterCapture = DVE_EDITORVIEW
            openVideoViewButton = UIButton(frame:CGRect(,, width: 200, height: 40))
            openVideoViewButton.setTitle("Back to Camera", for: .normal)
            openVideoViewButton.setTitleColor(, for: .normal)
            openVideoViewButton.addTarget(self, action:#selector(onClick), for:UIControlEvents.touchUpInside);
        override func didReceiveMemoryWarning() {
            // Dispose of any resources that can be recreated.
        @objc func onClick(){
  4. See document scan in action.Now if you launch the Hello World project, it will look like this:

    scan document in an iOS App

    Click the capture button, the document will show in the built-in editor view.

    document editor view

Scan to PDF

Now let’s save the captured document as PDF.

// Save the images of index 1-5 in buffer as a multi-page PDF 
let documentDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
let fileURL = documentDir!.appendingPathComponent("filename.pdf")
var indices = [Int]()
for i in 1...5 {
    if i < dcsView.buffer.count() {
let pdfEncode = DcsPDFEncodeParameter(), file: fileURL.path, encodeParameter: pdfEncode)

Try for Free

We provide 30-day free trial SDK, free demo app and also sample code for you to get started smoothly.

Subscribe Newsletter

Subscribe to our mailing list to get the monthly update.