Skip to content

Commit

Permalink
911119: Added validatePassword action in organize pdf sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Uma-SF4267 committed Sep 20, 2024
1 parent 022bb6e commit 5175ef8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
44 changes: 44 additions & 0 deletions How to/Organize pdf/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,50 @@ public IActionResult OnPostLoad([FromBody] jsonObjects responseData)
return Content(JsonConvert.SerializeObject(jsonResult));
}

public IActionResult OnPostValidatePassword([FromBody] jsonObjects responseData)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
MemoryStream stream = new MemoryStream();
var jsonObject = JsonConverterstring(responseData);
object jsonResult = new object();
if (jsonObject != null && jsonObject.ContainsKey("document"))
{
if (bool.Parse(jsonObject["isFileName"]))
{
string documentPath = GetDocumentPath(jsonObject["document"]);
if (!string.IsNullOrEmpty(documentPath))
{
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
stream = new MemoryStream(bytes);
}
else
{
string fileName = jsonObject["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0];
if (fileName == "http" || fileName == "https")
{
WebClient WebClient = new WebClient();
byte[] pdfDoc = WebClient.DownloadData(jsonObject["document"]);
stream = new MemoryStream(pdfDoc);
}
else
return this.Content(jsonObject["document"] + " is not found");
}
}
else
{
byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
stream = new MemoryStream(bytes);
}
}
string password = null;
if (jsonObject.ContainsKey("password"))
{
password = jsonObject["password"];
}
var result = pdfviewer.Load(stream, password);

return Content(JsonConvert.SerializeObject(result));
}
public Dictionary<string, string> JsonConverterstring(jsonObjects results)
{
Dictionary<string, object> resultObjects = new Dictionary<string, object>();
Expand Down
4 changes: 2 additions & 2 deletions How to/Organize pdf/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<title>@ViewData["Title"] - PDFViewerSample</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- Syncfusion ASP.NET Core controls styles -->
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/25.1.35/fluent.css" />
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/27.1.48/fluent.css" />
<!-- Syncfusion ASP.NET Core controls scripts -->
<script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js"></script>
<script src="https://cdn.syncfusion.com/ej2/27.1.48/dist/ej2.min.js"></script>
</head>
<body>
<header>
Expand Down

0 comments on commit 5175ef8

Please sign in to comment.