A Razor Class Library built using the Dynamsoft Document Normalizer SDK, which provides APIs for document edge detection and document rectification.
razor-document-library-blazor-document-scan.mp4
https://yushulx.me/Razor-Document-Library/
-
Import and initialize the Razor Document Library.
@using RazorDocumentLibrary @code { private DocumentJsInterop? documentJsInterop; protected override async Task OnInitializedAsync() { documentJsInterop = new DocumentJsInterop(JSRuntime); await documentJsInterop.LoadJS(); } }
-
Set the license key and load the wasm module.
await documentJsInterop.SetLicense(licenseKey); await documentJsInterop.LoadWasm();
-
Createa a document normalizer instance.
DocumentNormalizer normalizer = await documentJsInterop.CreateDocumentNormalizer();
-
Detect document edges.
Quadrilateral? result = await normalizer.DetectCanvas(canvas);
-
Rectify the document based on the detected edges.
IJSObjectReference rectifiedDocument = await normalizer.RectifyCanvas(canvas, result.location);
Represents the coordinates of the four corners of a quadrilateral.
Task<Quadrilateral?> DetectCanvas(IJSObjectReference canvas)
: Detects document edges from a canvas.Task<IJSObjectReference> RectifyCanvas(IJSObjectReference canvas, string location)
: Rectifies a document based on the detected edges.Task SetFilter(string filter)
: Sets the filter for document edge detection.Task ShowDocumentEditor(string elementId, IJSObjectReference imageCanvas, string location)
: Shows the document edge editor.RegisterCallback(ICallback callback)
: Registers a callback function for receiving the coordinates of the four corners of a document.Task ShowRectifiedDocument(string elementId, IJSObjectReference rectifiedDocument)
: Displays the rectified document within a specified HTML element.
Task LoadJS()
: Loads the Dynamsoft Document Normalizer JavaScript library.Task SetLicense(string license)
: Sets the license key.Task LoadWasm()
: Loads the Dynamsoft Document Normalizer WebAssembly module.Task<MrzRecognizer> CreateDocumentNormalizer()
: Creates a Document Normalizer instance.
cd RazorDocumentLibrary
dotnet build --configuration Release