Awesome
SignaturePad
A simple to use blazor component to draw a signature. It supports both mouse and touch inputs and works on Blazor Server and Blazor WebAssembly.
See a live demo right here on github.
Installation
You can install from Nuget using the following command:
Install-Package Blazor.SignaturePad
Or via the Visual Studio package manger.
Basic usage
Start by adding the following using statement to your root _Imports.razor
.
@using SignaturePad
Next you should define a property in your class. For example:
public class MyInput
{
public byte[] Signature { get; set; } = Array.Empty<byte>();
}
You can then use it wherever you want.
<SignaturePad @bind-Value="Input.Signature" style="width: 100%" />
The control provides you the image data as base64 byte[]
To get the image, you'll need to convert to byte[]
into a string. For example:
public class MyInput
{
public byte[] Signature { get; set; } = Array.Empty<byte>();
public string SignatureAsBase64 => System.Text.Encoding.UTF8.GetString(Signature);
}
Providing options
You can configure the SignaturePad by providing a SignaturePadOptions
instance to the component.
<SignaturePad @bind-Value="Input.Signature" Options="_options" style="width: 100%" />
@code {
public MyInput Input { get; set; } = new();
private SignaturePadOptions _options = new SignaturePadOptions
{
LineCap = LineCap.Round,
LineJoin = LineJoin.Round,
LineWidth = 20
};
}
Using existing base64 strings
By default the SignaturePad prefixes the signature with data:image/png;base64,
. When Loading existing base64 strings, this prefix should be applied like this:
Input.Signature = Encoding.UTF8.GetBytes("data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAALgAAAA5CAYAAACF3+G6AAAAAXNSR0IArs4c6QAADlZJREFUeF7t3QOULFkSBuB/1rZt27Zt88zatm3be9actW3bmLVtz25+b+7dyZed1ZXVXV1d3ZVxTp3u1y95b9y4EX/8EbVPRpnHCBwuyY2T+Pm3JP8sn88m+eqEG5wiyVmSnC7JX5NcJslxkhwqyeGTHKVc7x9J9kvyqSRfT/KOeTzwqlxjn1V50Rnf8xBJLlAU7YxJTp3k4ElOleT0SQ5b/j3jZfccXpX/CBs5uZzzsyTvTPKlJN9sFscnkvx2E9fbtaeuqoKfO8kxk5w1yX+SXDDJ2ZIcq8w0q3noGWb9L0k+k+S/nXMsjON2/kbBWekvJvllscz/Luf/uaXAf2wtrP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yDkHRCXifVMrgGj3UnlYpQWr75WN1WLDPZUDd79huf23Au0KTQLzZVTHK3CaZRNjsA8FNwjYPE9sHCJ53XNIa/GBerezxfMon1aLFXZplFA2/cCpakiomBS15XzIjC2M6GLYlyyvu3i2r5n6b6DMj4cauV2dj3Y/ui6DZnpDR4zb2V8UCk0wM3ezULxawKllmlVi2sB2MHsXPV3C0ajoJVJsCzL5P8Pkg7Vm1kdRBkAAAAASUVORK5CYII=");
Custom styling
You can customize the looks of SignaturePad by either overriding the CSS classes or by specifiying your own classes.
For the SignaturePad itself you can use the Class
parameter and for the button to clear the SignaturePad you can use the ClearButtonClass
parameter.