Skip to content

Commit 773a4f1

Browse files
authored
Merge pull request #53 from SyncfusionExamples/EJ2-942250-loadDiffDoc
942250: Sample on How to Load Documents with links and Validate Form Fields
2 parents cf248de + 1a7d981 commit 773a4f1

File tree

90 files changed

+80427
-0
lines changed

Some content is hidden

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

90 files changed

+80427
-0
lines changed
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.8.34309.116
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreSample", "CoreSample\CoreSample.csproj", "{74B177C7-8BEA-4FC2-8067-208F7A494DA3}"
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+
{74B177C7-8BEA-4FC2-8067-208F7A494DA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{74B177C7-8BEA-4FC2-8067-208F7A494DA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{74B177C7-8BEA-4FC2-8067-208F7A494DA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{74B177C7-8BEA-4FC2-8067-208F7A494DA3}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{74B177C7-8BEA-4FC2-8067-208F7A494DA3}.Release-Xml|Any CPU.ActiveCfg = Release|Any CPU
20+
{74B177C7-8BEA-4FC2-8067-208F7A494DA3}.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 = {0548ECA4-3BAC-44DB-90D2-F6C447AD24CC}
27+
EndGlobalSection
28+
EndGlobal
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.8" />
11+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="*" />
12+
<PackageReference Include="Syncfusion.EJ2.PdfViewer.AspNet.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="PDF_Succinctly.pdf">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
5+
<NameOfLastUsedPublishProfile>D:\EJ2 Materials\ASP.NET.Core\8.0\CoreSample8.01999985370\CoreSample\CoreSample\Properties\PublishProfiles\CoreSample20240719165733 - Web Deploy.pubxml</NameOfLastUsedPublishProfile>
6+
</PropertyGroup>
7+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
8+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
9+
</PropertyGroup>
10+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
<fallbackPackageFolders>
8+
<clear />
9+
</fallbackPackageFolders>
10+
<disabledPackageSources>
11+
<clear />
12+
</disabledPackageSources>
13+
</configuration>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using System.Diagnostics;
4+
5+
namespace CoreSample.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+
}
27+
28+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
@page "{handler?}"
2+
@model IndexModel
3+
@{
4+
// Set the page title for the browser tab
5+
ViewData["Title"] = "Home page";
6+
7+
// Build the base URL for the application using current request information
8+
var originUrl = $"{Request.Scheme}://{Request.Host}{Request.PathBase}";
9+
10+
// Define the default document path
11+
var document = originUrl + "/PDF_Succinctly.pdf";
12+
13+
// Set the resource URL for Syncfusion PDF Viewer library files
14+
var resourceUrl = originUrl + "/ej2-pdfviewer-lib";
15+
}
16+
17+
<div>
18+
<h5>Select Document to View</h5>
19+
<ul>
20+
<li id="set" onclick="loadDocument1()"><a href="#">Document 1</a></li>
21+
<li id="set" onclick="loadDocument2()"><a href="#">Document 2</a></li>
22+
<li id="set" onclick="loadDocument3()"><a href="#">Document 3</a></li>
23+
</ul>
24+
<ejs-pdfviewer id="pdfviewer" style="height:600px" resourceUrl=@resourceUrl formFieldPropertiesChange="formFieldPropertiesChange" formFieldAdd="onFormFieldAdd">
25+
</ejs-pdfviewer>
26+
</div>
27+
28+
<script>
29+
var originUrl = '@originUrl';
30+
31+
function loadDocument1() {
32+
var viewer = document.getElementById('pdfviewer').ej2_instances[0];
33+
viewer.load(originUrl + "/form-filling-document.pdf", "null");
34+
}
35+
36+
function loadDocument2() {
37+
var viewer = document.getElementById('pdfviewer').ej2_instances[0];
38+
viewer.load(originUrl + "/form-designer.pdf", "null");
39+
}
40+
41+
function loadDocument3() {
42+
var viewer = document.getElementById('pdfviewer').ej2_instances[0];
43+
viewer.load(originUrl + "/pdf-succinctly (5).pdf", "null");
44+
}
45+
46+
function validateEmail(value) {
47+
const emailRegex = /^[^\s@@]+@@[^\s@@]+\.[^\s@@]+$/;
48+
return emailRegex.test(value);
49+
}
50+
51+
function validateNumber(value) {
52+
const numberRegex = /^[0-9]+$/;
53+
return numberRegex.test(value);
54+
}
55+
56+
function validateDate(value) {
57+
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
58+
return dateRegex.test(value);
59+
}
60+
61+
function onFormFieldAdd(event) {
62+
console.log('New form field added:', event.field);
63+
64+
if (event.field.type === 'Text') {
65+
event.field.placeholder = 'Enter text here...';
66+
}
67+
}
68+
69+
70+
function formFieldPropertiesChange(event) {
71+
const viewer = document.getElementById('pdfviewer').ej2_instances[0];
72+
const field = event.field;
73+
const value = field.value;
74+
let isValid = true;
75+
76+
// Remove '_content' from the field ID if it exists
77+
const fieldIdWithoutContent = field.id.replace('_content', '');
78+
79+
// Find the matching field in the form field collection
80+
const formFields = viewer.formFieldCollections;
81+
const matchingField = formFields.find(f => f.id === fieldIdWithoutContent);
82+
83+
if (!matchingField) {
84+
console.error(`Field with ID "${fieldIdWithoutContent}" not found in the form field collection.`);
85+
return;
86+
}
87+
88+
// Validate based on field name
89+
if (matchingField.name.includes('My Email')) {
90+
isValid = validateEmail(value);
91+
} else if (matchingField.name.includes('My Phone')) {
92+
isValid = validateNumber(value);
93+
} else if (matchingField.name.includes('dob')) {
94+
isValid = validateDate(value);
95+
}
96+
97+
if (!isValid) {
98+
// Update field properties to show invalid state (red border), keep the value as is
99+
viewer.formDesigner.updateFormField(matchingField, { borderColor: 'red' });
100+
} else {
101+
// Reset to the default border color when valid input is entered
102+
viewer.formDesigner.updateFormField(matchingField, { borderColor: '#2f2f2fff' });
103+
}
104+
}
105+
106+
107+
</script>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.Caching.Memory;
3+
using Syncfusion.EJ2.PdfViewer;
4+
using Newtonsoft.Json;
5+
using Microsoft.AspNetCore.Mvc.RazorPages;
6+
using System.Reflection;
7+
using System.Net;
8+
using Syncfusion.Pdf.Parsing;
9+
10+
namespace CoreSample.Pages
11+
{
12+
[IgnoreAntiforgeryToken(Order = 1001)]
13+
public class IndexModel : PageModel
14+
{
15+
16+
private readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment;
17+
private IMemoryCache _cache;
18+
19+
public IndexModel(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, IMemoryCache cache)
20+
{
21+
_hostingEnvironment = hostingEnvironment;
22+
_cache = cache;
23+
}
24+
25+
}
26+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page
2+
@model PrivacyModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace CoreSample.Pages
5+
{
6+
public class PrivacyModel : PageModel
7+
{
8+
private readonly ILogger<PrivacyModel> _logger;
9+
10+
public PrivacyModel(ILogger<PrivacyModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
}
18+
}
19+
20+
}

0 commit comments

Comments
 (0)