Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Redaction/Add Redaction Annotation Programmatically/NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<fallbackPackageFolders>
<clear />
</fallbackPackageFolders>
<disabledPackageSources>
<clear />
</disabledPackageSources>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="*" />
<PackageReference Include="Syncfusion.EJ2.PdfViewer.AspNet.Core" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PDFViewerSample", "PDFViewerSample.csproj", "{39AA1883-BB43-4C46-9892-6033EA59C990}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{39AA1883-BB43-4C46-9892-6033EA59C990}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39AA1883-BB43-4C46-9892-6033EA59C990}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39AA1883-BB43-4C46-9892-6033EA59C990}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39AA1883-BB43-4C46-9892-6033EA59C990}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5F13CE16-9CC4-4755-AFB4-367F461A209C}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;

namespace PDFViewerSample.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
127 changes: 127 additions & 0 deletions Redaction/Add Redaction Annotation Programmatically/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
@page
@model IndexModel
@{
ViewData["Title"] = "Redaction programmatic support (All-in-one)";
}
<div class="text-center">
<div style="margin-bottom:12px; display:flex; flex-wrap:wrap; gap:8px; align-items:center; justify-content:center;">
<button type="button" class="e-btn" onclick="addRedaction()">Add Redaction</button>
<button type="button" class="e-btn" onclick="deleteFirstRedaction()">Delete First Redaction</button>
<button type="button" class="e-btn" onclick="editRedaction()">Edit Redaction</button>
<button type="button" class="e-btn" onclick="addPageRedactions()">Add Page Redactions (1,3,5,7)</button>
<button type="button" class="e-btn e-primary" onclick="applyRedaction()">Apply Redaction</button>
</div>

<ejs-pdfviewer
id="pdfViewer"
style="height:640px; display:block"
resourceUrl="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2-pdfviewer-lib"
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
isExtractText="true">
</ejs-pdfviewer>
</div>

<script type="text/javascript">
// Make the viewer globally accessible to all handlers
window.onload = function () {
window.viewer = document.getElementById('pdfViewer').ej2_instances[0];

// Include Redaction UI entry in the main toolbar
viewer.toolbarSettings = {
toolbarItems: [
'OpenOption', 'UndoRedoTool', 'PageNavigationTool', 'MagnificationTool', 'PanTool',
'SelectionTool', 'CommentTool', 'SubmitForm', 'AnnotationEditTool', 'RedactionEditTool',
'FormDesignerEditTool', 'SearchOption', 'PrintOption', 'DownloadOption'
]
};

// Default redaction appearance settings (used by UI and when not overridden)
viewer.redactionSettings = {
overlayText: 'Confidential',
markerFillColor: '#FF0000',
markerBorderColor: '#000000',
isRepeat: false,
fillColor: '#000000', // final fill color after redaction is applied
fontColor: '#FFFFFF',
fontSize: 12,
fontFamily: 'Arial',
textAlign: 'Center'
};
};

// 1) Add a single redaction annotation programmatically
function addRedaction() {
if (!window.viewer) return;
viewer.annotation.addAnnotation('Redaction', {
bound: { x: 200, y: 480, width: 160, height: 80 },
pageNumber: 1,
overlayText: 'Confidential',
fillColor: '#000000', // preview overlay/background
fontColor: '#FFFFFF',
fontSize: 12,
fontFamily: 'Arial',
markerFillColor: '#FF0000',
markerBorderColor: '#000000',
beforeRedactionsApplied: false
});
console.log('Redaction added');
}

// 2) Delete the first redaction annotation (if present)
function deleteFirstRedaction() {
if (!window.viewer) return;
var list = viewer.annotationCollection || [];
var firstRedaction = null;
for (var i = 0; i < list.length; i++) {
if (list[i].subject === 'Redaction') { firstRedaction = list[i]; break; }
}
if (firstRedaction) {
viewer.annotationModule.deleteAnnotationById(firstRedaction.annotationId);
console.log('First redaction deleted');
} else {
console.warn('No redaction found to delete.');
}
}

// 3) Edit existing redaction annotation properties
function editRedaction() {
if (!window.viewer) return;
var list = viewer.annotationCollection || [];
var edited = false;
for (var i = 0; i < list.length; i++) {
var item = list[i];
if (item.subject === 'Redaction') {
item.overlayText = 'EditedAnnotation';
item.markerFillColor = '#22FF00';
item.markerBorderColor = '#000000';
item.isRepeat = true;
item.fillColor = '#1F1F1F';
item.fontColor = '#FFD400';
item.fontSize = 14;
item.fontFamily = 'Symbol';
item.textAlign = 'Right';
item.beforeRedactionsApplied = false;
viewer.annotation.editAnnotation(item);
edited = true;
}
}
if (!edited) console.warn('No redaction found to edit.');
else console.log('Redaction(s) edited');
}

// 4) Add page redactions (entire pages) by page numbers (1-based)
function addPageRedactions() {
if (!window.viewer) return;
viewer.annotation.addPageRedactions([1, 3, 5, 7]);
console.log('Page redactions added for pages 1, 3, 5, 7');
}


// 5) Permanently apply all redaction marks
function applyRedaction() {
if (!window.viewer) return;
// Irreversible: original content will be removed
viewer.annotation.redact();
console.log('Redaction applied');
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Syncfusion.EJ2.PdfViewer;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Reflection;
using System.Net;

namespace PDFViewerSample.Pages
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class IndexModel : PageModel
{

private readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment;
private IMemoryCache _cache;

public IndexModel(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, IMemoryCache cache)
{
_hostingEnvironment = hostingEnvironment;
_cache = cache;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace PDFViewerSample.Pages
{
public class PrivacyModel : PageModel
{
private readonly ILogger<PrivacyModel> _logger;

public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}

public void OnGet()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - PDFViewerSample</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- Syncfusion ASP.NET Core controls styles -->
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/31.2.12/fluent.css" />
<!-- Syncfusion ASP.NET Core controls scripts -->
<script src="https://cdn.syncfusion.com/ej2/31.2.12/dist/ej2.min.js"></script>
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">PDFViewerSample</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2022 - PDFViewerSample - <a asp-area="" asp-page="/Privacy">Privacy</a>
</div>
</footer>

@await RenderSectionAsync("Scripts", required: false)
<!-- Syncfusion ASP.NET Core Script Manager -->
<ejs-scripts></ejs-scripts>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */

a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}

a {
color: #0077cc;
}

.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}

.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}

button.accept-policy {
font-size: 1rem;
line-height: inherit;
}

.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px;
}
Loading