first of all. Thanks a lot for the pdf viewer and the previous explanation for the zoomfactor. Thanks that explanation i can use WebApi and AspNetCore. My setup is a remote service done in WebApi ASP.net mvc and the client is asp.net core. My problem is that while i click downloading or printing the component loops.
I use an owin setup with coors enabled. My controller is the following.
using System;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Web.Http;
using Syncfusion.EJ2.PdfViewer;
using System.Net;
using System.Net.Http;
using KarveReportService.Models;
using Microsoft.Web.Http;
using System.Threading.Tasks;
using System.Web.Http.Cors;
namespace ReportService.Controllers
{
public class SpecialReportDto
{
public string Document { get; set; }
}
///
/// ReportServiceController.
///
/// [EnableCors(origins: "*", headers: "*", methods: "*")]
[RoutePrefix("api/ReportService")]
public class ReportServiceController : ApiController
{
private MemoryStream reportStream;
///
/// Load asynchronously a dictionatry.
///
///
[AllowAnonymous]
[HttpPost]
[Route("Load")]
public async Task Load([FromBody] Dictionary jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
object jsonResult = new object();
if (jsonObject != null && jsonObject.ContainsKey("document"))
{
var reportDescriptor = new ReportDescriptor(jsonObject["document"]);
var reportService = new KarveReportService.Models.ReportService();
var reportStream = await reportService.GenerateReportStreamAsync(reportDescriptor);
var desc = Path.Combine(reportDescriptor.ReportPath, reportDescriptor.ReportFileName);
jsonResult = pdfviewer.Load(reportDescriptor.OutputFileName, jsonObject);
}
return Content(HttpStatusCode.OK, JsonConvert.SerializeObject(jsonResult));
}
[HttpPost]
[Route("Bookmarks")]
public IHttpActionResult Bookmarks([FromBody] Dictionary jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
var jsonResult = pdfviewer.GetBookmarks(jsonObject);
return Content(HttpStatusCode.OK, JsonConvert.SerializeObject(jsonResult));
}
[HttpPost]
[Route("RenderPdfPages")]
public IHttpActionResult RenderPdfPages([FromBody] Dictionary jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
if (jsonObject.ContainsKey("zoomFactor"))
{
jsonObject["zoomFactor"] = "1";
}
else
{
jsonObject.Add("zoomFactor", "1");
}
var jsonResult = pdfviewer.GetPage(jsonObject);
return Content(HttpStatusCode.OK, JsonConvert.SerializeObject(jsonResult));
}
[HttpPost]
[Route("RenderThumbnailImages")]
public IHttpActionResult RenderThumbnailImages([FromBody] Dictionary jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
object result = pdfviewer.GetThumbnailImages(jsonObject);
return Content(HttpStatusCode.OK,JsonConvert.SerializeObject(result));
}
[HttpPost]
[Route("Unload")]
public IHttpActionResult Unload([FromBody] Dictionary jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
pdfviewer.ClearCache(jsonObject);
return this.Content(HttpStatusCode.OK,"Document cache is cleared");
}
[HttpPost]
[Route("Download")]
public IHttpActionResult Download([FromBody] Dictionary jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
return Content(HttpStatusCode.OK, documentBase);
}
[HttpPost]
[Route("PrintImages")]
public IHttpActionResult PrintImages([FromBody] Dictionary jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
object pageImage = pdfviewer.GetPrintImage(jsonObject);
return Content(HttpStatusCode.OK, pageImage);
}
[Route("GetPlainText")]
private HttpResponseMessage GetPlainText(string pageImage)
{
var responseText = new HttpResponseMessage(HttpStatusCode.OK);
responseText.Content = new StringContent(pageImage, System.Text.Encoding.UTF8, "text/plain");
return responseText;
}
}
}