PDF Viewer web service is not working

the pdf viwer js not working corectly i can't get the pdf file from the data on the web service


i don't know the reason why when i tried it with your web server work's

import { PdfViewerToolbarMagnificationNavigationLinkAnnotation,ThumbnailView,BookmarkView,
    TextSelectionAnnotationfrom '@syncfusion/ej2-pdfviewer';

PdfViewer.Inject(Toolbar,Magnification,NavigationLinkAnnotation,ThumbnailView,BookmarkView,
    TextSelectionAnnotation);


let pdfviewerPdfViewer = new PdfViewer();
pdfviewer.serviceUrl = "http://localhost:1454/api/pdfviewer";
//pdfviewer.serviceUrl = "https://ej2services.syncfusion.com/production/web-services/api/pdfviewer";
// pdfviewer.enableAllModules();
pdfviewer.appendTo('#PdfViewer');
pdfviewer.load('test.pdf'null);
//pdfviewer.load('PDF_Succinctly.pdf', null);

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

using Newtonsoft.Json;
using Syncfusion.EJ2.PdfViewer;
using System.IO;
using System.Web;
using System.Web.Http.Cors;

namespace pdfviwer_service.Controllers
{
[EnableCorsAttribute("*","*","*")]
public class PdfViewerController : ApiController
{
[HttpPost]
public object Load(Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
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 MemoryStream(bytes);
}
else
{
return (jsonObject["document"] + " is not found");
}
}
else
{
byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
stream = new MemoryStream(bytes);
}
}
jsonResult = pdfviewer.Load(stream, jsonObject);
return (JsonConvert.SerializeObject(jsonResult));
}





[HttpPost]
public object Bookmarks(Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
var jsonResult = pdfviewer.GetBookmarks(jsonObject);
return (JsonConvert.SerializeObject(jsonResult));
}
[HttpPost]
public object RenderPdfPages(Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
object jsonResult = pdfviewer.GetPage(jsonObject);
return (JsonConvert.SerializeObject(jsonResult));
}
[HttpPost]
public object RenderThumbnailImages(Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
object result = pdfviewer.GetThumbnailImages(jsonObject);
return (JsonConvert.SerializeObject(result));
}
[HttpPost]
public object Unload(Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
pdfviewer.ClearCache(jsonObject);
return ("Document cache is cleared");
}
[HttpPost]
public HttpResponseMessage Download(Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
return (GetPlainText(documentBase));
}
[HttpPost]
public object PrintImages(Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer();
object pageImage = pdfviewer.GetPrintImage(jsonObject);
return (JsonConvert.SerializeObject(pageImage));
}
private HttpResponseMessage GetPlainText(string pageImage)
{
var responseText = new HttpResponseMessage(HttpStatusCode.OK);
responseText.Content = new StringContent(pageImage, System.Text.Encoding.UTF8, "text/plain");
return responseText;
}

// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}




private string GetDocumentPath(string document)
{
string documentPath = string.Empty;
if (!System.IO.File.Exists(document))
{
var path = HttpContext.Current.Request.PhysicalApplicationPath;
if (System.IO.File.Exists(path + "App_Data\\Data\\" + document))
documentPath = path + "App_Data\\Data\\" + document;
}
else
{
documentPath = document;
}
return documentPath;
}

}
}


1 Reply

DM Dhivyabharathi Mohan Syncfusion Team February 9, 2021 10:35 AM UTC

Hi Youssef, 
  
 
We are unable to reproduce the reported issue with the code snippet you have shared. The sample which we tried is shared below.  
 
  
 
MVC Web service: 
  
 
Kindly refer to the sample and let us know if it works fine at your end. You can also modify the sample to reproduce the issue and send us back. It will be helpful for us to investigate further and provide details. 
 
Regards,
Dhivya.
 
  


Loader.
Up arrow icon