Skip to content

Commit b05105a

Browse files
845073: Sample for Show and Hide Annotation
1 parent e5a2015 commit b05105a

Some content is hidden

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

57 files changed

+40568
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html><html lang="en"><head>
2+
<title>EJ2 PDF Viewer</title>
3+
<meta charset="utf-8">
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<meta name="description" content="Typescript PDF Viewer Control">
6+
<meta name="author" content="Syncfusion">
7+
<link href="https://cdn.syncfusion.com/ej2/27.2.5/ej2-base/styles/material.css" rel="stylesheet">
8+
<link href="https://cdn.syncfusion.com/ej2/27.2.5/ej2-pdfviewer/styles/material.css" rel="stylesheet">
9+
<link href="https://cdn.syncfusion.com/ej2/27.2.5/ej2-buttons/styles/material.css" rel="stylesheet">
10+
<link href="https://cdn.syncfusion.com/ej2/27.2.5/ej2-popups/styles/material.css" rel="stylesheet">
11+
<link href="https://cdn.syncfusion.com/ej2/27.2.5/ej2-navigations/styles/material.css" rel="stylesheet">
12+
<link href="https://cdn.syncfusion.com/ej2/27.2.5/ej2-dropdowns/styles/material.css" rel="stylesheet">
13+
<link href="https://cdn.syncfusion.com/ej2/27.2.5/ej2-lists/styles/material.css" rel="stylesheet">
14+
<link href="https://cdn.syncfusion.com/ej2/27.2.5/ej2-inputs/styles/material.css" rel="stylesheet">
15+
<link href="https://cdn.syncfusion.com/ej2/27.2.5/ej2-splitbuttons/styles/material.css" rel="stylesheet">
16+
<link href="https://cdn.syncfusion.com/ej2/27.2.5/ej2-notifications/styles/material.css" rel="stylesheet">
17+
18+
<!-- Essential JS 2 PDF Viewer's script -->
19+
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
20+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
21+
22+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
23+
</head>
24+
<body>
25+
<div id="container">
26+
<button id="toggleBtn">Hide Annotation</button>
27+
<div id="PdfViewer" style="height:500px;width:100%;"></div>
28+
</div>
29+
30+
<script>
31+
var ele = document.getElementById('container');
32+
if(ele) {
33+
ele.style.visibility = "visible";
34+
}
35+
</script>
36+
<script src="index.js" type="text/javascript"></script>
37+
</body></html>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
let exportObject = null;
2+
let annotationsVisible = true;
3+
4+
var pdfviewer = new ej.pdfviewer.PdfViewer({
5+
serviceUrl: 'https://localhost:44309/pdfviewer',
6+
documentPath: 'Annotations.pdf',
7+
});
8+
ej.pdfviewer.PdfViewer.Inject(ej.pdfviewer.TextSelection, ej.pdfviewer.TextSearch, ej.pdfviewer.Print, ej.pdfviewer.Navigation, ej.pdfviewer.Toolbar,
9+
ej.pdfviewer.Magnification, ej.pdfviewer.Annotation, ej.pdfviewer.FormDesigner, ej.pdfviewer.FormFields, ej.pdfviewer.PageOrganizer);
10+
pdfviewer.appendTo('#PdfViewer');
11+
12+
// Toggle logic
13+
document.getElementById('toggleBtn').addEventListener('click', () => {
14+
const button = document.getElementById('toggleBtn');
15+
16+
if (annotationsVisible) {
17+
// Export and delete annotations
18+
pdfviewer.exportAnnotationsAsObject().then((value) => {
19+
exportObject = value;
20+
const count = pdfviewer.annotationCollection.length;
21+
for (let i = 0; i < count; i++) {
22+
pdfviewer.deleteAnnotations(pdfviewer.annotationCollection[0]);
23+
}
24+
button.innerText = 'Show Annotation';
25+
annotationsVisible = false;
26+
});
27+
} else {
28+
// Restore annotations
29+
if (exportObject) {
30+
pdfviewer.importAnnotation(JSON.parse(exportObject));
31+
}
32+
button.innerText = 'Hide Annotation';
33+
annotationsVisible = true;
34+
}
35+
});
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.3.32901.215
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ControllerPractice", "ControllerPractice\ControllerPractice.csproj", "{14100176-83DC-4CB1-87D4-4D71C9E8F177}"
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+
{14100176-83DC-4CB1-87D4-4D71C9E8F177}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{14100176-83DC-4CB1-87D4-4D71C9E8F177}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{14100176-83DC-4CB1-87D4-4D71C9E8F177}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{14100176-83DC-4CB1-87D4-4D71C9E8F177}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{14100176-83DC-4CB1-87D4-4D71C9E8F177}.Release-Xml|Any CPU.ActiveCfg = Release|Any CPU
20+
{14100176-83DC-4CB1-87D4-4D71C9E8F177}.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 = {676A0D7F-7DC9-4AC1-B66A-956820E0B388}
27+
EndGlobalSection
28+
EndGlobal
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.13" />
9+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="22.2.10" />
10+
<PackageReference Include="Syncfusion.EJ2.PdfViewer.AspNet.Core.Windows" Version="22.2.10" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
5+
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
6+
</PropertyGroup>
7+
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using ControllerPractice.Models;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Logging;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
10+
namespace ControllerPractice.Controllers
11+
{
12+
public class HomeController : Controller
13+
{
14+
private readonly ILogger<HomeController> _logger;
15+
16+
public HomeController(ILogger<HomeController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
public IActionResult Index()
22+
{
23+
return View();
24+
}
25+
26+
public IActionResult Privacy()
27+
{
28+
return View();
29+
}
30+
31+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
32+
public IActionResult Error()
33+
{
34+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)