##How To?

Save signature image with user defined format

By default the downloaded image from the signature canvas will be of png format. We can define our own format to download the image with saveImageFormat property. And we can also save the image along with the background by using the saveWithBackground property.

The following code example is used to download drawn image on the Signature component.

  • HTML
  • <ej-signature id="mySignature" [backgroundImage]="image" [saveWithBackground]="true" [saveImageFormat]="format" > </ej-signature>
    
    <input id="btnOpen" style="height: 30px" type="button" class="ejinputtext" value="Save" (click)="onClick($event)"/>

    Add the following script to define the download format for the canvas.

  • JS
  • export class SignatureComponent {
        image: any;
        format: any;
        constructor() {
         this.image = "image.png";
         this.format="jpeg";
        }
    onClick(event) {
        let obj = $('#mySignature').ejSignature('instance');
        obj.save("mySignature");
      }
     }

    The following screenshot illustrates the Signature with saving (downloading) the drawn image.

    Save Signature Image with user defined format

    To clear the Signature

    To clear the signature, you can simply use the clear() method. This method will clear all the drawn strokes in the signature canvas and leaves it empty.

  • HTML
  • <ej-signature id="mySignature" [height]="height" > </ej-signature>
    
    <input id="btnOpen" style="height: 30px" type="button" class="ejinputtext" value="Save" (click)="onClick($event)"/>

    Add the following script to clear the Signature.

  • JS
  • export class SignatureComponent {
    
        constructor() {
          this.height = 300;
        }
    onClick(event) {
        let obj = $('#mySignature').ejSignature('instance');
        obj.clear();
      }
     }

    Make signature as responsive

    When the signature component is resized or even the window is resized the strokes drawn in the signature will be disappeared. To make the strokes visible even after resizing the window, we must set theĀ isResponsive property as true.

    The following code example is used to render the Signature component with responsive support.

  • HTML
  • <ej-signature id="mySignature" [isResponsive ]="true" > </ej-signature>

    The following screenshot illustrates the Signature with responsiveness.

    Before Responsiveness:

    Make Signature before responsive

    After giving the Responsiveness:

    Make Signature after responsive

    To check whether any input to the signature control since render

    We can detect whether not there has been any input to the signature control since it has rendered. To detect we can use the storeSnap public variable, which is an array that stores all the canvas inputs. At initial rendering this array is empty and we can use this variable to check for the drawn strokes.

  • JS
  • export class SignatureComponent {
    
          let obj  = $("#signature").ejSignature("instance");
    
                if (ej.isNullOrUndefined(sign.storeSnap)) {
                   
                    //Something
    
                }
    
    }