Have Fun with the WPF Demo of .NET TWAIN 5.0

Dynamic .NET TWAIN 5.0 has been released for a while. To help users to quickly grasp APIs, a brand-new API demo, written in WPF with C# & VB.NET, is included. In this tutorial, we would like to show the anatomy of this application. Let’s glance at the screenshot as a warm up. As you can see, the functionalities of the demo include scanner control, image loading, barcode recognition, OCR, image manipulation and processing.

WPF UI

How to install Dynamic .NET TWAIN 5.0?

Visit Dynamic .NET TWAIN page and get the installation package by clicking Download button. Follow the InstallShield Wizard step by step.

Where is the API demo?

The demo source code is located at “…\Dynamsoft\Dynamic .NET TWAIN 5.0 Trial\Samples\C# Samples\VS 12” and “…\Dynamsoft\Dynamic .NET TWAIN 5.0 Trial\Samples\VB .NET Samples\VS 12\WpfControlsDemo”. You can choose your preferred programming language, C# or VB.NET.

What does the project look like in Visual Studio?

WPF project

The reference DynamicDotNetTWAIN.Wpf.dll is located at “…\Dynamsoft\Dynamic .NET TWAIN 5.0 Trial\Samples\Bin”. It will be copied to your project folder when you run the Visual Studio solution file “WpfControlsDemo.sln”. If you want to create your own project, don’t forget to add it. In this project, we have created three windows. The main window is “Window1.xaml”.

How to use the relevant APIs to implement following functions?

All implementation logics are same no matter which language you choose. Let’s illustrate with C#.

Read more

How to Use Dynamic Web TWAIN with Internet Explorer 11 on Windows 8.1

It’s been a while now since Microsoft released a Windows 8.1 Preview with a Preview of IE 11 too. No doubt many users have already tested it. It is apparent that Microsoft has entirely rebuilt the developer tools and made them much more beautiful and powerful. There are eight distinct tools: DOM Explorer, Console, Debugger, Network, UI Responsiveness, Profiler, Memory, and Emulation. In this article, I will share some of my experiences with the debugger and console tools of IE 11. And I’ll provide a review of a hands-on test on how Dynamic Web TWAIN works with IE 11.

Read more

How to Read Barcode in WPF with VB.NET

We’re proud to reveal that Dynamsoft’s Dynamic .NET TWAIN 5.0 is on its way to release soon. In addition to WinForms support, the new version will include a WPF control. You can use it in your WPF app to capture images from TWAIN scanners and UVC/WIA webcams, to edit and save images to local disks, to a server or a database. Today, I’d like to cover how, using VB.NET, you can use the Dynamic .NET TWAIN 5.0 SDK to implement barcode reading in a WPF application.

The relevant source code can be downloaded here.

Barcode Demo

1.        Create a New WPF Project

First, start Visual Studio .NET, and create a new WPF project. Select Visual Basic as the type and choose WPF Application as the template.

Create WPF Project

2.        Add a Reference

Right-click on the project root, and select Add Reference… from the menu. Click Browse to locate DynamicDotNetTWAIN.dll and add it.

WPF Reference

3.      Add Dynamic .NET TWAIN Component

If there is no Dynamic .NET TWAIN component available, you might need to open the toolbox. To do so, right-click on the panel and select Choose Items… Switch to the tab WPF Components and click Browse… to load DynamicDotNetTWAIN.Wpf.dll

 WPF Component

4.         Add Buttons and Textbox

Next, you’ll want to drag two buttons and one textbox from the toolbox to design a form. The buttons are used to load an image and make the detection of a barcode. And, the textbox is used to display the information decoded from barcode.

WPF Button

5.         Code for Loading Image

Now, what you need to do is to acquire an image using the Windows standard API. Then you’ll need to load it using the Dynamic .NET TWAIN component method. Just a couple of lines of code are needed for loading an image. It’s pretty simple.

       Dim filedlg As OpenFileDialog
        filedlg = New OpenFileDialog()
        filedlg.Multiselect = True
       Dim strFilename As String
        If (filedlg.ShowDialog() = DialogResult.OK) Then
            For Each strFilename In filedlg.FileNames
                DynamicDotNetTwain1.LoadImage(strFilename)
            Next
        End If

6.         Code for Barcode Recognition

To decode a barcode, the path for the barcode library needs to be first be specified. Then, with one additional line of code, you’ll get results.

