Skip to content

Commit e95c64f

Browse files
993766: Updated Sample for Redaction ASP.NET Core
1 parent 17a09a8 commit e95c64f

Some content is hidden

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

60 files changed

+1329
-0
lines changed
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="*" />
11+
<PackageReference Include="Syncfusion.EJ2.PdfViewer.AspNet.Core" Version="*" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.32112.339
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PDFViewerSample", "PDFViewerSample.csproj", "{39AA1883-BB43-4C46-9892-6033EA59C990}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{39AA1883-BB43-4C46-9892-6033EA59C990}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{39AA1883-BB43-4C46-9892-6033EA59C990}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{39AA1883-BB43-4C46-9892-6033EA59C990}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{39AA1883-BB43-4C46-9892-6033EA59C990}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5F13CE16-9CC4-4755-AFB4-367F461A209C}
24+
EndGlobalSection
25+
EndGlobal
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using System.Diagnostics;
4+
5+
namespace PDFViewerSample.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+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
@page
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Redaction programmatic support (All-in-one)";
5+
}
6+
<div class="text-center">
7+
<div style="margin-bottom:12px; display:flex; flex-wrap:wrap; gap:8px; align-items:center; justify-content:center;">
8+
<button type="button" class="e-btn" onclick="addRedaction()">Add Redaction</button>
9+
<button type="button" class="e-btn" onclick="deleteFirstRedaction()">Delete First Redaction</button>
10+
<button type="button" class="e-btn" onclick="editRedaction()">Edit Redaction</button>
11+
<button type="button" class="e-btn" onclick="addPageRedactions()">Add Page Redactions (1,3,5,7)</button>
12+
<button type="button" class="e-btn e-primary" onclick="applyRedaction()">Apply Redaction</button>
13+
</div>
14+
15+
<ejs-pdfviewer
16+
id="pdfViewer"
17+
style="height:640px; display:block"
18+
resourceUrl="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2-pdfviewer-lib"
19+
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
20+
isExtractText="true">
21+
</ejs-pdfviewer>
22+
</div>
23+
24+
<script type="text/javascript">
25+
// Make the viewer globally accessible to all handlers
26+
window.onload = function () {
27+
window.viewer = document.getElementById('pdfViewer').ej2_instances[0];
28+
29+
// Include Redaction UI entry in the main toolbar
30+
viewer.toolbarSettings = {
31+
toolbarItems: [
32+
'OpenOption', 'UndoRedoTool', 'PageNavigationTool', 'MagnificationTool', 'PanTool',
33+
'SelectionTool', 'CommentTool', 'SubmitForm', 'AnnotationEditTool', 'RedactionEditTool',
34+
'FormDesignerEditTool', 'SearchOption', 'PrintOption', 'DownloadOption'
35+
]
36+
};
37+
38+
// Default redaction appearance settings (used by UI and when not overridden)
39+
viewer.redactionSettings = {
40+
overlayText: 'Confidential',
41+
markerFillColor: '#FF0000',
42+
markerBorderColor: '#000000',
43+
isRepeat: false,
44+
fillColor: '#000000', // final fill color after redaction is applied
45+
fontColor: '#FFFFFF',
46+
fontSize: 12,
47+
fontFamily: 'Arial',
48+
textAlign: 'Center'
49+
};
50+
};
51+
52+
// 1) Add a single redaction annotation programmatically
53+
function addRedaction() {
54+
if (!window.viewer) return;
55+
viewer.annotation.addAnnotation('Redaction', {
56+
bound: { x: 200, y: 480, width: 160, height: 80 },
57+
pageNumber: 1,
58+
overlayText: 'Confidential',
59+
fillColor: '#000000', // preview overlay/background
60+
fontColor: '#FFFFFF',
61+
fontSize: 12,
62+
fontFamily: 'Arial',
63+
markerFillColor: '#FF0000',
64+
markerBorderColor: '#000000',
65+
beforeRedactionsApplied: false
66+
});
67+
console.log('Redaction added');
68+
}
69+
70+
// 2) Delete the first redaction annotation (if present)
71+
function deleteFirstRedaction() {
72+
if (!window.viewer) return;
73+
var list = viewer.annotationCollection || [];
74+
var firstRedaction = null;
75+
for (var i = 0; i < list.length; i++) {
76+
if (list[i].subject === 'Redaction') { firstRedaction = list[i]; break; }
77+
}
78+
if (firstRedaction) {
79+
viewer.annotationModule.deleteAnnotationById(firstRedaction.annotationId);
80+
console.log('First redaction deleted');
81+
} else {
82+
console.warn('No redaction found to delete.');
83+
}
84+
}
85+
86+
// 3) Edit existing redaction annotation properties
87+
function editRedaction() {
88+
if (!window.viewer) return;
89+
var list = viewer.annotationCollection || [];
90+
var edited = false;
91+
for (var i = 0; i < list.length; i++) {
92+
var item = list[i];
93+
if (item.subject === 'Redaction') {
94+
item.overlayText = 'EditedAnnotation';
95+
item.markerFillColor = '#22FF00';
96+
item.markerBorderColor = '#000000';
97+
item.isRepeat = true;
98+
item.fillColor = '#1F1F1F';
99+
item.fontColor = '#FFD400';
100+
item.fontSize = 14;
101+
item.fontFamily = 'Symbol';
102+
item.textAlign = 'Right';
103+
item.beforeRedactionsApplied = false;
104+
viewer.annotation.editAnnotation(item);
105+
edited = true;
106+
}
107+
}
108+
if (!edited) console.warn('No redaction found to edit.');
109+
else console.log('Redaction(s) edited');
110+
}
111+
112+
// 4) Add page redactions (entire pages) by page numbers (1-based)
113+
function addPageRedactions() {
114+
if (!window.viewer) return;
115+
viewer.annotation.addPageRedactions([1, 3, 5, 7]);
116+
console.log('Page redactions added for pages 1, 3, 5, 7');
117+
}
118+
119+
120+
// 5) Permanently apply all redaction marks
121+
function applyRedaction() {
122+
if (!window.viewer) return;
123+
// Irreversible: original content will be removed
124+
viewer.annotation.redact();
125+
console.log('Redaction applied');
126+
}
127+
</script>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
9+
namespace PDFViewerSample.Pages
10+
{
11+
[IgnoreAntiforgeryToken(Order = 1001)]
12+
public class IndexModel : PageModel
13+
{
14+
15+
private readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment;
16+
private IMemoryCache _cache;
17+
18+
public IndexModel(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, IMemoryCache cache)
19+
{
20+
_hostingEnvironment = hostingEnvironment;
21+
_cache = cache;
22+
}
23+
}
24+
}
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace PDFViewerSample.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+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - PDFViewerSample</title>
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
8+
<!-- Syncfusion ASP.NET Core controls styles -->
9+
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/31.2.12/fluent.css" />
10+
<!-- Syncfusion ASP.NET Core controls scripts -->
11+
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js"></script>
12+
</head>
13+
<body>
14+
<header>
15+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
16+
<div class="container">
17+
<a class="navbar-brand" asp-area="" asp-page="/Index">PDFViewerSample</a>
18+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
19+
aria-expanded="false" aria-label="Toggle navigation">
20+
<span class="navbar-toggler-icon"></span>
21+
</button>
22+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
23+
<ul class="navbar-nav flex-grow-1">
24+
<li class="nav-item">
25+
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
26+
</li>
27+
<li class="nav-item">
28+
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
29+
</li>
30+
</ul>
31+
</div>
32+
</div>
33+
</nav>
34+
</header>
35+
<div class="container">
36+
<main role="main" class="pb-3">
37+
@RenderBody()
38+
</main>
39+
</div>
40+
41+
<footer class="border-top footer text-muted">
42+
<div class="container">
43+
&copy; 2022 - PDFViewerSample - <a asp-area="" asp-page="/Privacy">Privacy</a>
44+
</div>
45+
</footer>
46+
47+
@await RenderSectionAsync("Scripts", required: false)
48+
<!-- Syncfusion ASP.NET Core Script Manager -->
49+
<ejs-scripts></ejs-scripts>
50+
</body>
51+
</html>

0 commit comments

Comments
 (0)