Today I am going to introduce you to using signature pad with AngularJS and WCF service. In this article I am going to show you how to bind signature pad using WCF services.
I used the following in this article:
- Canvas signature pad.
- AngularJS
- How to store your canvas signature in database and display on screen.
Step 1: SQL Script for signature pad,
- CREATE TABLE[dbo].[mstSign]
- (
- [SignId][UNIQUEIDENTIFIER] NOT NULL, [cName][VARCHAR](150) NULL, [cSigndata][VARCHAR](MAX) NULL, [dtDateTime][DATETIME] NULL
- )
Step 2: Wcf Service
- I used my hosted service here.
- So, you can get the latest service from my previous article Call WCF Service Using jQuery.
- I updated my service code there, and also you can see WCF configuration using Windows activation service from web.config.
Step 3: Html5 Canvas code
- I used signature_pad.js for displaying signature pattern on screen.
- This JavaScript file is attached in source code.
- <div class="form-group">
- <label for="name">Enter Your Signature</label>
- <canvas id='signatureCanvas' width='300' height='150' style='border: 1px solid black;'></canvas>
- </div>
JavaScript code for displaying signature
- var canvas = document.getElementById('signatureCanvas');
- var signaturePad = new SignaturePad(canvas);
- var canvas = document.getElementById('signatureCanvas');
- var signaturePad = new SignaturePad(canvas);
Step 4: Save Canvas using service
My Controller:
- // for signature image
- var sigImg = signaturePad.toDataURL().replace('data:image/png;base64,', '');
- var name = $scope.sign.name;
- var xml = JSON.stringify
- ({
- 'name': name,
- 'imageData': sigImg
- });
- // call add service for save signature
- signService.Add(name, sigImg).success(function(response) {});
My Service:
- Add: function(name, imagedata)
- {
- return $http
- ({
- method: 'POST',
- headers:
- {
- 'Content-Type': 'application/json; charset=utf-8'
- },
- url: 'http://kunalpatel.tk/ProductService.svc/AddNewSignature',
- data:
- {
- name: name,
- imageData: imagedata
- }
- });
- }
Step 5: Load signature on screen
My Html:
- <tr ng-repeat="sign in Signatures">
- <td><b>{{ sign.cName }}</b></td>
- <td class="zoom_img"><img src="http://www.kunalpatel.tk/Images /Signature/{{ sign.cSigndata }}" height="50" width="100" /> </td>
- </tr>
- // for signature image
- var sigImg = signaturePad.toDataURL().replace('data:image/png;base64,', '');
- var name = $scope.sign.name;
- var xml = JSON.stringify
- ({
- 'name': name,
- 'imageData': sigImg
- });
- // call add service for save signature
- signService.Add(name, sigImg).success(function(response) {});
- Add: function(name, imagedata)
- {
- return $http
- ({
- method: 'POST',
- headers:
- {
- 'Content-Type': 'application/json; charset=utf-8'
- },
- url: 'http://kunalpatel.tk/ProductService.svc/AddNewSignature',
- data:
- {
- name: name,
- imageData: imagedata
- }
- });
- }
- <tr ng-repeat="sign in Signatures">
- <td><b>{{ sign.cName }}</b></td>
- <td class="zoom_img"><img src="http://www.kunalpatel.tk/Images /Signature/{{ sign.cSigndata }}" height="50" width="100" /> </td>
- </tr>
My Controller
- signService.get().success(function(response)
- {
- $scope.Signatures = JSON.parse(response.d);
- });
My Service
- get: function()
- {
- return $http
- ({
- method: 'POST',
- headers:
- {
- 'Content-Type': 'application/json; charset=utf-8'
- },
- url: 'http://kunalpatel.tk/ProductService.svc/LoadAllSignature',
- data: {}
- });
- }
Step 5 : Final Output
- signService.get().success(function(response)
- {
- $scope.Signatures = JSON.parse(response.d);
- });
- get: function()
- {
- return $http
- ({
- method: 'POST',
- headers:
- {
- 'Content-Type': 'application/json; charset=utf-8'
- },
- url: 'http://kunalpatel.tk/ProductService.svc/LoadAllSignature',
- data: {}
- });
- }
Read more articles on AngularJS:


Iqbal LatiffiPosted Oct 23, 2016, 11:09 PM
Hi, thanks for sharing. May I ask, why I can't save the signature and name into my DB? May u teach me steps-by-steps to do it? I use MS SQL Server. I really appreciate it.
Nitesh KejriwalPosted Mar 22, 2016, 8:21 AM
Nice share!
Santhakumar MunuswamyPosted Feb 16, 2016, 3:06 PM
Thanks for nice work
Kunal PatelPosted Feb 15, 2016, 6:26 AM
Thank to all.
Jaipal ReddyPosted Feb 15, 2016, 1:45 AM
Nice Share. .
Shubham KumarPosted Feb 15, 2016, 12:58 AM
nice share
Sibeesh VenuPosted Feb 15, 2016, 12:35 AM
Nice Share
Debasis SahaPosted Feb 15, 2016, 12:02 AM
Nice One...
Rupali ShindePosted Feb 14, 2016, 11:47 PM
hi, thanks for such new idea. i am facing issue with solution - when i added signature and clicked on save button. in below grid i am not able to see any records. when i inspect page IE it is showing error Access Denied.
Shridhar SharmaPosted Feb 14, 2016, 11:24 PM
nice share
Mohammed IbrahimPosted Feb 14, 2016, 11:22 PM
nice
Gowtham KPosted Feb 14, 2016, 12:02 PM
Good One, Thanks for sharing
Pramod ThakurPosted Feb 14, 2016, 11:00 AM
nice.. thanks for sharing..
Debendra DashPosted Feb 13, 2016, 10:20 PM
Good one........
Kumaresh RajalingamPosted Feb 13, 2016, 8:30 PM
Nice