Signature
A production signature field: capture, clear, undo, validate and export. The signature is stored as vector ink, so it can be re-rendered at any size, embedded in a PDF as SVG, or rasterized at print resolution.
Validation and the accepted state
A scribble of one dot is not a signature. The page measures the ink - its length, the number of strokes and
how long the pen was down - and enables Accept signature only past a minimum length: a real
validation rule that the vector model makes easy to express. Accepting makes the field
ReadOnly, the way ink on paper is final, until the signer chooses to sign again.
BinkInkMetrics ink = BinkDocumentQuery.MeasureInk(_canvas.CurrentDocument); bool valid = ink.Length > 120f; // also ink.StrokeCount, ink.Duration, ink.Bounds
The message beside the buttons comes from StrokeCompleted, which hands over each finished stroke:
its Input.HasRealPressure says whether a pen measured the pressure or the width was derived from
drawing speed. While the field is read only, drawing, undo, redo and the editing shortcuts are refused (zooming
still works), and its accessible name changes from "Sign here" to "Accepted signature".
A field inside a form
Whether a finger on a touch screen signs or scrolls the page is the one decision a signature field has to make,
because no setting gets both. This field sets EnableTouchGestures, so a finger signs on a phone.
In a long form that has to keep scrolling past the field, leave it off, as it is by default: the canvas then
sets touch-action: pan-x pan-y, a finger scrolls, and a stylus still signs because a pen is not a
touch pointer. The wheel is left to the page either way (WheelMode is None by
default), so a mouse wheel over the field still scrolls the form.
@* EnableTouchGestures="false": a finger scrolls the form, and a pen still signs. *@ <BinkCanvas Height="200px" AriaLabel="Sign here" EnableTouchGestures="true" ReadOnly="_accepted" StrokeCompleted="OnStrokeCompleted" DocumentChanged="() => StateHasChanged()" />
The clipboard and dropping files stay off, as they are by default, so nobody can paste or drop a picture of a signature into the field. The signing line and its caption are printed over the canvas by the page, not drawn into the document, so they never appear in what is saved or exported.
Export cropped to the ink
BinkExportRegion.Content crops an export to what was drawn, and a transparent background lets the
signature sit on whatever document it is placed into. The stored copy above is exported the same way, with
BinkSvgExporter on the document rather than through the canvas.
await _canvas.SavePngAsync("signature.png", new BinkPngExportOptions { Region = BinkExportRegion.Content, Padding = 12f, Scale = 3f, Background = BinkColor.Transparent, });