Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions PDFViewer/ASP.NET MVC Razor Examples/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,57 @@ 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 Expand Up @@ -133,6 +184,15 @@ public ActionResult RenderPdfPages(jsonObjects jsonObject)
return Content(JsonConvert.SerializeObject(jsonResult));
}

[System.Web.Mvc.HttpPost]
public ActionResult RenderPdfTexts(jsonObjects jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
var jsonData = JsonConverter(jsonObject);
object jsonResult = pdfviewer.GetDocumentText(jsonData);
return Content(JsonConvert.SerializeObject(jsonResult));
}

[System.Web.Mvc.HttpPost]
public ActionResult Unload(jsonObjects jsonObject)
{
Expand Down Expand Up @@ -279,5 +339,6 @@ public class jsonObjects
public string isFormFieldAnnotationsExist { get; set; }
public string documentLiveCount { get; set; }
public string annotationDataFormat { get; set; }
public string organizePages { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/20.3.61/fluent.css" />
<script src="https://cdn.syncfusion.com/ej2/20.3.61/dist/ej2.min.js"></script>
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/27.1.48/fluent.css" />
<script src="https://cdn.syncfusion.com/ej2/27.1.48/dist/ej2.min.js"></script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
Expand Down
Loading