microsoft / powerbi-client-react

Power BI for React which provides components and services to enabling developers to easily embed Power BI reports into their applications.
MIT License
310 stars 98 forks source link

Not able to export(visible) in PNG/PDF/PPTX from external libraries. #87

Closed Sushmasrig closed 1 year ago

Sushmasrig commented 1 year ago

Power Bi react client has internal export functionalities, but for my use case, I want to use external export(Pdf/png/pptx) instead of internal. I used third-party libraries to export, everything is rendering correctly except the power bi client component. I am attaching the link for reference: https://stackblitz.com/edit/react-nyqusc?file=src%2FApp.js

"html-to-image": "^1.11.11",
"jspdf": "^2.5.1",
"powerbi-client": "^2.19.1",
"powerbi-client-react": "1.3.3",
"powerbi-report-authoring": "1.1.3",
"react": "17.0.2",
"react-dom": "17.0.2"

Node version: v14.18.1

I also used other Pdf libraries but still power bi client component is not able to export(visible) in pdf and png.

KotanaSai21 commented 1 year ago

Microsoft recommends using Export To File API for exporting PowerBI Report.

Export To File REST API helps us to export the report. Refer Export Power BI embedded analytics reports API documentation.

We also have ani API report.print() this method prints only the active page of report invoking windows.print() on embedded iframe component.

Feel Free to reach out if you have any other queries.

Sushmasrig commented 1 year ago

Thank you for sharing this information. report. print() is working fine for me.

Sushmasrig commented 1 year ago

I have checked the documentation for .pptx and .png but it will be helpful if there is any working example or any sample code for reference.

KotanaSai21 commented 1 year ago

From the documentation, export job consists of four steps.

  1. Sending an Export request - Make a REST API call to get the exportId ( ExportToFile or ExportToFileInGroup)
  2. Polling - Make a call to identify whether the report is ready to download. ( GetExportToFileStatus or GetExportToFileStatusInGroup )
  3. Getting the File - From polling, you get to know the export state. Once Export state is succeeded, make a call to get the file. (GetFileof ExportToFile or GetFileofExportToFileInGroup)
  4. Once you get the file stream, download the file.

Refer to this Export PowerBI Embedded Report using Export To File APIs gist file for sample running code.

Feel free to reach out if you have any other queries.

Sushmasrig commented 1 year ago

I tried as you mentioned in your code URL: https://api.powerbi.com/v1.0/myorg/reports/{myReportId}/ExportTo. Payload: {"format":"PPTX","powerBIReportConfiguration":{}}
Http Error: 403. I even checked my accessToken and reportId are being passed correctly but still getting 403 error.

KotanaSai21 commented 1 year ago

@Sushmasrig ,

To use ExportToFile API, reports must reside in Premium or Embedded Capacity. Refer to Limitations documentation and verify.