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() 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)
twainPro1 = new Accusoft.TwainProSdk.TwainPro();
twainDevice = new TwainDevice(twainPro1);
twainDevice.ShowUserInterface = false;
twainDevice.Scanned += new Accusoft.TwainProSdk.ScannedEventHandler(twainDevice_Scanned);
catch (Exception ex)
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");
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 www.accusoft.com/imagxpressdownload.htm.
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.