using Newtonsoft.Json;
using Syncfusion.EJ;
using Syncfusion.EJ.PdfViewer;
using Syncfusion.Pdf.Parsing;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
namespace hive
{
public class PdfViewerController : ApiController
{
PdfViewerHelper helper = new PdfViewerHelper();
public object Load(Dictionary<string, string> jsonResult)
{
//load the multiple document from client side
if (jsonResult.ContainsKey("newFileName"))
{
var name = jsonResult["newFileName"];
var pdfName = name.ToString();
helper.Load(HttpContext.Current.Server.MapPath("~/Data/" + pdfName));
}
else
{
if (jsonResult.ContainsKey("isInitialLoading"))
{
if (jsonResult.ContainsKey("file"))
{
var name = jsonResult["file"];
helper.Load(name);
}
else
{
helper.Load(HttpContext.Current.Server.MapPath("~/Data/theform.pdf"));
}
}
}
string output = JsonConvert.SerializeObject(helper.ProcessPdf(jsonResult));
return output;
}
public object FileUpload(Dictionary<string, string> jsonResult)
{
if (jsonResult.ContainsKey("uploadedFile"))
{
var fileurl = jsonResult["uploadedFile"];
byte[] byteArray = Convert.FromBase64String(fileurl);
MemoryStream stream = new MemoryStream(byteArray);
helper.Load(stream);
}
string output = JsonConvert.SerializeObject(helper.ProcessPdf(jsonResult));
return output;
}
public object Download(Dictionary<string, string> jsonResult)
{
var newdata = helper.GetDocumentData(jsonResult);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(helper.DocumentStream);
PdfLoadedForm loadedForm = loadedDocument.Form;
if (loadedForm != null)
{
DirectoryInfo dtInfo = new DirectoryInfo(HttpContext.Current.Request.PhysicalApplicationPath);
if (!Directory.Exists(dtInfo + "/output"))
Directory.CreateDirectory(dtInfo + "/output");
loadedDocument.Save(dtInfo + "/output/FormDocument.pdf");
loadedDocument.Close(true);
}
return null;
}
}
}
[ WebFormView.aspx ]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormView.aspx.cs" Inherits="hive.WebFormView" %>
<%@ Register Assembly="Syncfusion.EJ.Web" Namespace="Syncfusion.JavaScript.Web" TagPrefix="ej" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src='<%= Page.ResolveClientUrl("~/Scripts/jquery-1.11.1.min.js")%>' type="text/javascript"></script>
<script src='<%= Page.ResolveClientUrl("~/Scripts/jquery.easing-1.3.min.js")%>' type="text/javascript"></script>
<script src='<%= Page.ResolveClientUrl("~/Scripts/ej/web/ej.web.all.min.js")%>' type="text/javascript"></script>
<link rel='nofollow' href="Content/ej/flat-hive/ej.web.all.min.css" rel="stylesheet" type="text/css"/>
<script src='<%= Page.ResolveClientUrl("~/Scripts/ej/common/jquery.globalize.min.js")%>' type="text/javascript"></script>
<script src='<%= Page.ResolveClientUrl("~/Scripts/jsrender.min.js")%>' type="text/javascript"></script>
<script src='<%= Page.ResolveClientUrl("~/Scripts/ej/common/ej.webform.min.js")%>' type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<ej:pdfviewer id="PdfViewer1" runat="server" serviceurl="../api/PdfViewer"></ej:pdfviewer>
</div>
</form>
</body>
</html>
[ Global.asax.cs ]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using System.Web.Http;
using System.Web.SessionState;
namespace hive
{
public class Global : HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
System.Web.Http.GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional });
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
}
}