Customization of Signature Control

6 Apr 20226 minutes to read

The Signature control draws stroke/path using moveTo() and lineTo() methods to connect one or more points while drawing in canvas. The stroke width can be modified by using its color and width. And the background can be modified by using its background color and background image.

Stroke Width

The variable stroke width is based on the values of MaxStrokeWidth, MinStrokeWidth and Velocity for smoother and realistic signature. The default value of minimum stroke width is set as 0.5, maximum stroke width is set as 2.5 and velocity is set as 0.7.

In the following example, minimum stroke width is set as 0.5, maximum stroke width is set as 3 and velocity is set as 0.7.

<div class='wrap'>
    @Html.EJS().Signature("signature").MaxStrokeWidth(3).MinStrokeWidth(0.5).Velocity(0.7).Render()
</div>

<style>
    .wrap {
        margin: 0 auto;
        width: 300px;
        text-align: center;
    }

    #signature {
        border: 1px solid lightgray;
        height: 100%;
        width: 100%;
    }
</style>
public ActionResult Default()
{
    return View();
}

Output be like the below.

Signature Sample

Stroke Color

Color of the stroke can be specified by using StrokeColor property and it accepts hexadecimal code, RGB, and text. The default value of this property is “#000000”.

<div class='wrap'>
    <div id="input">
        <input type="text" id="text" placeholder="Enter the Stroke Color Value">
        @Html.EJS().Button("btn").Content("Set Stroke Color").IsPrimary(true).Render()
    </div>
    <div id="signature-control">
        @Html.EJS().Signature("signature").Render()
    </div>
</div>

<script>
    document.getElementById("btn").addEventListener('click', function () {
        var signature = document.getElementById("signature").ej2_instances[0];
        var color = document.getElementById("text").value;
        signature.strokeColor = color;
    });
</script>

<style>
    .wrap {
        margin: 0 auto;
        width: 500px;
    }

    #signature {
        border: 1px solid lightgray;
        height: 100%;
        width: 100%;
    }

    #input {
        margin-bottom: 30px;
    }

    #text {
        height: 30px;
        width: 300px;
    }
</style>
public ActionResult Default()
{
    return View();
}

Output be like the below.

Signature Sample

Background Color

Background color of a signature can be specified by using BackgroundColor property and it accepts hexadecimal code, RGB, and text. The default value of this property is “#ffffff”.

<div class='wrap'>
    <div id="input">
        <input type="text" id="text" placeholder="Enter the Background Color Value">
        @Html.EJS().Button("btn").Content("Set Background Color").IsPrimary(true).Render()
    </div>
    <div id="signature-control">
        @Html.EJS().Signature("signature").Render()
    </div>
</div>

<script>
    document.getElementById("btn").addEventListener('click', function () {
        var signature = document.getElementById("signature").ej2_instances[0];
        var bgColor = document.getElementById("text").value;
        signature.backgroundColor = bgColor;
    });
</script>

<style>
    .wrap {
        margin: 0 auto;
        width: 500px;
    }

    #signature {
        border: 1px solid lightgray;
        height: 100%;
        width: 100%;
    }

    #input {
        margin-bottom: 30px;
    }

    #text {
        height: 30px;
        width: 300px;
    }
</style>
public ActionResult Default()
{
    return View();
}

Output be like the below.

Signature Sample

Background Image

Background image of a signature can be specified by using BackgroundImage property. The background image can be set by either hosting the image in our local IIS or online image.

<div class='wrap'>
    <div id="input">
        <input type="text" id="text" placeholder="Enter the URL of the background Image">
        @Html.EJS().Button("btn").Content("Set Background Image").IsPrimary(true).Render()
    </div>
    <div id="signature-control">
        @Html.EJS().Signature("signature").Render()
    </div>
</div>

<script>
    document.getElementById("btn").addEventListener('click', function () {
        var signature = document.getElementById("signature").ej2_instances[0];
        var bgImage = document.getElementById("text").value;
        signature.backgroundImage = bgImage;
    });
</script>

<style>
    .wrap {
        margin: 0 auto;
        width: 500px;
        text-align: center;
    }

    #signature {
        border: 1px solid lightgray;
        height: 100%;
        width: 100%;
    }

    #input {
        margin-bottom: 30px;
    }

    #text {
        height: 30px;
        width: 350px;
    }
</style>
public ActionResult Default()
{
    return View();
}

Output be like the below.

Signature Sample

See Also