I have a powerbi report embedded to my webpage. What I need is to add an "export" button to my page and export the report to the PDF when the button is clicked. How can I achieve this? People online advises using report.print()
or window.print()
, but both did not work for me.
var reportContainer = document.getElementById('reportContainer');
var report = powerbi.embed(reportContainer, config);
var report2 = powerbi.get(reportContainer);
console.log(report); --returns the report
console.log(report2); --also returns the report
report.print(); --nothing happens
report2.print(); --nothing happens
var saveAsParameters = {
name: "newReport"
};
report2.saveAs(saveAsParameters); --nothing happens report.saveas also nothing happens
window.print(); --it prints a blank page.
I found this but did not help: Print/Generate PDF of embedded power bi report
Please note that I know I can export the report to pdf via PowerBI Desktop but I need to do it on my custom web page.
Any help would be so appreciated.
Looks like, soon that will be available as part of API (After Feb 2020).
https://learn.microsoft.com/en-us/power-platform-release-plan/2019wave2/business-intelligence/api-export-report-powerpoint-pdf-jpeg
Developers will be able to provide their users with the option to export their data in PowerPoint, PDF, and JPEG formats in two main scenarios:
Interactive mode: End users interact with a report and export their own view of the data.
Non-interactive mode: Offline generation of snapshots distributed to different people in the organization.The following capabilities will be supported:
Export report for both Power BI and non-Power BI users (SaaS and PaaS embed scenarios)
Export user context (the screenshot will include applied filters, cross filters, etc.)
Export including row-Level security (RLS)
Export a single page or entire report
You can provide your consumers to print the report. Whenever you print there is an option to download as a pdf. So you can attack the problem by method of print.
This can be easily achieved by using Power BI Javascript APIs.
First create an HTML button, which will allow the user to click to Print their report.
<button id="theClick" onclick="print()">Print</button>
Once you have your button, then add the javascript for it.
function print() {
var element = $('#report-container')[0];
var report = powerbi.get(element);
report.print();
}
For more information, you can read the official documentation by Microsoft: https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/embedding-basic-interactions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With