From 1c9b490cf40c250a3903e746e9288eff810a8f6b Mon Sep 17 00:00:00 2001 From: Uma-SF4267 Date: Fri, 20 Sep 2024 12:14:55 +0530 Subject: [PATCH] 911119: Added validatePassword action in organize pdf sample --- .../Controllers/HomeController.cs | 49 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 4 +- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/How to/Organize pdf/PDFViewerSample/PDFViewerSample/Controllers/HomeController.cs b/How to/Organize pdf/PDFViewerSample/PDFViewerSample/Controllers/HomeController.cs index 2b4e91e..cc45412 100644 --- a/How to/Organize pdf/PDFViewerSample/PDFViewerSample/Controllers/HomeController.cs +++ b/How to/Organize pdf/PDFViewerSample/PDFViewerSample/Controllers/HomeController.cs @@ -58,6 +58,55 @@ public ActionResult Load(jsonObjects jsonObject) return Content(JsonConvert.SerializeObject(jsonResult)); } + [System.Web.Mvc.HttpPost] + public ActionResult ValidatePassword(jsonObjects jsonObject) + { + PdfRenderer pdfviewer = new PdfRenderer(); + MemoryStream stream = new MemoryStream(); + var jsonData = JsonConverter(jsonObject); + object jsonResult = new object(); + if (jsonObject != null && jsonData.ContainsKey("document")) + { + if (bool.Parse(jsonData["isFileName"])) + { + string documentPath = GetDocumentPath(jsonData["document"]); + + if (!string.IsNullOrEmpty(documentPath)) + { + byte[] bytes = System.IO.File.ReadAllBytes(documentPath); + stream = new MemoryStream(bytes); + } + else + { + string fileName = jsonData["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0]; + if (fileName == "http" || fileName == "https") + { + var WebClient = new WebClient(); + byte[] pdfDoc = WebClient.DownloadData(jsonData["document"]); + stream = new MemoryStream(pdfDoc); + } + else + { + return this.Content(jsonData["document"] + " is not found"); + } + } + } + else + { + byte[] bytes = Convert.FromBase64String(jsonData["document"]); + stream = new MemoryStream(bytes); + + } + } + string password = null; + if (jsonObject != null && jsonData.ContainsKey("password")) + { + password = jsonData["password"]; + } + var result = pdfviewer.Load(stream, password); + return Content(JsonConvert.SerializeObject(result)); + } + public Dictionary JsonConverter(jsonObjects results) { Dictionary resultObjects = new Dictionary(); diff --git a/How to/Organize pdf/PDFViewerSample/PDFViewerSample/Views/Shared/_Layout.cshtml b/How to/Organize pdf/PDFViewerSample/PDFViewerSample/Views/Shared/_Layout.cshtml index a896b33..d9756c1 100644 --- a/How to/Organize pdf/PDFViewerSample/PDFViewerSample/Views/Shared/_Layout.cshtml +++ b/How to/Organize pdf/PDFViewerSample/PDFViewerSample/Views/Shared/_Layout.cshtml @@ -7,9 +7,9 @@ @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") - + - +