Skip to content

Commit 9646f84

Browse files
845073: Updated sample to client side using resourceUrl
1 parent 88bd1b2 commit 9646f84

File tree

4 files changed

+34
-43
lines changed

4 files changed

+34
-43
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
<add key="nexus" value="https://nexus.syncfusioninternal.com/repository/nuget-hosted/" />
7+
</packageSources>
8+
<disabledPackageSources>
9+
<clear />
10+
</disabledPackageSources>
11+
<fallbackPackageFolders>
12+
<clear />
13+
</fallbackPackageFolders>
14+
</configuration>
Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,37 @@
1-
@page "{handler?}"
1+
@page "{handler?}"
22
@using ShowHideAnnotations.Pages
33
@model IndexModel
44
@{
55
ViewData["Title"] = "Home page";
66
}
77

88
<div class="text-center">
9-
<button id="toggleBtn" onclick="toggleAnnotations()">Hide Annotations</button>
10-
<ejs-pdfviewer id="pdfviewer" style="height:600px" serviceUrl="/Index" documentPath="">
9+
<button id="hideBtn">Hide Annotations</button>
10+
<button id="unhideBtn">Show Annotations</button>
11+
<ejs-pdfviewer id="pdfviewer" style="height:600px" resourceUrl="https://cdn.syncfusion.com/ej2/30.1.37/dist/ej2-pdfviewer-lib" documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf">
1112
</ejs-pdfviewer>
1213
</div>
1314

1415
<script type="text/javascript">
1516
var exportObject = null;
16-
var annotationsVisible = true;
1717
18-
// Function to run when page loads
1918
document.addEventListener('DOMContentLoaded', function() {
20-
// Get viewer instance
21-
var viewer = document.getElementById('pdfviewer').ej2_instances[0];
19+
var pdfviewer = document.getElementById('pdfviewer').ej2_instances[0];
2220
23-
// Load the PDF document
24-
if (viewer) {
25-
viewer.documentPath="Data/Annotations.pdf";
26-
27-
// You can also add any initialization code here
28-
console.log("PDF viewer initialized and document loading started");
29-
}
30-
});
31-
32-
function toggleAnnotations() {
33-
var viewer = document.getElementById('pdfviewer').ej2_instances[0];
34-
35-
if (annotationsVisible) {
36-
// Hide annotations by exporting and deleting them
37-
viewer.exportAnnotationsAsObject().then(function(value) {
21+
function HideAnnotations() {
22+
pdfviewer.exportAnnotationsAsObject().then(function(value) {
3823
exportObject = value;
39-
40-
var count = viewer.annotationCollection.length;
41-
for (var i = 0; i < count; i++) {
42-
// Always delete the first item as the collection shrinks
43-
viewer.annotationModule.deleteAnnotationById(viewer.annotationCollection[0].annotationId);
44-
}
45-
46-
annotationsVisible = false;
47-
document.getElementById('toggleBtn').textContent = 'Show Annotations';
24+
pdfviewer.deleteAnnotations();
4825
});
49-
} else {
50-
// Restore annotations
26+
}
27+
28+
function UnHideAnnotations() {
5129
if (exportObject) {
52-
var exportAnnotObject = JSON.parse(exportObject);
53-
viewer.importAnnotation(exportAnnotObject);
30+
pdfviewer.importAnnotation(JSON.parse(exportObject));
5431
}
55-
56-
annotationsVisible = true;
57-
document.getElementById('toggleBtn').textContent = 'Hide Annotations';
5832
}
59-
}
33+
34+
document.getElementById('hideBtn').addEventListener('click', HideAnnotations);
35+
document.getElementById('unhideBtn').addEventListener('click', UnHideAnnotations);
36+
});
6037
</script>

How to/Show and Hide Annotations/ShowHideAnnotations/ShowHideAnnotations/Pages/Shared/_Layout.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
99
<link rel="stylesheet" href="~/PDFViewerSample.styles.css" asp-append-version="true" />
1010
<!-- Syncfusion ASP.NET Core controls styles -->
11-
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/29.1.33/fluent.css" />
11+
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/30.1.37/fluent.css" />
1212
<!-- Syncfusion ASP.NET Core controls scripts -->
13-
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js"></script>
13+
<script src="https://cdn.syncfusion.com/ej2/30.1.37/dist/ej2.min.js"></script>
1414
</head>
1515
<body>
1616
<div class="container">

How to/Show and Hide Annotations/ShowHideAnnotations/ShowHideAnnotations/ShowHideAnnotations.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="*" />
11-
<PackageReference Include="Syncfusion.EJ2.PdfViewer.AspNet.Core" Version="*" />
10+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="30.1.40" />
11+
<PackageReference Include="Syncfusion.EJ2.PdfViewer.AspNet.Core" Version="100.2.100" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)