Skip to content

Commit 722d326

Browse files
author
mugunthan-anbalagan
committed
sample(EJ2-69305): Added sample to insert signature in text form field
1 parent a8214d4 commit 722d326

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+78545
-0
lines changed

Blazor/Server/DocumentEditor.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocumentEditor", "DocumentEditor\DocumentEditor.csproj", "{EB1810A4-4E9D-4782-8A23-F64D40C675F1}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
Release-Xml|Any CPU = Release-Xml|Any CPU
13+
EndGlobalSection
14+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
15+
{EB1810A4-4E9D-4782-8A23-F64D40C675F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{EB1810A4-4E9D-4782-8A23-F64D40C675F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{EB1810A4-4E9D-4782-8A23-F64D40C675F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{EB1810A4-4E9D-4782-8A23-F64D40C675F1}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{EB1810A4-4E9D-4782-8A23-F64D40C675F1}.Release-Xml|Any CPU.ActiveCfg = Release|Any CPU
20+
{EB1810A4-4E9D-4782-8A23-F64D40C675F1}.Release-Xml|Any CPU.Build.0 = Release|Any CPU
21+
EndGlobalSection
22+
GlobalSection(SolutionProperties) = preSolution
23+
HideSolutionNode = FALSE
24+
EndGlobalSection
25+
GlobalSection(ExtensibilityGlobals) = postSolution
26+
SolutionGuid = {0C89EEC6-DABA-4267-AEF6-DB0EC80BFF77}
27+
EndGlobalSection
28+
EndGlobal
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace DocumentEditor.Data;
2+
3+
public class WeatherForecast
4+
{
5+
public DateOnly Date { get; set; }
6+
7+
public int TemperatureC { get; set; }
8+
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
10+
11+
public string? Summary { get; set; }
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace DocumentEditor.Data;
2+
3+
public class WeatherForecastService
4+
{
5+
private static readonly string[] Summaries = new[]
6+
{
7+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
8+
};
9+
10+
public Task<WeatherForecast[]> GetForecastAsync(DateOnly startDate)
11+
{
12+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
13+
{
14+
Date = startDate.AddDays(index),
15+
TemperatureC = Random.Shared.Next(-20, 55),
16+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
17+
}).ToArray());
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.Blazor.Core" Version="20.4.0.52" />
11+
<PackageReference Include="Syncfusion.Blazor.Themes" Version="20.4.0.52" />
12+
<PackageReference Include="Syncfusion.Blazor.WordProcessor" Version="20.4.0.52" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@page
2+
@model DocumentEditor.Pages.ErrorModel
3+
4+
<!DOCTYPE html>
5+
<html lang="en">
6+
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
10+
<title>Error</title>
11+
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
12+
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
13+
</head>
14+
15+
<body>
16+
<div class="main">
17+
<div class="content px-4">
18+
<h1 class="text-danger">Error.</h1>
19+
<h2 class="text-danger">An error occurred while processing your request.</h2>
20+
21+
@if (Model.ShowRequestId)
22+
{
23+
<p>
24+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
25+
</p>
26+
}
27+
28+
<h3>Development Mode</h3>
29+
<p>
30+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
31+
</p>
32+
<p>
33+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
34+
It can result in displaying sensitive information from exceptions to end users.
35+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
36+
and restarting the app.
37+
</p>
38+
</div>
39+
</div>
40+
</body>
41+
42+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
5+
namespace DocumentEditor.Pages;
6+
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
@page "/"
2+
3+
@using Syncfusion.Blazor.Buttons;
4+
@using Syncfusion.Blazor.DocumentEditor;
5+
@using System.Text.Json
6+
@using Syncfusion.Blazor.Inputs
7+
@using Syncfusion.Blazor.Popups
8+
9+
<div class="control-section">
10+
<div>
11+
<div>
12+
<SfDocumentEditorContainer UseDefaultEditor="false" Width="1000px" Height="590px">
13+
<SfDocumentEditor @ref="documentEditor">
14+
<DocumentEditorEvents Created="LoadDocument" BeforeFormFieldFill="BeforeFormFill"></DocumentEditorEvents>
15+
</SfDocumentEditor>
16+
</SfDocumentEditorContainer>
17+
</div>
18+
</div>
19+
</div>
20+
21+
<SfDialog AllowPrerender="true" IsModal="true" @bind-Visible="showSignatureDialog" AllowDragging=true CloseOnEscape="true" Height="300px" Width="600px">
22+
<DialogTemplates>
23+
<Header>
24+
Signature
25+
</Header>
26+
<Content>
27+
@if(isOpen) {
28+
<SfSignature @ref="signature" IsReadOnly="false" style="height:100%; width: 100%;"></SfSignature>
29+
}
30+
</Content>
31+
</DialogTemplates>
32+
<DialogButtons>
33+
<DialogButton CssClass="e-flat" Content="OK" IsPrimary="true" OnClick="@InsertSignature"></DialogButton>
34+
<DialogButton CssClass="e-flat" Content="Cancel" IsPrimary="true" OnClick="@CloseDialog"></DialogButton>
35+
</DialogButtons>
36+
<DialogEvents Opened="@OnOpenHandler" Closed="@DialogClosed"></DialogEvents>
37+
</SfDialog>
38+
39+
@code {
40+
SfDocumentEditor? documentEditor;
41+
42+
SfSignature? signature;
43+
44+
bool isOpen = false;
45+
46+
bool showSignatureDialog = false;
47+
48+
public async void InsertSignature()
49+
{
50+
await documentEditor.Selection.SelectFieldAsync();
51+
string image = await signature.GetSignatureAsync(SignatureFileType.Png);
52+
await documentEditor.Editor.InsertImageAsync(image, 150, 30);
53+
showSignatureDialog = false;
54+
StateHasChanged();
55+
}
56+
57+
58+
public void BeforeFormFill(FormFieldFillEventArgs args)
59+
{
60+
// Check whether form field name match the signature field.
61+
if (args.FieldName == "signature")
62+
{
63+
//Cancel form field fill.
64+
args.IsCanceled = true;
65+
showSignatureDialog = true;
66+
StateHasChanged();
67+
}
68+
}
69+
70+
private void OnOpenHandler(Syncfusion.Blazor.Popups.OpenEventArgs args)
71+
{
72+
isOpen = true;
73+
}
74+
75+
private void DialogClosed(CloseEventArgs args)
76+
{
77+
isOpen = false;
78+
}
79+
80+
private void CloseDialog()
81+
{
82+
showSignatureDialog = false;
83+
StateHasChanged();
84+
}
85+
86+
private async void LoadDocument()
87+
{
88+
string filePath = "wwwroot/data/Form Fields.docx";
89+
using (FileStream fileStream = new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
90+
{
91+
WordDocument document = WordDocument.Load(fileStream, ImportFormatType.Docx);
92+
string json = JsonSerializer.Serialize(document);
93+
document.Dispose();
94+
await documentEditor.OpenAsync(json);
95+
}
96+
}
97+
}
98+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@page "/"
2+
@using Microsoft.AspNetCore.Components.Web
3+
@namespace DocumentEditor.Pages
4+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
5+
6+
<!DOCTYPE html>
7+
<html lang="en">
8+
<head>
9+
<meta charset="utf-8" />
10+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
11+
<base href="~/" />
12+
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
13+
<link href="css/site.css" rel="stylesheet" />
14+
<link href="DocumentEditor.styles.css" rel="stylesheet" />
15+
<link rel="icon" type="image/png" href="favicon.png"/>
16+
<link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
17+
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
18+
<script src="_content/Syncfusion.Blazor.WordProcessor/scripts/syncfusion-blazor-documenteditor.min.js" type="text/javascript"></script>
19+
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
20+
</head>
21+
<body>
22+
<component type="typeof(App)" render-mode="ServerPrerendered" />
23+
24+
<div id="blazor-error-ui">
25+
<environment include="Staging,Production">
26+
An error has occurred. This application may no longer respond until reloaded.
27+
</environment>
28+
<environment include="Development">
29+
An unhandled exception has occurred. See browser dev tools for details.
30+
</environment>
31+
<a href="" class="reload">Reload</a>
32+
<a class="dismiss">🗙</a>
33+
</div>
34+
35+
<script src="_framework/blazor.server.js"></script>
36+
<script>
37+
window.saveSteam = function (steam) {
38+
console.log(steam);
39+
}
40+
</script>
41+
</body>
42+
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Microsoft.AspNetCore.Components;
2+
using Microsoft.AspNetCore.Components.Web;
3+
using DocumentEditor.Data;
4+
using Syncfusion.Blazor;
5+
6+
var builder = WebApplication.CreateBuilder(args);
7+
8+
// Add services to the container.
9+
builder.Services.AddRazorPages();
10+
builder.Services.AddServerSideBlazor();
11+
builder.Services.AddSyncfusionBlazor();
12+
13+
builder.Services.AddServerSideBlazor().AddCircuitOptions(options => { options.DetailedErrors = true; });
14+
15+
builder.Services.AddServerSideBlazor().AddHubOptions(o => { o.MaximumReceiveMessageSize = 102400000; });
16+
17+
builder.Services.AddSingleton<WeatherForecastService>();
18+
19+
var app = builder.Build();
20+
21+
// Configure the HTTP request pipeline.
22+
if (!app.Environment.IsDevelopment())
23+
{
24+
app.UseExceptionHandler("/Error");
25+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
26+
app.UseHsts();
27+
}
28+
29+
app.UseHttpsRedirection();
30+
31+
app.UseStaticFiles();
32+
33+
app.UseRouting();
34+
35+
app.MapBlazorHub();
36+
app.MapFallbackToPage("/_Host");
37+
38+
app.Run();

0 commit comments

Comments
 (0)