Click here to Skip to main content
13,410,009 members (37,545 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 7 Sep 2011

Scan Directly to Google Docs

, 7 Sep 2011
Enterprises use cloud services to save money on storage, desktop software and facilitate collaboration with coworkers. Provide applications the ability to capture images locally from a scanner and upload to the Cloud in just a few lines of code.

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.


Cloud services have gained popularity for very good reasons.  Enterprises can use these services to save money on storage, desktop software and to facilitate better collaboration with coworkers. 

One of the most popular cloud services for document management is Google Docs.  Google Docs is an extremely easy to use free document solution that works with most existing document formats without the need of desktop software.  Users can work in the cloud with Google Docs, access their documents from any computer connected to the Internet and easily share their document to collaborate with co-workers.  Google also makes its popular service available to application developers in the form of their Google Data SDK.  The SDK contains many easy to follow samples and is available for a variety of platforms including .NET. 

Document capture from scanners is a challenge for cloud services since they need access to the scanner drivers running locally on a machine.  Combining an easy to use image scanning component with Google’s SDK provides applications the ability to capture images locally from a scanner and then upload to the Cloud in just a few lines of code. TwainPRO is an easy to use Twain scanning component available in the ImagXpress family of imaging components from Accusoft Pegasus.  ImagXpress contains components for scanning, image processing, annotations and printing.  The component architecture of ImagXpress provides application developers with the flexibility to include “just the right amount” of imaging support for their applications.  This whitepaper will detail how to combine image capture using TwainPRO with the Google Data SDK to enable applications to scan directly to Google Docs.

How the Sample Works

The Google Data SDK includes a sample called DocListUploader that shows how to use the SDK to upload documents to Google Docs.  Upon logging in, the sample shows a list of the user’s documents.  The user can then drag and drop documents onto the form and the sample application will upload the documents to the user’s Google Docs accounts.  Finally, the sample refreshes the document list to show that the document has been uploaded to the user’s Google Docs account.

DocListUploader was the starting point to the TwainPROScanToGoogleDocs sample application, available on Accusoft Labs.  To demonstrate the ability to use TwainPRO to scan to Google Docs, a button was added to the form and in less than 20 lines of code, we have a simple cloud scanning application. Let’s take a look at how this is done.

Integrating TwainPRO with the Google Data SDK

The TwainPRO component makes it very easy to capture an image using a scanner.  The main TwainPRO class controls the operations of the component, such as licensing and logging.  The real Twain capture work is handled by the TwainDevice class.  So to add scanning capabilities to the DocListUploader sample, we first need to create our TwainPRO objects:

private Accusoft.TwainProSdk.TwainDevice twainDevice;
private Accusoft.TwainProSdk.TwainPro twainPro1;

Setting up the TwainPRO Actions

To add scanning to the Google Data SDK sample, we chose to add a button to allow the user to scan to Google Docs once they logged into their account.  A simple method was written to set up the scanning action once the user clicks on the scan button. 

The main methods of the TwainDevice class that handle image acquisition from the scanner are SelectSource() and StartSession().  The SelectSource() method brings up the Twain Data Source Manager user interface to allow the user to select a scanner.  Once the user selects a scanner source, StartSession() drives the scanner to acquire an image.  The ShowUserInterface() allows a TwainPRO developer to specify whether or not to suppress the scanner’s user interface.  Lastly, we need to add a ScannedEventHandler so we can work with the image acquired from the scanner.

private void TwainProButton_Click(object sender, EventArgs e)
//create instances of TwainPro and TwainDevice
      twainPro1 = new Accusoft.TwainProSdk.TwainPro();
      twainDevice = new TwainDevice(twainPro1);
//hide or show the scanner’s UI
      twainDevice.ShowUserInterface = false;
//Add the Scanned event
twainDevice.Scanned += new Accusoft.TwainProSdk.ScannedEventHandler(twainDevice_Scanned);
      catch (Exception ex)
            //handle the exception

Upload the Scanned Image to Google Docs

At this point our TwainPRO component has connected to a scanner, started a scanning job and acquired an image.  Now we need to work with the resulting image.  In the first method we defined, we created the twainDevice_Scanned event to fire once the scanner completes the image acquisition.  Now we need to create an event handler to capture the image data and upload the image to Google Docs. TwainPRO can work with several types of images.  A developer can choose to save the acquired image as JPEG, TIFF or PDF (the ImagXpress component can be added to provide support for many more image formats).  For this demo, we choose to save the image as a PDF and then call the UploadFile(filePath) method from the DocListUploader sample to upload our scanned image to Google Docs.

public void twainDevice_Scanned(object sender, Accusoft.TwainProSdk.ScannedEventArgs e)
      Accusoft.TwainProSdk.SaveOptions saveOptions = new SaveOptions();
      saveOptions.Format = ScannedImageFormat.Pdf;
      string strCurrentDir = System.IO.Directory.GetCurrentDirectory();
      string strPath = System.IO.Path.Combine(strCurrentDir, "AccusoftCloudScanDemo" + ".pdf");
         //upload our scanned document to Google Docs
         //refresh the file list in DocListUploader
      catch (ArgumentException)
  catch (Accusoft.TwainProSdk.TwainProException ex)


Just like that, we have now added the ability to scan to Google Docs in less than 20 lines of code. To access the full TwainPROScanToGoogleDocs sample visit Accusoft Labs. The TwainPRO component can be downloaded with ImagXpress at

About the Author

Steve Wilson joined Accusoft Pegasus in 2007. As a Product Group Director, Steve coordinates the efforts of Engineers to further strengthen Accusoft Pegasus’ position in the imaging marketplace. Steve is responsible for leading his teams to develop new products as well as increase the feature sets within several Accusoft Pegasus product lines. He brings a strong technical background to the management team, as well as experience managing diverse offshore and onshore development teams. Steve earned a Bachelor of Science in Computer Science from the University of South Florida.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Organisation

1 members

You may also be interested in...

Comments and Discussions

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180221.1 | Last Updated 7 Sep 2011
Article Copyright 2011 by Accusoft
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid