Skip to content

Commit c181196

Browse files
993766: Redaction Annotation Samples
1 parent 8321d9f commit c181196

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3478
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Web;
2+
using System.Web.Optimization;
3+
4+
namespace MvcSample
5+
{
6+
public class BundleConfig
7+
{
8+
// For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862
9+
public static void RegisterBundles(BundleCollection bundles)
10+
{
11+
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
12+
"~/Scripts/jquery-{version}.js"));
13+
14+
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
15+
"~/Scripts/jquery.validate*"));
16+
17+
// Use the development version of Modernizr to develop with and learn from. Then, when you're
18+
// ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
19+
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
20+
"~/Scripts/modernizr-*"));
21+
22+
bundles.Add(new Bundle("~/bundles/bootstrap").Include(
23+
"~/Scripts/bootstrap.js"));
24+
25+
bundles.Add(new StyleBundle("~/Content/css").Include(
26+
"~/Content/bootstrap.css",
27+
"~/Content/site.css"));
28+
}
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Web;
2+
using System.Web.Mvc;
3+
4+
namespace MvcSample
5+
{
6+
public class FilterConfig
7+
{
8+
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
9+
{
10+
filters.Add(new HandleErrorAttribute());
11+
}
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using System.Web.Routing;
7+
8+
namespace MvcSample
9+
{
10+
public class RouteConfig
11+
{
12+
public static void RegisterRoutes(RouteCollection routes)
13+
{
14+
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
15+
16+
routes.MapRoute(
17+
name: "Default",
18+
url: "{controller}/{action}/{id}",
19+
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
20+
);
21+
}
22+
}
23+
}
Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
using Newtonsoft.Json;
2+
using Syncfusion.EJ2.PdfViewer;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Net.Http;
8+
using System.Net;
9+
using System.Reflection;
10+
using System.Web;
11+
using System.Web.Mvc;
12+
13+
namespace MvcSample.Controllers
14+
{
15+
public class HomeController : Controller
16+
{
17+
[System.Web.Mvc.HttpPost]
18+
public ActionResult Load(jsonObjects jsonObject)
19+
{
20+
PdfRenderer pdfviewer = new PdfRenderer();
21+
MemoryStream stream = new MemoryStream();
22+
var jsonData = JsonConverter(jsonObject);
23+
object jsonResult = new object();
24+
if (jsonObject != null && jsonData.ContainsKey("document"))
25+
{
26+
if (bool.Parse(jsonData["isFileName"]))
27+
{
28+
string documentPath = GetDocumentPath(jsonData["document"]);
29+
30+
if (!string.IsNullOrEmpty(documentPath))
31+
{
32+
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
33+
stream = new MemoryStream(bytes);
34+
}
35+
else
36+
{
37+
string fileName = jsonData["document"].Split(new string[] { "://" }, StringSplitOptions.None)[0];
38+
if (fileName == "http" || fileName == "https")
39+
{
40+
var WebClient = new WebClient();
41+
byte[] pdfDoc = WebClient.DownloadData(jsonData["document"]);
42+
stream = new MemoryStream(pdfDoc);
43+
}
44+
else
45+
{
46+
return this.Content(jsonData["document"] + " is not found");
47+
}
48+
}
49+
}
50+
else
51+
{
52+
byte[] bytes = Convert.FromBase64String(jsonData["document"]);
53+
stream = new MemoryStream(bytes);
54+
55+
}
56+
}
57+
jsonResult = pdfviewer.Load(stream, jsonData);
58+
return Content(JsonConvert.SerializeObject(jsonResult));
59+
}
60+
61+
public Dictionary<string, string> JsonConverter(jsonObjects results)
62+
{
63+
Dictionary<string, object> resultObjects = new Dictionary<string, object>();
64+
resultObjects = results.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
65+
.ToDictionary(prop => prop.Name, prop => prop.GetValue(results, null));
66+
var emptyObjects = (from kv in resultObjects
67+
where kv.Value != null
68+
select kv).ToDictionary(kv => kv.Key, kv => kv.Value);
69+
Dictionary<string, string> jsonResult = emptyObjects.ToDictionary(k => k.Key, k => k.Value.ToString());
70+
return jsonResult;
71+
}
72+
73+
[System.Web.Mvc.HttpPost]
74+
public ActionResult ExportAnnotations(jsonObjects jsonObject)
75+
{
76+
PdfRenderer pdfviewer = new PdfRenderer();
77+
var jsonData = JsonConverter(jsonObject);
78+
string jsonResult = pdfviewer.ExportAnnotation(jsonData);
79+
return Content((jsonResult));
80+
}
81+
82+
[System.Web.Mvc.HttpPost]
83+
public ActionResult ImportAnnotations(jsonObjects jsonObject)
84+
{
85+
PdfRenderer pdfviewer = new PdfRenderer();
86+
string jsonResult = string.Empty;
87+
var jsonData = JsonConverter(jsonObject);
88+
if (jsonObject != null && jsonData.ContainsKey("fileName"))
89+
{
90+
string documentPath = GetDocumentPath(jsonData["fileName"]);
91+
if (!string.IsNullOrEmpty(documentPath))
92+
{
93+
jsonResult = System.IO.File.ReadAllText(documentPath);
94+
}
95+
else
96+
{
97+
return this.Content(jsonData["document"] + " is not found");
98+
}
99+
}
100+
return Content(JsonConvert.SerializeObject(jsonResult));
101+
}
102+
103+
[System.Web.Mvc.HttpPost]
104+
public ActionResult RenderPdfTexts(jsonObjects jsonObject)
105+
{
106+
PdfRenderer pdfviewer = new PdfRenderer();
107+
var jsonData = JsonConverter(jsonObject);
108+
object jsonResult = pdfviewer.GetDocumentText(jsonData);
109+
return Content(JsonConvert.SerializeObject(jsonResult));
110+
}
111+
112+
[System.Web.Mvc.HttpPost]
113+
public ActionResult ImportFormFields(jsonObjects jsonObject)
114+
{
115+
PdfRenderer pdfviewer = new PdfRenderer();
116+
var jsonData = JsonConverter(jsonObject);
117+
object jsonResult = pdfviewer.ImportFormFields(jsonData);
118+
return Content(JsonConvert.SerializeObject(jsonResult));
119+
}
120+
121+
[System.Web.Mvc.HttpPost]
122+
public ActionResult ExportFormFields(jsonObjects jsonObject)
123+
{
124+
PdfRenderer pdfviewer = new PdfRenderer();
125+
var jsonData = JsonConverter(jsonObject);
126+
string jsonResult = pdfviewer.ExportFormFields(jsonData);
127+
return Content(jsonResult);
128+
}
129+
130+
[System.Web.Mvc.HttpPost]
131+
public ActionResult RenderPdfPages(jsonObjects jsonObject)
132+
{
133+
PdfRenderer pdfviewer = new PdfRenderer();
134+
var jsonData = JsonConverter(jsonObject);
135+
object jsonResult = pdfviewer.GetPage(jsonData);
136+
return Content(JsonConvert.SerializeObject(jsonResult));
137+
}
138+
139+
[System.Web.Mvc.HttpPost]
140+
public ActionResult Unload(jsonObjects jsonObject)
141+
{
142+
PdfRenderer pdfviewer = new PdfRenderer();
143+
var jsonData = JsonConverter(jsonObject);
144+
pdfviewer.ClearCache(jsonData);
145+
return this.Content("Document cache is cleared");
146+
}
147+
148+
[System.Web.Mvc.HttpPost]
149+
public ActionResult RenderThumbnailImages(jsonObjects jsonObject)
150+
{
151+
PdfRenderer pdfviewer = new PdfRenderer();
152+
var jsonData = JsonConverter(jsonObject);
153+
object result = pdfviewer.GetThumbnailImages(jsonData);
154+
return Content(JsonConvert.SerializeObject(result));
155+
}
156+
157+
[System.Web.Mvc.HttpPost]
158+
public ActionResult Bookmarks(jsonObjects jsonObject)
159+
{
160+
PdfRenderer pdfviewer = new PdfRenderer();
161+
var jsonData = JsonConverter(jsonObject);
162+
object jsonResult = pdfviewer.GetBookmarks(jsonData);
163+
return Content(JsonConvert.SerializeObject(jsonResult));
164+
}
165+
166+
[System.Web.Mvc.HttpPost]
167+
public ActionResult RenderAnnotationComments(jsonObjects jsonObject)
168+
{
169+
PdfRenderer pdfviewer = new PdfRenderer();
170+
var jsonData = JsonConverter(jsonObject);
171+
object jsonResult = pdfviewer.GetAnnotationComments(jsonData);
172+
return Content(JsonConvert.SerializeObject(jsonResult));
173+
}
174+
175+
[System.Web.Mvc.HttpPost]
176+
public ActionResult Download(jsonObjects jsonObject)
177+
{
178+
PdfRenderer pdfviewer = new PdfRenderer();
179+
var jsonData = JsonConverter(jsonObject);
180+
string documentBase = pdfviewer.GetDocumentAsBase64(jsonData);
181+
return Content(documentBase);
182+
}
183+
184+
[System.Web.Mvc.HttpPost]
185+
public ActionResult PrintImages(jsonObjects jsonObject)
186+
{
187+
PdfRenderer pdfviewer = new PdfRenderer();
188+
var jsonData = JsonConverter(jsonObject);
189+
object pageImage = pdfviewer.GetPrintImage(jsonData);
190+
return Content(JsonConvert.SerializeObject(pageImage));
191+
}
192+
193+
private HttpResponseMessage GetPlainText(string pageImage)
194+
{
195+
var responseText = new HttpResponseMessage(HttpStatusCode.OK);
196+
responseText.Content = new StringContent(pageImage, System.Text.Encoding.UTF8, "text/plain");
197+
return responseText;
198+
}
199+
200+
private string GetDocumentPath(string document)
201+
{
202+
string documentPath = string.Empty;
203+
if (!System.IO.File.Exists(document))
204+
{
205+
var path = HttpContext.Request.PhysicalApplicationPath;
206+
if (System.IO.File.Exists(path + "App_Data\\" + document))
207+
documentPath = path + "App_Data\\" + document;
208+
}
209+
else
210+
{
211+
documentPath = document;
212+
}
213+
return documentPath;
214+
}
215+
216+
public ActionResult Index()
217+
{
218+
return View();
219+
}
220+
221+
public ActionResult About()
222+
{
223+
ViewBag.Message = "Your application description page.";
224+
return View();
225+
}
226+
227+
public ActionResult Contact()
228+
{
229+
ViewBag.Message = "Your contact page.";
230+
return View();
231+
}
232+
}
233+
234+
public class jsonObjects
235+
{
236+
public string document { get; set; }
237+
public string password { get; set; }
238+
public bool isClientsideLoading { get; set; }
239+
public string organizePages { get; set; }
240+
public string zoomFactor { get; set; }
241+
public string isFileName { get; set; }
242+
public string xCoordinate { get; set; }
243+
public string yCoordinate { get; set; }
244+
public string pageNumber { get; set; }
245+
public string documentId { get; set; }
246+
public string hashId { get; set; }
247+
public string sizeX { get; set; }
248+
public string sizeY { get; set; }
249+
public string startPage { get; set; }
250+
public string endPage { get; set; }
251+
public string stampAnnotations { get; set; }
252+
public string textMarkupAnnotations { get; set; }
253+
public string stickyNotesAnnotation { get; set; }
254+
public string shapeAnnotations { get; set; }
255+
public string measureShapeAnnotations { get; set; }
256+
public string action { get; set; }
257+
public string pageStartIndex { get; set; }
258+
public string pageEndIndex { get; set; }
259+
public string fileName { get; set; }
260+
public string elementId { get; set; }
261+
public string pdfAnnotation { get; set; }
262+
public string importPageList { get; set; }
263+
public string uniqueId { get; set; }
264+
public string data { get; set; }
265+
public string viewPortWidth { get; set; }
266+
public string viewportHeight { get; set; }
267+
public string tilecount { get; set; }
268+
public bool isCompletePageSizeNotReceived { get; set; }
269+
public string freeTextAnnotation { get; set; }
270+
public string signatureData { get; set; }
271+
public string fieldsData { get; set; }
272+
public string formDesigner { get; set; }
273+
public bool isSignatureEdited { get; set; }
274+
public string inkSignatureData { get; set; }
275+
public bool hideEmptyDigitalSignatureFields { get; set; }
276+
public bool showDigitalSignatureAppearance { get; set; }
277+
public bool digitalSignaturePresent { get; set; }
278+
public string tileXCount { get; set; }
279+
public string tileYCount { get; set; }
280+
public string digitalSignaturePageList { get; set; }
281+
public string annotationCollection { get; set; }
282+
public string annotationsPageList { get; set; }
283+
public string formFieldsPageList { get; set; }
284+
public bool isAnnotationsExist { get; set; }
285+
public bool isFormFieldAnnotationsExist { get; set; }
286+
public string documentLiveCount { get; set; }
287+
public string annotationDataFormat { get; set; }
288+
}
289+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%@ Application Codebehind="Global.asax.cs" Inherits="MvcSample.MvcApplication" Language="C#" %>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using System.Web.Optimization;
7+
using System.Web.Routing;
8+
9+
namespace MvcSample
10+
{
11+
public class MvcApplication : System.Web.HttpApplication
12+
{
13+
protected void Application_Start()
14+
{
15+
AreaRegistration.RegisterAllAreas();
16+
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
17+
RouteConfig.RegisterRoutes(RouteTable.Routes);
18+
BundleConfig.RegisterBundles(BundleTable.Bundles);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)