Set the path of barcode library

        Dim strDllFolder As String
        strDllFolder = Application.ExecutablePath
        Dim pos As Integer
        pos = strDllFolder.LastIndexOf("\Samples\")
        If (pos <> -1) Then
            strDllFolder = strDllFolder.Substring(0, strDllFolder.IndexOf("\", pos)) + "\Bin\BarcodeResources\"
        End If
        Me.DynamicDotNetTwain1.BarcodeDllPath = strDllFolder

Get the results and display them on screen

        Me.TextBox1.Text = ""
        Dim aryResult() As Result
        aryResult = Me.DynamicDotNetTwain1.ReadBarcode(Me.DynamicDotNetTwain1.CurrentImageIndexInBuffer, BarcodeFormat.All)
        Dim strText As StringBuilder
        strText = New StringBuilder()
        If aryResult.Length = 1 Then
            strText.AppendFormat(aryResult.Length & " total barcode" & ("") & " found." & Constants.vbCrLf)
        Else
            strText.AppendFormat(aryResult.Length & " total barcode" & ("s") & " found." & Constants.vbCrLf)
        End If
        For i As Integer = 0 To aryResult.Length - 1
            Dim objResult As Result
            objResult = aryResult(i)
            strText.AppendFormat("      Result " & (i + 1) & Constants.vbCrLf)
            strText.AppendFormat("      BarcodeFormat: " & objResult.BarcodeFormat.ToString() & Constants.vbCrLf)
            strText.AppendFormat("      Text read: " & objResult.Text & Constants.vbCrLf)
        Next i
        Me.TextBox1.Text = strText.ToString()

I hope this brief tutorial is helpful to anyone who is looking for a .NET barcode reader SDK in VB.NET.

For further inquiries, please feel free to send me an email at kgao[at]dynamsoft.com.

Dynamic .NET TWAIN 5.0 is scheduled to be released late next month. To stay informed about all our product announcements, blog posts and more, be sure to follow us on Twitter, like us on Facebook or add us on Google+. Also, if you’d like to be amongst the first to try out the new version first, please contact support[at]dynamsoft.com.

Scan and Save Images to a Database in C# Using Dynamic .NET TWAIN

In today’s “big data era”, more and more organizations are using an enterprise content management (ECM) or record management system (RMS) to help maintain and manage the documents. Digitizing documents and storing them in a central database has become an important part of many organization’s document management workflow. For this purpose, we will illustrate creating an application to capture documents as images from scanners and webcams. We’ll also cover how to save them in SQL Server in C#.

We will be using Dynamic .NET TWAIN to expedite development and deployment of such an application. Dynamic .NET TWAIN is a document scanning SDK based on the .NET Framework 2.0/4.0. The SDK enables users to capture images from TWAIN scanners and UVC/WIA webcams. It also allows simple edits or processing. Finally, it enables saving of images to your local/server disk, FTP site or database from your WinForm application.

Using the Code

If you are interested in using a .NET imaging SDK to quickly implement image capturing in your application, you can download the 30-day free trial of Dynamic .NET TWAIN. After installation, in the installation directory, you will find “DynamicDotNetTWAIN.dll” under \Bin\v2.0 and \Bin\v4.0. You can choose the corresponding version to suit your specific .NET framework version.

Capture and upload image to database in .NET

 

Capture Images

With Dynamic .NET TWAIN, you can enable image capturing from TWAIN devices and USB/WIA webcams using just a few lines of code. Here’s a sample of this code:

Public frmCustomizeScan()
        {
            InitializeComponent();

            dynamicDotNetTwain.SupportedDeviceType = Dynamsoft.DotNet.TWAIN.Enums.EnumSupportedDeviceType.SDT_ALL; // enable capturing images from both scanners and webcams
            int lngNum;
            dynamicDotNetTwain.OpenSourceManager();
            for (lngNum = 0; lngNum < dynamicDotNetTwain.SourceCount; lngNum++)
            {     
               cmbSource.Items.Add(dynamicDotNetTwain.SourceNameItems(Convert.ToInt16(lngNum))); // display the available imaging devices
            }
            if (lngNum > 0)
                cmbSource.SelectedIndex = 0;          

        }

        private void cmdScan_Click(object sender, EventArgs e)
        {
            dynamicDotNetTwain.IfAppendImage = true;
		    AcquireImage(); // acquire images
        }

        private void AcquireImage()
        {
            dynamicDotNetTwain.SelectSourceByIndex(Convert.ToInt16(cmbSource.SelectedIndex));
            dynamicDotNetTwain.IfShowUI = chkIfShowUI.Checked;
            dynamicDotNetTwain.OpenSource();
            dynamicDotNetTwain.IfDisableSourceAfterAcquire = true;

            try { dynamicDotNetTwain.AcquireImage(); }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }

        }

Uploading

Dynamic .NET TWAIN provides HTTP Upload methods with which you can upload the scanned or captured images to a web server or database. This can be done in file formats including, PDF, TIF, JPG, PNG and BMP. Multi-page TIF and PDF are also supported.

When uploading the images, you can add extra parameters and store them with the image record in the database. Here’s sample code for that:

  private void BtnUpload_Click(object sender, EventArgs e)
        {
            string strActionPage = "Upload.aspx"; // for receiving the uploaded image data on the server side
            string strFileName = textBox1.Text;
            string strFileType = textBox2.Text;
            string strHTTPServer = "localhost"; // the name or the IP of your HTTP Server
            dynamicDotNetTwain.HTTPPort = 8066; //the port number of the HTTP Server
            dynamicDotNetTwain.HTTPUserName = "chloe"; //user name for logging into HTTP Server
            dynamicDotNetTwain.HTTPPassword = "c";
            dynamicDotNetTwain.SetHTTPFormField("FileType", strFileType); // pass extra text parameters when uploading image
            dynamicDotNetTwain.HTTPUploadAllThroughPostAsPDF(strHTTPServer,strActionPage, strFileName+".pdf"); // save the captured images as a multi-page PDF file
            if (dynamicDotNetTwain.ErrorCode !=ErrorCode.Succeed)
            {
                MessageBox.Show(dynamicDotNetTwain.HTTPPostResponseString);
            }
            else
            {
                MessageBox.Show("PDF saved successfully.");
            }
        }

Upload.aspx

The action page – Upload.aspx – referred to in the HTTPUploadAllThroughPostAsPDF method is for receiving the image data on the server side. So make sure to deploy the file in your web server. Here’s how to do that:

<%@ Page Language="c#" AutoEventWireup="false" Debug="True"%>

<%

 	try
	{
		int iFileLength;
		HttpFileCollection files = HttpContext.Current.Request.Files;
		HttpPostedFile uploadfile = files["RemoteFile"];
		String strImageName = uploadfile.FileName; 
		String strFileType = System.Web.HttpContext.Current.Request.Form["FileType"];

		iFileLength = uploadfile.ContentLength;
		Byte[] inputBuffer = new Byte[iFileLength];
		System.IO.Stream inputStream;
		inputStream = uploadfile.InputStream;
		inputStream.Read(inputBuffer,0,iFileLength);	    

	    String strConnString = "Data Source=192.168.8.211;Initial Catalog=WebTwain;User ID=sa;Pwd=sa";

		System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(strConnString);

		String SqlCmdText = "INSERT INTO tblImage (strImageName,imgImageData, strFileType) VALUES (@ImageName,@Image, @ImageType)";
		System.Data.SqlClient.SqlCommand sqlCmdObj = new System.Data.SqlClient.SqlCommand(SqlCmdText, sqlConnection);

		sqlCmdObj.Parameters.Add("@Image",System.Data.SqlDbType.Binary,iFileLength).Value = inputBuffer;
		sqlCmdObj.Parameters.Add("@ImageName",System.Data.SqlDbType.VarChar,255).Value = strImageName;
        sqlCmdObj.Parameters.Add("@ImageType", System.Data.SqlDbType.VarChar, 255).Value = strFileType;

		sqlConnection.Open();
		sqlCmdObj.ExecuteNonQuery();
		sqlConnection.Close();
	}
	catch(Exception e)
	{
       		Response.Write(e.Message);    
       		throw;         

	}

%>

Deploy & Run the Application

For your convenience, the complete source code can be downloaded from this article.

If you get a license error when running the sample code, you can download Dynamic .NET TWAIN from Dynamsoft’s website to get a valid trial license for free:  Dynamic .NET TWAIN 30-Day Free Trial Download

Make sure you deploy the web application, which includes Upload.aspx, in your web server (IIS, Apache, etc.) and update the values of strHTTPServerHTTPPortHTTPUserName and HTTPPassword in BtnUpload_Click()accordingly before running. You can find CreateTable.sql for the script to create the table for storing the PDF files.

 

Read more on CodeProject.

 

APIs for Image Capture Applications

When developing an online image capture application, which API shall we choose?

Catherine wrote an article which introduces three popular APIs for imaging apps – TWAIN, WIA and DirectShow. It will give you some ideas on TWAIN vs WIA vs Direcshow and will give you some clues on which API to go for your application.

Read more the artice posted on Drdobbs. 

If you want to take advantage of 3rd-party imaging SDKS to accelerate development and integration, you can check out Dynamsoft’s .NET & web Image Capture SDKs.

New Article on CodeProject: Reading Barcodes from an Image in a Web App

Because of its accuracy and its ease of use, Barcodes have become more and more popular as a part of daily document management workflow. You can use barcodes to identify documents, separate batch scanning, or even get reliable metadata as a document identifier.

This article will show you how to decode barcodes from an image captured or scanned in a web application with the help of ImageCapture Suite.

 

Dynamsoft’s Image Capture Suite is an online image acquisition and processing toolkit designed for web applications. It allows you to capture images from scanners, webcams and other TWAIN/UVC/WIA compatible devices from all mainstream browsers – Internet Explorer (32-bit/64-bit), Firefox, Chrome and Safari – on Windows and Mac. The toolkit also comes with a Barcode Reader SDK which allows you to decode both 1D and 2D barcode symbols online.

If you are interested in the SDK, the 30-day Free Trial can be downloaded from Dynamsoft website.

 

Read more: Reading Barcodes from an Image in a Web App

ImageCapture Suite Barcode Reader Online Demo

 

ImageCapture Suite 30-Day Free Trial Download

New Article on CodeProject: Develop a Cross-Platform Document Imaging Web App

Document management is a big challenge nowadays, especially for paper-heavy industries like healthcare, financial, government etc. You may want to develop a document imaging application which allows users, either using Windows or Mac OS, to easily scan documents or capture images via browsers, so that you can manage the documents/records more efficiently.

Dynamsoft’s ImageCapture Suite is a browser-based document imaging library. It allows you to capture images from scanners, webcams and other TWAIN/UVC/WIA compatible devices on Windows or Mac. If you are interested in the SDK, the 30-day Free Trial can be downloaded from Dynamsoft website.

Key Features

  • Capture images/documents from scanners, webcams and other TWAIN/WIA/UVC compatible imaging devices.
  • Compatible with the mainstream browsers including IE (both 32-bit & 64-bit), Firefox, Chrome, Safari and Opera on Windows and Mac.
  • Edit images: Crop, Change Image Size, Rotate, Zoom, Erase and more.
  • Upload images to various locations – local folder, FTP site, web server, database, SharePoint library and more.
  • Enhanced security: supports SSL and Windows/Forms/Basic Authentication.
  • Supported image formats include BMP, JPEG, PNG, TIFF (both single and multi-page) and PDF (both single and multi-page).

 

Read more: Develop a Cross-Platform Document Imaging Web App

ImageCapture Suite Online Demo

New Article on CodeProject: How to make ActiveX work with IE Protected Mode?

Since Internet Explorer 7 on Windows Vista was released, Protected Mode has been introduced as a new security feature. When running in Protected Mode, Internet Explorer is a low integrity process and has limited permissions to access the user system.

When running Dynamic Web TWAIN, the scanner browser plugin for web application,  on Windows Vista and above, IE Protected Mode is on by default so users consistently get issues like the following:

  • ActiveX failed to access the scanners connected to the user machine
  • IE crashed when ActiveX tries to acquire images from scanner due to insufficient permission

 

With Dynamic Web TWAIN v9.0, you can now use an independent broker process to communicate with the scanners for better compatibility and robustness.

  • Avoid browser crashes caused by scanner driver problems, thus improving the robustness of the web application. The independent process will not affect the browser process.
  • The independent process used for scanning has a higher permission level than the browser process. This can solve the scanning issues, such as browsers not accessing the scanner source successfully, caused by the increased security features of Windows/IE.

 

Read more: How to work with IE Protected Mode?

Try out Online Demo of Dynamic Web TWAIN

Download 30-day free trial of Dynamic Web TWAIN 9.0

Dynamic Web TWAIN 9.0 Released!

I am pleased to announce that version 9.0 is now available!

Three dramatic improvements are included in this new version:

  • Do document scanning in an independent process, which greatly improves the robustness of the application.
  • New license verification process. In v9.0, license key can be encrypted in licensing tool and directly embedded in scan page. So the installation & deployment process will be much easier for developers and end users.
  • Support multi-thread HTTP Upload/Download, which dramatically improves upload/download performance and user experience.

For full release notes, please refer to here.

Other resources:

If you are ready to purchase a license, please visit our online store or send your order tosales@dynamsoft.com.

I’d love to hear any comments or suggestions about this new version. Please don’t hesitate to contact me.

Using Barcode as Batch Separator in Web Application

For document management, it is a common requirement that a user puts a stack of documents for automatic document feeder (ADF) scanning. The documents may be for different purposes and he wants to save them into different files automatically after the scanning finishes. This way, it will greatly save the time.

So how can we achieve that? How to enable users to do that on your website or with your web application?

Read more