Skip to content

845073: Sample to show and Hide Annotations #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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.10.34607.79
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShowHideAnnotations", "ShowHideAnnotations\ShowHideAnnotations.csproj", "{AEF9913F-0F38-4676-9A9F-D1042B5C30AC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AEF9913F-0F38-4676-9A9F-D1042B5C30AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEF9913F-0F38-4676-9A9F-D1042B5C30AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEF9913F-0F38-4676-9A9F-D1042B5C30AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEF9913F-0F38-4676-9A9F-D1042B5C30AC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {31245B35-82FC-4C3B-A888-4730D0AD8EE0}
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,28 @@
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;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@page "{handler?}"
@using ShowHideAnnotations.Pages
@model IndexModel
@{
ViewData["Title"] = "Home page";
}

<div class="text-center">
<button id="toggleBtn" onclick="toggleAnnotations()">Hide Annotations</button>
<ejs-pdfviewer id="pdfviewer" style="height:600px" serviceUrl="/Index" documentPath="">
</ejs-pdfviewer>
</div>

<script type="text/javascript">
var exportObject = null;
var annotationsVisible = true;

// Function to run when page loads
document.addEventListener('DOMContentLoaded', function() {
// Get viewer instance
var viewer = document.getElementById('pdfviewer').ej2_instances[0];

// Load the PDF document
if (viewer) {
viewer.documentPath="Data/Annotations.pdf";

// You can also add any initialization code here
console.log("PDF viewer initialized and document loading started");
}
});

function toggleAnnotations() {
var viewer = document.getElementById('pdfviewer').ej2_instances[0];

if (annotationsVisible) {
// Hide annotations by exporting and deleting them
viewer.exportAnnotationsAsObject().then(function(value) {
exportObject = value;

var count = viewer.annotationCollection.length;
for (var i = 0; i < count; i++) {
// Always delete the first item as the collection shrinks
viewer.annotationModule.deleteAnnotationById(viewer.annotationCollection[0].annotationId);
}

annotationsVisible = false;
document.getElementById('toggleBtn').textContent = 'Show Annotations';
});
} else {
// Restore annotations
if (exportObject) {
var exportAnnotObject = JSON.parse(exportObject);
viewer.importAnnotation(exportAnnotObject);
}

annotationsVisible = true;
document.getElementById('toggleBtn').textContent = 'Hide Annotations';
}
}
</script>
Loading