How to view pdf from controller

Hi,

  I have a pdf viewer as follows:

  <SfPdfViewer
                     ServiceUrl="/report/viewreport"
             Height="100%" Width="100%"></SfPdfViewer>

 And my controller is like this:

  [HttpGet("viewreport")]
        public async Task<IActionResult> ViewReport()
        {
            XtraReport1 rpt = new XtraReport1();
            MemoryStream ms = new MemoryStream();
            await rpt.ExportToPdfAsync(ms);
            return new FileContentResult(ms.GetBuffer(), "application/pdf");
        }

It only displays a blank viewer, how to do it correctly?

Thank you.

9 Replies 1 reply marked as answer

MS Martin Sato replied to Martin Sato March 31, 2021 11:12 AM UTC

Hi,

  I have a pdf viewer as follows:

  <SfPdfViewer
                     ServiceUrl="/report/viewreport"
             Height="100%" Width="100%"></SfPdfViewer>

 And my controller is like this:

  [HttpGet("viewreport")]
        public async Task<IActionResult> ViewReport()
        {
            XtraReport1 rpt = new XtraReport1();
            MemoryStream ms = new MemoryStream();
            await rpt.ExportToPdfAsync(ms);
            return new FileContentResult(ms.GetBuffer(), "application/pdf");
        }

It only displays a blank viewer, how to do it correctly?

Thank you.

Hi,

 I copied some of your examples, but I receive this error:

Web-service is not listening. PDF Viewer depends on web-service for all it's features. Please start the web service to continue.



Thank you.


VS Vasugi Sivajothi Syncfusion Team March 31, 2021 11:29 AM UTC

Hi Martin, 
 
Thanks for contacting Syncfusion support. 
 
Syncfusion PDF Viewer control is both server and client-side oriented. So, we need to create the own web service and add the web service URL in the serviceUrl property of our client-side for further processing in the PDF document.  We have shared the simple sample for your reference. Please refer to the below sample and documentation steps to create the web service, 
 
 
 
 
 
Documentation:  
 
 
 
 
 
Kindly try this and revert to us with more details if the provided solution is not meet your requirement. 
 
Regards 
Vasugi 
 



MS Martin Sato replied to Vasugi Sivajothi March 31, 2021 01:23 PM UTC

Hi Martin, 
 
Thanks for contacting Syncfusion support. 
 
Syncfusion PDF Viewer control is both server and client-side oriented. So, we need to create the own web service and add the web service URL in the serviceUrl property of our client-side for further processing in the PDF document.  We have shared the simple sample for your reference. Please refer to the below sample and documentation steps to create the web service, 
 
 
 
 
 
Documentation:  
 
 
 
 
 
Kindly try this and revert to us with more details if the provided solution is not meet your requirement. 
 
Regards 
Vasugi 
 


Please see my sample project, it's not working. 

Thank you.

Attachment: PDFVIEWERSAMPLE_a8f9f2eb.rar


VS Vasugi Sivajothi Syncfusion Team April 1, 2021 12:28 PM UTC

Hi Martin, 
 
Thanks for the update. 
 
We have analyzed the code in the provided sample, we suspect that the reported issue occurs due to not enabling the CORS in your sample. So kindly add the below code in the startup.cs file with in (Configure) method. In our PDFViewerController.cs file, we have provided the code ([Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]) before all our action method. So that the reported issue occurs in your end. 
  
app.UseCors(); 
  
We have modified the provided sample. Please refer to the below link, 
 
Kindly try this and revert to us with more details if you still have concerns about this. 
 
Regards, 
Vasugi 


Marked as answer

MS Martin Sato replied to Vasugi Sivajothi April 2, 2021 02:15 AM UTC

Hi Martin, 
 
Thanks for the update. 
 
We have analyzed the code in the provided sample, we suspect that the reported issue occurs due to not enabling the CORS in your sample. So kindly add the below code in the startup.cs file with in (Configure) method. In our PDFViewerController.cs file, we have provided the code ([Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]) before all our action method. So that the reported issue occurs in your end. 
  
app.UseCors(); 
  
We have modified the provided sample. Please refer to the below link, 
 
Kindly try this and revert to us with more details if you still have concerns about this. 
 
Regards, 
Vasugi 


It is working now, is possible to let the pdf viewer occupy the whole div? 

Thanks.


DM Dhivyabharathi Mohan Syncfusion Team April 2, 2021 10:40 AM UTC

Hi Martin, 
 
We have modified the sample by creating our PDF Viewer inside the div element by occupying the whole div. And we have shared the sample. Kindly download the sample from the below link, 
 
 
 
Kindly try it and revert us, if you have any concerns about this. 
 
Regards, 
Dhivya.  



MS Martin Sato replied to Dhivyabharathi Mohan April 2, 2021 12:20 PM UTC

Hi Martin, 
 
We have modified the sample by creating our PDF Viewer inside the div element by occupying the whole div. And we have shared the sample. Kindly download the sample from the below link, 
 
 
 
Kindly try it and revert us, if you have any concerns about this. 
 
Regards, 
Dhivya.  


Thank you very much for your quick response. It's working now.

I have another question, how to pass extra parameter to service like I want to send an ID.

Also, I want to show a loader while the pdfviewer is not shown yet to client, I used sfspinner, but it won't stop spinning even if I call HideAsync.



Thank you.


VS Vasugi Sivajothi Syncfusion Team April 5, 2021 12:10 PM UTC

Hi Martin,  
 
Thank you for your update. 
 
Please find the details, 
 
Query 
Details 
Thank you very much for your quick response. It's working now. 
 
I have another question, how to pass extra parameter to service like I want to send an ID. 
 
 
Currently, we do not have support to pass extra parameter to service in blazor. However, we will analyze further on this and update you with more details on April 8, 2021. 
 
Also, I want to show a loader while the pdfviewer is not shown yet to client, I used sfspinner, but it won't stop spinning even if I call HideAsync. 
 
We can hide or show spinner using VisibleProperty. Please refer to the below documentation, 
 
 
Kindly try this and let us know if you have any concerns about this. 
 
 
Regards, 
Vasugi 



VS Vasugi Sivajothi Syncfusion Team April 8, 2021 04:49 PM UTC

Hi Martin,   
 
As we mentioned earlier, we do not have support to pass extra parameter to service in blazor. We have added it to our feature request list. But we don’t have any immediate plans to implement this feature. At the planning stage for every release cycle, we review all open features. We will implement this feature in any of our upcoming releases.             
     
Now, you can track the status through the below link.           
     
 
 
Regards, 
Vasugi 


Loader.
Up arrow icon