Skip to content

Commit

Permalink
Merge pull request #39 from SyncfusionExamples/EJ2-911119
Browse files Browse the repository at this point in the history
911119: Added validatePassword action in organize pdf sample
  • Loading branch information
SasidharanKaruppiah authored Sep 20, 2024
2 parents 060cb58 + 1c9b490 commit 48b98bf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> JsonConverter(jsonObjects results)
{
Dictionary<string, object> resultObjects = new Dictionary<string, object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<!-- Syncfusion ASP.NET MVC 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 MVC 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>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-dark">
Expand Down

0 comments on commit 48b98bf

Please sign in to comment.