Skip to content

Commit c9eb789

Browse files
authored
Merge pull request #39 from SyncfusionExamples/EJ2-896384-radiobutton
908531: Added validatePassword action to get whether document is password protected.
2 parents ce9ab34 + 6bba0f9 commit c9eb789

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

PDFViewer/ASP.NET MVC Razor Examples/Controllers/HomeController.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,57 @@ public ActionResult Load(jsonObjects jsonObject)
6060
return Content(JsonConvert.SerializeObject(jsonResult));
6161
}
6262

63+
[System.Web.Mvc.HttpPost]
64+
public ActionResult ValidatePassword(jsonObjects jsonObject)
65+
{
66+
PdfRenderer pdfviewer = new PdfRenderer();
67+
MemoryStream stream = new MemoryStream();
68+
var jsonData = JsonConverter(jsonObject);
69+
object jsonResult = new object();
70+
if (jsonObject != null && jsonData.ContainsKey("document"))
71+
{
72+
if (bool.Parse(jsonData["isFileName"]))
73+
{
74+
string documentPath = GetDocumentPath(jsonData["document"]);
75+
76+
if (!string.IsNullOrEmpty(documentPath))
77+
{
78+
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
79+
stream = new MemoryStream(bytes);
80+
81+
}
82+
else
83+
{
84+
string fileName = jsonData["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0];
85+
if (fileName == "http" || fileName == "https")
86+
{
87+
var WebClient = new WebClient();
88+
byte[] pdfDoc = WebClient.DownloadData(jsonData["document"]);
89+
stream = new MemoryStream(pdfDoc);
90+
}
91+
else
92+
{
93+
return this.Content(jsonData["document"] + " is not found");
94+
}
95+
96+
}
97+
}
98+
else
99+
{
100+
byte[] bytes = Convert.FromBase64String(jsonData["document"]);
101+
stream = new MemoryStream(bytes);
102+
103+
}
104+
}
105+
string password = null;
106+
if (jsonObject != null && jsonData.ContainsKey("password"))
107+
{
108+
password = jsonData["password"];
109+
}
110+
var result = pdfviewer.Load(stream, password);
111+
return Content(JsonConvert.SerializeObject(result));
112+
}
113+
63114
public Dictionary<string, string> JsonConverter(jsonObjects results)
64115
{
65116
Dictionary<string, object> resultObjects = new Dictionary<string, object>();
@@ -133,6 +184,15 @@ public ActionResult RenderPdfPages(jsonObjects jsonObject)
133184
return Content(JsonConvert.SerializeObject(jsonResult));
134185
}
135186

187+
[System.Web.Mvc.HttpPost]
188+
public ActionResult RenderPdfTexts(jsonObjects jsonObject)
189+
{
190+
PdfRenderer pdfviewer = new PdfRenderer();
191+
var jsonData = JsonConverter(jsonObject);
192+
object jsonResult = pdfviewer.GetDocumentText(jsonData);
193+
return Content(JsonConvert.SerializeObject(jsonResult));
194+
}
195+
136196
[System.Web.Mvc.HttpPost]
137197
public ActionResult Unload(jsonObjects jsonObject)
138198
{
@@ -279,5 +339,6 @@ public class jsonObjects
279339
public string isFormFieldAnnotationsExist { get; set; }
280340
public string documentLiveCount { get; set; }
281341
public string annotationDataFormat { get; set; }
342+
public string organizePages { get; set; }
282343
}
283344
}

PDFViewer/ASP.NET MVC Razor Examples/Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>@ViewBag.Title - My ASP.NET Application</title>
77
@Styles.Render("~/Content/css")
8-
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/20.3.61/fluent.css" />
9-
<script src="https://cdn.syncfusion.com/ej2/20.3.61/dist/ej2.min.js"></script>
8+
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/27.1.48/fluent.css" />
9+
<script src="https://cdn.syncfusion.com/ej2/27.1.48/dist/ej2.min.js"></script>
1010
</head>
1111
<body>
1212
<div class="navbar navbar-inverse navbar-fixed-top">

0 commit comments

Comments
 (0)