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, 7:09 PM EDT
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, 4:21 AM EDT
Nice share!
Santhakumar MunuswamyPosted Feb 16, 2016, 10:06 AM EST
Thanks for nice work
Kunal PatelPosted Feb 15, 2016, 1:26 AM EST
Thank to all.
Jaipal ReddyPosted Feb 14, 2016, 8:45 PM EST
Nice Share. .
Shubham KumarPosted Feb 14, 2016, 7:58 PM EST
nice share
Sibeesh VenuTOP 100Posted Feb 14, 2016, 7:35 PM EST
Nice Share
Debasis SahaTOP 100Posted Feb 14, 2016, 7:02 PM EST
Nice One...
Rupali ShindePosted Feb 14, 2016, 6:47 PM EST
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, 6:24 PM EST
nice share
Mohammed IbrahimPosted Feb 14, 2016, 6:22 PM EST
nice
Gowtham KTOP 100Posted Feb 14, 2016, 7:02 AM EST
Good One, Thanks for sharing
Pramod ThakurPosted Feb 14, 2016, 6:00 AM EST
nice.. thanks for sharing..
Debendra DashPosted Feb 13, 2016, 5:20 PM EST
Good one........
Kumaresh RajalingamPosted Feb 13, 2016, 3:30 PM EST
Nice