Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate PDF output of powerbi embedded report

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.

like image 530
Eray Balkanli Avatar asked Mar 07 '19 20:03

Eray Balkanli


2 Answers

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

like image 143
Krzysztof Krysztofczyk Avatar answered Nov 14 '22 14:11

Krzysztof Krysztofczyk


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.

like image 1
pragyy Avatar answered Nov 14 '22 12:11

pragyy