Welcome to the Blazor feedback portal. We’re happy you’re here! If you have feedback on how to improve the Blazor, we’d love to hear it!>
Thanks for joining our community and helping improve Syncfusion products!
Hello Syncfusion Team,
The pdf viewer does not load the document when it is deployed, it is always waiting. It does not throw error.
The pdf is in a shared folder on Disk S that I can access without problems.
I use blazor wasm net core 5
Attached controller and a sample image.
Please help me.
CONTROLLER (The controlled I take it from an example of you) :
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
private IWebHostEnvironment _hostingEnvironment;
//Initialize the memory cache object
public IMemoryCache _cache;
private readonly AppDbContext _context;
private readonly ILogger
public ValuesController(IWebHostEnvironment hostingEnvironment, IMemoryCache cache
, AppDbContext appContext
, ILogger
{
_hostingEnvironment = hostingEnvironment;
_cache = cache;
this._context = appContext;
this.logger = logger;
logger.LogInformation("PdfViewerController initialized");
Console.WriteLine("PdfViewerController initialized");
}
[HttpPost("Load")]
//
[Route("[controller]/Load")]
//Post action for Loading the PDF documents
public IActionResult Load([FromBody] Dictionary
{
Console.WriteLine("Load called");
logger.LogInformation("Load called");
//Initialize the PDF viewer object with memory cache object
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 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);
var result = Content(JsonConvert.SerializeObject(jsonResult));
return result;
}
//[AcceptVerbs("Post")]
//[HttpPost("Image")]
//
//[Route("[controller]/Image")]
////Post action for processing the bookmarks from the PDF documents
//public byte[] Image()
//{
// string filePath = @"S:\documents\Capture.jpeg";
// using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
// {
// using (var memoryStream = new MemoryStream())
// {
// fileStream.CopyTo(memoryStream);
// Bitmap image = new Bitmap(1, 1);
// image.Save(memoryStream, ImageFormat.Jpeg);
// byte[] byteImage = memoryStream.ToArray();
// return byteImage;
// }
// }
//}
[AcceptVerbs("Post")]
[HttpPost("Bookmarks")]
[Route("[controller]/Bookmarks")]
//Post action for processing the bookmarks from the PDF documents
public IActionResult Bookmarks([FromBody] Dictionary
{
//Initialize the PDF Viewer object with memory cache object
PdfRenderer pdfviewer = new PdfRenderer(_cache);
var jsonResult = pdfviewer.GetBookmarks(jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}
[AcceptVerbs("Post")]
[HttpPost("RenderPdfPages")]
[Route("[controller]/RenderPdfPages")]
//Post action for processing the PDF documents
public IActionResult RenderPdfPages([FromBody] Dictionary
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object jsonResult = pdfviewer.GetPage(jsonObject);
var result = JsonConvert.SerializeObject(jsonResult);
//var bytes = Encoding.UTF8.GetBytes(jsonResult.ToString());
//return File(jsonResult, "application/octet-stream");
return Content(result);
}
[AcceptVerbs("Post")]
[HttpPost("RenderThumbnailImages")]
[Route("[controller]/RenderThumbnailImages")]
//Post action for rendering the ThumbnailImages
public IActionResult RenderThumbnailImages([FromBody] Dictionary
{
//Initialize the PDF Viewer object with memory cache object
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object result = pdfviewer.GetThumbnailImages(jsonObject);
return Content(JsonConvert.SerializeObject(result));
}
[AcceptVerbs("Post")]
[HttpPost("RenderAnnotationComments")]
[Route("[controller]/RenderAnnotationComments")]
//Post action for rendering the annotations
public IActionResult RenderAnnotationComments([FromBody] Dictionary
{
//Initialize the PDF Viewer object with memory cache object
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object jsonResult = pdfviewer.GetAnnotationComments(jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}
[AcceptVerbs("Post")]
[HttpPost("ExportAnnotations")]
[Route("[controller]/ExportAnnotations")]
//Post action to export annotations
public IActionResult ExportAnnotations([FromBody] Dictionary
{
//PdfRenderer pdfviewer = new PdfRenderer(_cache);
//string jsonResult = pdfviewer.GetAnnotations(jsonObject);
return NoContent();
}
[AcceptVerbs("Post")]
[HttpPost("ImportAnnotations")]
[Route("[controller]/ImportAnnotations")]
//Post action to import annotations
public IActionResult ImportAnnotations([FromBody] Dictionary
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
string jsonResult = string.Empty;
if (jsonObject != null && jsonObject.ContainsKey("fileName"))
{
string documentPath = GetDocumentPath(jsonObject["fileName"]);
if (!string.IsNullOrEmpty(documentPath))
{
jsonResult = System.IO.File.ReadAllText(documentPath);
}
else
{
return this.Content(jsonObject["document"] + " is not found");
}
}
return Content(jsonResult);
}
[AcceptVerbs("Post")]
[HttpPost("ExportFormFields")]
[Route("[controller]/ExportFormFields")]
public IActionResult ExportFormFields([FromBody] Dictionary
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
string jsonResult = pdfviewer.ExportFormFields(jsonObject);
return Content(jsonResult);
}
[AcceptVerbs("Post")]
[HttpPost("ImportFormFields")]
[Route("[controller]/ImportFormFields")]
public IActionResult ImportFormFields([FromBody] Dictionary
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object jsonResult = pdfviewer.ImportFormFields(jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}
[AcceptVerbs("Post")]
[HttpPost("Unload")]
[Route("[controller]/Unload")]
//Post action for unloading and disposing the PDF document resources
public IActionResult Unload([FromBody] Dictionary
{
//Initialize the PDF Viewer object with memory cache object
PdfRenderer pdfviewer = new PdfRenderer(_cache);
pdfviewer.ClearCache(jsonObject);
return this.Content("Document cache is cleared");
}
[HttpPost("Download")]
[Route("[controller]/Download")]
//Post action for downloading the PDF documents
public IActionResult Download([FromBody] Dictionary
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
return Content(documentBase);
}
[HttpPost("PrintImages")]
[Route("[controller]/PrintImages")]
//Post action for printing the PDF documents
public IActionResult PrintImages([FromBody] Dictionary
{
//Initialize the PDF Viewer object with memory cache object
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object pageImage = pdfviewer.GetPrintImage(jsonObject);
return Content(JsonConvert.SerializeObject(pageImage));
}
[HttpPost("RenderPdfTexts")]
[Route("[controller]/RenderPdfTexts")]
public IActionResult RenderPdfTexts([FromBody] Dictionary
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
object result = pdfviewer.GetDocumentText(jsonObject);
return Content(JsonConvert.SerializeObject(result));
}
//Gets the path of the PDF document
private string GetDocumentPath(string document)
{
string xSQL = string.Format("select CAMPO, VALORC from Solution where CAMPO = 'RUTAOF2' OR CAMPO = 'RUTACNC' OR CAMPO = 'RUTAENSAYO' OR CAMPO = 'RUTATRAZABILIDAD' OR CAMPO = 'RUTADATOS'");
var ubicaciones = _context.Solution.FromSqlRaw(xSQL).ToList
var ubicacion = ubicaciones.Where(s => s.CAMPO == "RUTAOF2").Select(c => c.VALORC).FirstOrDefault();
string documentPath = string.Empty;
//document = "27303156459_011_00001_00000065.pdf";
if (!System.IO.File.Exists(ubicacion + "/" + document))
{
var sol = ubicaciones.Where(s => s.CAMPO == "RUTAOF2").FirstOrDefault();
//var path = _hostingEnvironment.ContentRootPath;
//string webRootPath = _hostingEnvironment.WebRootPath;
//if (System.IO.File.Exists(path + "/documentos/" + document))
// documentPath = path + "/documentos/" + document;
ubicacion = "D:\\Descargas\\";
document = "27303156459_011_00001_00000058.pdf";
if (System.IO.File.Exists(ubicacion +"/" + document))
documentPath = ubicacion + "/" + document;
}
else
{
documentPath = ubicacion + "/" + document;
}
Console.WriteLine(documentPath);
return documentPath;
}
// GET api/values
[HttpGet]
public IEnumerable
{
int size = IntPtr.Size;
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
}