Skip to content

Commit 54c5e15

Browse files
SaravanaPriya31SaravanaPriya31
authored andcommitted
877844: commit
1 parent b161d23 commit 54c5e15

File tree

10 files changed

+519
-0
lines changed

10 files changed

+519
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - PdfViewerWebService</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/PdfViewerWebService.styles.css" asp-append-version="true" />
10+
</head>
11+
<body>
12+
<header>
13+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
14+
<div class="container">
15+
<a class="navbar-brand" asp-area="" asp-page="/Index">PdfViewerWebService</a>
16+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
17+
aria-expanded="false" aria-label="Toggle navigation">
18+
<span class="navbar-toggler-icon"></span>
19+
</button>
20+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
21+
<ul class="navbar-nav flex-grow-1">
22+
<li class="nav-item">
23+
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
24+
</li>
25+
<li class="nav-item">
26+
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
27+
</li>
28+
</ul>
29+
</div>
30+
</div>
31+
</nav>
32+
</header>
33+
<div class="container">
34+
<main role="main" class="pb-3">
35+
@RenderBody()
36+
</main>
37+
</div>
38+
39+
<footer class="border-top footer text-muted">
40+
<div class="container">
41+
&copy; 2023 - PdfViewerWebService - <a asp-area="" asp-page="/Privacy">Privacy</a>
42+
</div>
43+
</footer>
44+
45+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
46+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
47+
<script src="~/js/site.js" asp-append-version="true"></script>
48+
49+
@await RenderSectionAsync("Scripts", required: false)
50+
</body>
51+
</html>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2+
for details on configuring this project to bundle and minify static web assets. */
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
a {
11+
color: #0077cc;
12+
}
13+
14+
.btn-primary {
15+
color: #fff;
16+
background-color: #1b6ec2;
17+
border-color: #1861ac;
18+
}
19+
20+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
21+
color: #fff;
22+
background-color: #1b6ec2;
23+
border-color: #1861ac;
24+
}
25+
26+
.border-top {
27+
border-top: 1px solid #e5e5e5;
28+
}
29+
.border-bottom {
30+
border-bottom: 1px solid #e5e5e5;
31+
}
32+
33+
.box-shadow {
34+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
35+
}
36+
37+
button.accept-policy {
38+
font-size: 1rem;
39+
line-height: inherit;
40+
}
41+
42+
.footer {
43+
position: absolute;
44+
bottom: 0;
45+
width: 100%;
46+
white-space: nowrap;
47+
line-height: 60px;
48+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
2+
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Caching.Memory;
4+
using Newtonsoft.Json;
5+
using Syncfusion.EJ2.PdfViewer;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Net;
10+
11+
namespace PdfViewerWebService
12+
{
13+
[Route("[controller]")]
14+
[ApiController]
15+
public class PdfViewerController : ControllerBase
16+
{
17+
private IWebHostEnvironment _hostingEnvironment;
18+
        //Initialize the memory cache object  
19+
        public IMemoryCache _cache;
20+
public PdfViewerController(IWebHostEnvironment hostingEnvironment, IMemoryCache cache)
21+
{
22+
_hostingEnvironment = hostingEnvironment;
23+
_cache = cache;
24+
Console.WriteLine("PdfViewerController initialized");
25+
}
26+
27+
[HttpPost("Load")]
28+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
29+
[Route("[controller]/Load")]
30+
        //Post action for Loading the PDF documents  
31+
        public IActionResult Load([FromBody] Dictionary<string, string> jsonObject)
32+
{
33+
Console.WriteLine("Load called");
34+
//Initialize the PDF viewer object with memory cache object
35+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
36+
MemoryStream stream = new MemoryStream();
37+
object jsonResult = new object();
38+
if (jsonObject != null && jsonObject.ContainsKey("document"))
39+
{
40+
if (bool.Parse(jsonObject["isFileName"]))
41+
{
42+
string documentPath = GetDocumentPath(jsonObject["document"]);
43+
if (!string.IsNullOrEmpty(documentPath))
44+
{
45+
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
46+
stream = new MemoryStream(bytes);
47+
}
48+
else
49+
{
50+
string fileName = jsonObject["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0];
51+
52+
if (fileName == "http" || fileName == "https")
53+
{
54+
WebClient WebClient = new WebClient();
55+
byte[] pdfDoc = WebClient.DownloadData(jsonObject["document"]);
56+
stream = new MemoryStream(pdfDoc);
57+
}
58+
59+
else
60+
{
61+
return this.Content(jsonObject["document"] + " is not found");
62+
}
63+
}
64+
}
65+
else
66+
{
67+
byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
68+
stream = new MemoryStream(bytes);
69+
}
70+
}
71+
jsonResult = pdfviewer.Load(stream, jsonObject);
72+
return Content(JsonConvert.SerializeObject(jsonResult));
73+
}
74+
75+
[AcceptVerbs("Post")]
76+
[HttpPost("Bookmarks")]
77+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
78+
[Route("[controller]/Bookmarks")]
79+
        //Post action for processing the bookmarks from the PDF documents
80+
        public IActionResult Bookmarks([FromBody] Dictionary<string, string> jsonObject)
81+
{
82+
//Initialize the PDF Viewer object with memory cache object
83+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
84+
var jsonResult = pdfviewer.GetBookmarks(jsonObject);
85+
return Content(JsonConvert.SerializeObject(jsonResult));
86+
}
87+
88+
[AcceptVerbs("Post")]
89+
[HttpPost("RenderPdfPages")]
90+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
91+
[Route("[controller]/RenderPdfPages")]
92+
        //Post action for processing the PDF documents 
93+
        public IActionResult RenderPdfPages([FromBody] Dictionary<string, string> jsonObject)
94+
{
95+
//Initialize the PDF Viewer object with memory cache object
96+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
97+
object jsonResult = pdfviewer.GetPage(jsonObject);
98+
return Content(JsonConvert.SerializeObject(jsonResult));
99+
}
100+
101+
[AcceptVerbs("Post")]
102+
[HttpPost("RenderPdfTexts")]
103+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
104+
[Route("[controller]/RenderPdfTexts")]
105+
        //Post action for processing the PDF texts 
106+
        public IActionResult RenderPdfTexts([FromBody] Dictionary<string, string> jsonObject)
107+
{
108+
//Initialize the PDF Viewer object with memory cache object
109+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
110+
object jsonResult = pdfviewer.GetDocumentText(jsonObject);
111+
return Content(JsonConvert.SerializeObject(jsonResult));
112+
}
113+
114+
[AcceptVerbs("Post")]
115+
[HttpPost("RenderThumbnailImages")]
116+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
117+
[Route("[controller]/RenderThumbnailImages")]
118+
        //Post action for rendering the ThumbnailImages
119+
        public IActionResult RenderThumbnailImages([FromBody] Dictionary<string, string> jsonObject)
120+
{
121+
//Initialize the PDF Viewer object with memory cache object
122+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
123+
object result = pdfviewer.GetThumbnailImages(jsonObject);
124+
return Content(JsonConvert.SerializeObject(result));
125+
}
126+
[AcceptVerbs("Post")]
127+
[HttpPost("RenderAnnotationComments")]
128+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
129+
[Route("[controller]/RenderAnnotationComments")]
130+
        //Post action for rendering the annotations
131+
        public IActionResult RenderAnnotationComments([FromBody] Dictionary<string, string> jsonObject)
132+
{
133+
//Initialize the PDF Viewer object with memory cache object
134+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
135+
object jsonResult = pdfviewer.GetAnnotationComments(jsonObject);
136+
return Content(JsonConvert.SerializeObject(jsonResult));
137+
}
138+
[AcceptVerbs("Post")]
139+
[HttpPost("ExportAnnotations")]
140+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
141+
[Route("[controller]/ExportAnnotations")]
142+
        //Post action to export annotations
143+
        public IActionResult ExportAnnotations([FromBody] Dictionary<string, string> jsonObject)
144+
{
145+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
146+
string jsonResult = pdfviewer.ExportAnnotation(jsonObject);
147+
return Content(jsonResult);
148+
}
149+
[AcceptVerbs("Post")]
150+
[HttpPost("ImportAnnotations")]
151+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
152+
[Route("[controller]/ImportAnnotations")]
153+
        //Post action to import annotations
154+
        public IActionResult ImportAnnotations([FromBody] Dictionary<string, string> jsonObject)
155+
{
156+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
157+
string jsonResult = string.Empty;
158+
object JsonResult;
159+
if (jsonObject != null && jsonObject.ContainsKey("fileName"))
160+
{
161+
string documentPath = GetDocumentPath(jsonObject["fileName"]);
162+
if (!string.IsNullOrEmpty(documentPath))
163+
{
164+
jsonResult = System.IO.File.ReadAllText(documentPath);
165+
}
166+
else
167+
{
168+
return this.Content(jsonObject["document"] + " is not found");
169+
}
170+
}
171+
else
172+
{
173+
string extension = Path.GetExtension(jsonObject["importedData"]);
174+
if (extension != ".xfdf")
175+
{
176+
JsonResult = pdfviewer.ImportAnnotation(jsonObject);
177+
return Content(JsonConvert.SerializeObject(JsonResult));
178+
}
179+
else
180+
{
181+
string documentPath = GetDocumentPath(jsonObject["importedData"]);
182+
if (!string.IsNullOrEmpty(documentPath))
183+
{
184+
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
185+
jsonObject["importedData"] = Convert.ToBase64String(bytes);
186+
JsonResult = pdfviewer.ImportAnnotation(jsonObject);
187+
return Content(JsonConvert.SerializeObject(JsonResult));
188+
}
189+
else
190+
{
191+
return this.Content(jsonObject["document"] + " is not found");
192+
}
193+
}
194+
}
195+
return Content(jsonResult);
196+
}
197+
198+
[AcceptVerbs("Post")]
199+
[HttpPost("ExportFormFields")]
200+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
201+
[Route("[controller]/ExportFormFields")]
202+
public IActionResult ExportFormFields([FromBody] Dictionary<string, string> jsonObject)
203+
204+
{
205+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
206+
string jsonResult = pdfviewer.ExportFormFields(jsonObject);
207+
return Content(jsonResult);
208+
}
209+
210+
[AcceptVerbs("Post")]
211+
[HttpPost("ImportFormFields")]
212+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
213+
[Route("[controller]/ImportFormFields")]
214+
public IActionResult ImportFormFields([FromBody] Dictionary<string, string> jsonObject)
215+
{
216+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
217+
jsonObject["data"] = GetDocumentPath(jsonObject["data"]);
218+
object jsonResult = pdfviewer.ImportFormFields(jsonObject);
219+
return Content(JsonConvert.SerializeObject(jsonResult));
220+
}
221+
222+
[AcceptVerbs("Post")]
223+
[HttpPost("Unload")]
224+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
225+
[Route("[controller]/Unload")]
226+
        //Post action for unloading and disposing the PDF document resources 
227+
        public IActionResult Unload([FromBody] Dictionary<string, string> jsonObject)
228+
{
229+
//Initialize the PDF Viewer object with memory cache object
230+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
231+
pdfviewer.ClearCache(jsonObject);
232+
return this.Content("Document cache is cleared");
233+
}
234+
235+
236+
[HttpPost("Download")]
237+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
238+
[Route("[controller]/Download")]
239+
        //Post action for downloading the PDF documents
240+
        public IActionResult Download([FromBody] Dictionary<string, string> jsonObject)
241+
{
242+
//Initialize the PDF Viewer object with memory cache object
243+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
244+
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
245+
return Content(documentBase);
246+
}
247+
248+
[HttpPost("PrintImages")]
249+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
250+
[Route("[controller]/PrintImages")]
251+
        //Post action for printing the PDF documents
252+
        public IActionResult PrintImages([FromBody] Dictionary<string, string> jsonObject)
253+
{
254+
//Initialize the PDF Viewer object with memory cache object
255+
PdfRenderer pdfviewer = new PdfRenderer(_cache);
256+
object pageImage = pdfviewer.GetPrintImage(jsonObject);
257+
return Content(JsonConvert.SerializeObject(pageImage));
258+
}
259+
260+
//Gets the path of the PDF document
261+
private string GetDocumentPath(string document)
262+
{
263+
string documentPath = string.Empty;
264+
if (!System.IO.File.Exists(document))
265+
{
266+
var path = _hostingEnvironment.ContentRootPath;
267+
if (System.IO.File.Exists(path + "/Data/" + document))
268+
documentPath = path + "/Data/" + document;
269+
}
270+
else
271+
{
272+
documentPath = document;
273+
}
274+
Console.WriteLine(documentPath);
275+
return documentPath;
276+
}
277+
// GET api/values
278+
[HttpGet]
279+
public IEnumerable<string> Get()
280+
{
281+
return new string[] { "value1", "value2" };
282+
}
283+
284+
// GET api/values/5
285+
[HttpGet("{id}")]
286+
public string Get(int id)
287+
{
288+
return "value";
289+
}
290+
}
291+
}

0 commit comments

Comments
 (0)