Skip to content

Commit 02352d2

Browse files
951648: Updated CSP Sample
1 parent 959a159 commit 02352d2

19 files changed

+583
-0
lines changed
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.10.34607.79
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContentSecurityPolicy", "ContentSecurityPolicy\ContentSecurityPolicy.csproj", "{FD7944D2-FBB0-4820-978C-DF7B37A79B67}"
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+
{FD7944D2-FBB0-4820-978C-DF7B37A79B67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{FD7944D2-FBB0-4820-978C-DF7B37A79B67}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{FD7944D2-FBB0-4820-978C-DF7B37A79B67}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{FD7944D2-FBB0-4820-978C-DF7B37A79B67}.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 = {31245B35-82FC-4C3B-A888-4730D0AD8EE0}
24+
EndGlobalSection
25+
EndGlobal
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>net8.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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
5+
</PropertyGroup>
6+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
7+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
8+
</PropertyGroup>
9+
</Project>
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@page "{handler?}"
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Home page";
5+
}
6+
7+
<div class="text-center">
8+
<ejs-pdfviewer id="pdfviewer" style="height:600px" resourceUrl="https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2-pdfviewer-lib" documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf" enableLocalStorage="true">
9+
</ejs-pdfviewer>
10+
</div>
11+
12+
<script type="text/javascript">
13+
14+
</script>
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
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+
public IActionResult OnPostLoad([FromBody] jsonObjects responseData)
25+
{
26+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
27+
MemoryStream stream = new MemoryStream();
28+
var jsonObject = JsonConverterstring(responseData);
29+
object jsonResult = new object();
30+
if (jsonObject != null && jsonObject.ContainsKey("document"))
31+
{
32+
if (bool.Parse(jsonObject["isFileName"]))
33+
{
34+
string documentPath = GetDocumentPath(jsonObject["document"]);
35+
if (!string.IsNullOrEmpty(documentPath))
36+
{
37+
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
38+
stream = new MemoryStream(bytes);
39+
}
40+
else
41+
{
42+
string fileName = jsonObject["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0];
43+
if (fileName == "http" || fileName == "https")
44+
{
45+
WebClient WebClient = new WebClient();
46+
byte[] pdfDoc = WebClient.DownloadData(jsonObject["document"]);
47+
stream = new MemoryStream(pdfDoc);
48+
}
49+
else
50+
return this.Content(jsonObject["document"] + " is not found");
51+
}
52+
}
53+
else
54+
{
55+
byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
56+
stream = new MemoryStream(bytes);
57+
}
58+
}
59+
jsonResult = pdfviewer.Load(stream, jsonObject);
60+
return Content(JsonConvert.SerializeObject(jsonResult));
61+
}
62+
63+
public Dictionary<string, string> JsonConverterstring(jsonObjects results)
64+
{
65+
Dictionary<string, object> resultObjects = new Dictionary<string, object>();
66+
resultObjects = results.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
67+
.ToDictionary(prop => prop.Name, prop => prop.GetValue(results, null));
68+
var emptyObjects = (from kv in resultObjects
69+
where kv.Value != null
70+
select kv).ToDictionary(kv => kv.Key, kv => kv.Value);
71+
Dictionary<string, string> jsonResult = emptyObjects.ToDictionary(k => k.Key, k => k.Value.ToString());
72+
return jsonResult;
73+
}
74+
75+
//Post action for processing the PDF documents.
76+
public IActionResult OnPostRenderPdfPages([FromBody] jsonObjects responseData)
77+
{
78+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
79+
var jsonObject = JsonConverterstring(responseData);
80+
object jsonResult = pdfviewer.GetPage(jsonObject);
81+
return Content(JsonConvert.SerializeObject(jsonResult));
82+
}
83+
84+
//Post action for unloading and disposing the PDF document resources
85+
public IActionResult OnPostUnload([FromBody] jsonObjects responseData)
86+
{
87+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
88+
var jsonObject = JsonConverterstring(responseData);
89+
pdfviewer.ClearCache(jsonObject);
90+
return this.Content("Document cache is cleared");
91+
}
92+
93+
//Post action for rendering the ThumbnailImages
94+
public IActionResult OnPostRenderThumbnailImages([FromBody] jsonObjects responseData)
95+
{
96+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
97+
var jsonObject = JsonConverterstring(responseData);
98+
object result = pdfviewer.GetThumbnailImages(jsonObject);
99+
return Content(JsonConvert.SerializeObject(result));
100+
}
101+
102+
//Post action for processing the bookmarks from the PDF documents
103+
public IActionResult OnPostBookmarks([FromBody] jsonObjects responseData)
104+
{
105+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
106+
var jsonObject = JsonConverterstring(responseData);
107+
object jsonResult = pdfviewer.GetBookmarks(jsonObject);
108+
return Content(JsonConvert.SerializeObject(jsonResult));
109+
}
110+
111+
//Post action for rendering the annotation comments
112+
public IActionResult OnPostRenderAnnotationComments([FromBody] jsonObjects responseData)
113+
{
114+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
115+
var jsonObject = JsonConverterstring(responseData);
116+
object jsonResult = pdfviewer.GetAnnotationComments(jsonObject);
117+
return Content(JsonConvert.SerializeObject(jsonResult));
118+
}
119+
120+
//Post action for exporting the annotations
121+
public IActionResult OnPostExportAnnotations([FromBody] jsonObjects responseData)
122+
{
123+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
124+
var jsonObject = JsonConverterstring(responseData);
125+
string jsonResult = pdfviewer.ExportAnnotation(jsonObject);
126+
return Content(jsonResult);
127+
}
128+
129+
//Post action for importing the annotations
130+
public IActionResult OnPostImportAnnotations([FromBody] jsonObjects responseData)
131+
{
132+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
133+
var jsonObject = JsonConverterstring(responseData);
134+
string jsonResult = string.Empty;
135+
object JsonResult;
136+
if (jsonObject != null && jsonObject.ContainsKey("fileName"))
137+
{
138+
string documentPath = GetDocumentPath(jsonObject["fileName"]);
139+
if (!string.IsNullOrEmpty(documentPath))
140+
{
141+
jsonResult = System.IO.File.ReadAllText(documentPath);
142+
}
143+
else
144+
{
145+
return this.Content(jsonObject["document"] + " is not found");
146+
}
147+
}
148+
else
149+
{
150+
string extension = Path.GetExtension(jsonObject["importedData"]);
151+
if (extension != ".xfdf")
152+
{
153+
JsonResult = pdfviewer.ImportAnnotation(jsonObject);
154+
return Content(JsonConvert.SerializeObject(JsonResult));
155+
}
156+
else
157+
{
158+
string documentPath = GetDocumentPath(jsonObject["importedData"]);
159+
if (!string.IsNullOrEmpty(documentPath))
160+
{
161+
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
162+
jsonObject["importedData"] = Convert.ToBase64String(bytes);
163+
JsonResult = pdfviewer.ImportAnnotation(jsonObject);
164+
return Content(JsonConvert.SerializeObject(JsonResult));
165+
}
166+
else
167+
{
168+
return this.Content(jsonObject["document"] + " is not found");
169+
}
170+
}
171+
}
172+
return Content(jsonResult);
173+
}
174+
175+
//Post action for downloading the PDF documents
176+
public IActionResult OnPostDownload([FromBody] jsonObjects responseData)
177+
{
178+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
179+
var jsonObject = JsonConverterstring(responseData);
180+
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
181+
return Content(documentBase);
182+
}
183+
184+
//Post action for printing the PDF documents
185+
public IActionResult OnPostPrintImages([FromBody] jsonObjects responseData)
186+
{
187+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
188+
var jsonObject = JsonConverterstring(responseData);
189+
object pageImage = pdfviewer.GetPrintImage(jsonObject);
190+
return Content(JsonConvert.SerializeObject(pageImage));
191+
}
192+
193+
//Gets the path of the PDF document
194+
private string GetDocumentPath(string document)
195+
{
196+
string documentPath = string.Empty;
197+
if (!System.IO.File.Exists(document))
198+
{
199+
string basePath = _hostingEnvironment.WebRootPath;
200+
string dataPath = string.Empty;
201+
dataPath = basePath + "/";
202+
if (System.IO.File.Exists(dataPath + (document)))
203+
documentPath = dataPath + document;
204+
}
205+
else
206+
{
207+
documentPath = document;
208+
}
209+
return documentPath;
210+
}
211+
}
212+
213+
public class jsonObjects
214+
{
215+
public string document { get; set; }
216+
public string password { get; set; }
217+
public string zoomFactor { get; set; }
218+
public string isFileName { get; set; }
219+
public string xCoordinate { get; set; }
220+
public string yCoordinate { get; set; }
221+
public string pageNumber { get; set; }
222+
public string documentId { get; set; }
223+
public string hashId { get; set; }
224+
public string sizeX { get; set; }
225+
public string sizeY { get; set; }
226+
public string startPage { get; set; }
227+
public string endPage { get; set; }
228+
public string stampAnnotations { get; set; }
229+
public string textMarkupAnnotations { get; set; }
230+
public string stickyNotesAnnotation { get; set; }
231+
public string shapeAnnotations { get; set; }
232+
public string measureShapeAnnotations { get; set; }
233+
public string action { get; set; }
234+
public string pageStartIndex { get; set; }
235+
public string pageEndIndex { get; set; }
236+
public string fileName { get; set; }
237+
public string elementId { get; set; }
238+
public string pdfAnnotation { get; set; }
239+
public string importPageList { get; set; }
240+
public string uniqueId { get; set; }
241+
public string data { get; set; }
242+
public string viewPortWidth { get; set; }
243+
public string viewPortHeight { get; set; }
244+
public string tilecount { get; set; }
245+
public bool isCompletePageSizeNotReceived { get; set; }
246+
public string freeTextAnnotation { get; set; }
247+
public string signatureData { get; set; }
248+
public string fieldsData { get; set; }
249+
public string formDesigner { get; set; }
250+
public string inkSignatureData { get; set; }
251+
public bool hideEmptyDigitalSignatureFields { get; set; }
252+
public bool showDigitalSignatureAppearance { get; set; }
253+
public bool digitalSignaturePresent { get; set; }
254+
public string tileXCount { get; set; }
255+
public string tileYCount { get; set; }
256+
public string digitalSignaturePageList { get; set; }
257+
public string annotationCollection { get; set; }
258+
public string annotationsPageList { get; set; }
259+
public string formFieldsPageList { get; set; }
260+
public bool isAnnotationsExist { get; set; }
261+
public bool isFormFieldAnnotationsExist { get; set; }
262+
public string documentLiveCount { get; set; }
263+
public string annotationDataFormat { get; set; }
264+
public string importedData { get; set; }
265+
}
266+
}

0 commit comments

Comments
 (0)