Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
147020 | Aug 29,2019 01:45 AM UTC | Sep 6,2019 04:58 AM UTC | ASP.NET Core - EJ 2 | 8 |
![]() |
Tags: PDF Viewer |
private readonly IHostingEnvironment _hostingEnvironment;
private IMemoryCache _cache;
public PdfViewerController(IHostingEnvironment hostingEnvironment, IMemoryCache cache)
{
_hostingEnvironment = hostingEnvironment;
_cache = cache;
}
[AcceptVerbs("Post")]
[HttpPost]
[Route("api/[controller]/Load")]
public IActionResult Upload([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
MemoryStream stream = new MemoryStream();
object jsonResult = new object();
if (jsonObject != null && jsonObject.ContainsKey("document"))
{
if (bool.Parse(jsonObject["isFileName"]))
{
string documentPath = GetDocumentPath(jsonObject["document"]);
if (!string.IsNullOrEmpty(documentPath))
{
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
//_stream = new FileStream(documentPath, FileMode.OpenOrCreate);
stream = new MemoryStream(bytes);
}
else
{
return this.Content(jsonObject["document"] + " is not found");
}
}
else
{
byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
stream = new MemoryStream(bytes);
}
}
jsonResult = pdfviewer.Load(stream, jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}
[AcceptVerbs("Post")]
[HttpPost]
[Route("api/[controller]/RenderPdfPages")]
public IActionResult RenderPdfPages([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object jsonResult = pdfviewer.GetPage(jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}
[AcceptVerbs("Post")]
[HttpPost]
[Route("api/[controller]/RenderAnnotationComments")]
public IActionResult RenderAnnotationComments([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object jsonResult = pdfviewer.GetAnnotationComments(jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}
[AcceptVerbs("Post")]
[HttpPost]
[Route("api/[controller]/Unload")]
public IActionResult Unload([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
pdfviewer.ClearCache(jsonObject);
return this.Content("Document cache is cleared");
}
[AcceptVerbs("Post")]
[HttpPost]
[Route("api/[controller]/RenderThumbnailImages")]
public IActionResult RenderThumbnailImages([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object result = pdfviewer.GetThumbnailImages(jsonObject);
return Content(JsonConvert.SerializeObject(result));
}
[AcceptVerbs("Post")]
[HttpPost]
[Route("api/[controller]/Bookmarks")]
public IActionResult Bookmarks([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object jsonResult = pdfviewer.GetBookmarks(jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}
[AcceptVerbs("Post")]
[HttpPost]
[Route("api/[controller]/Download")]
public IActionResult Download([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
return Content(documentBase);
}
[AcceptVerbs("Post")]
[HttpPost]
[Route("api/[controller]/PrintImages")]
public IActionResult PrintImages([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object pageImage = pdfviewer.GetPrintImage(jsonObject);
return Content(JsonConvert.SerializeObject(pageImage));
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.