Get PDF report programmatically in React

1 Answer 56 Views
Report Viewer - HTML5
Haseeb
Top achievements
Rank 1
Haseeb asked on 18 Oct 2024, 06:18 PM | edited on 18 Oct 2024, 06:31 PM

Hi

Using telerik report in react, showing report in Report Viewer and all fine.

Now need to get the PDF (inline, not download) of this report from Report Viewer programmatically. (Not in backend). Is there is a way to get the PDF.

I can download PDF using viewer.current.commands.export.exec("PDF"); but i need to get pdf contents. (need to upload to azure blob)

 

Also when we export PDF manually, ReportViewer calls the CreateDocument endpoint  [HttpPost("clients/{clientID}/instances/{instanceID}/documents")] 

to get the document id. and then uses clientid, instanceid and documentid to get pdf.

In react how can we get the client id and instanceid from Report Viewer.

Thanks

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Dimitar
Telerik team
answered on 23 Oct 2024, 12:22 PM

Hello Haseeb,

Thank you for the provided information about the scenario!

The Telerik reports are rendered on the server and thus to get the PDF result of a report programmatically, the easiest approach would be to add a new endpoint on the server which you may call in React application APis like fetch, axios, etc.

You may have a look at the Exporting a report to PDF programmatically - Telerik Reporting KB article for an example of how to do this.

Additionally, you mentioned in the latter half of the post, that the report may be exported from the report viewer as well. In this case, you may listen for the exportEnd(e, args) event which will contain the URL of the exported document as a resource in the args parameter each time someone exports from the report viewer.

I hope that the provided information will help.

Regards,
Dimitar
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Haseeb
Top achievements
Rank 1
commented on 23 Oct 2024, 06:26 PM

Thanks,
I am getting URL from exportEnd(e, args) to get URL and its solved my issue. (I was trying to get PDF of already generated instance).

It would be great to have functionality to get the clientID and InstanceId from TelerikReportViewer component.



Tags
Report Viewer - HTML5
Asked by
Haseeb
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or