8

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.

Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
  • Please use this below answer for print the embeded report from web application, https://stackoverflow.com/questions/54460823/download-print-option-in-powerbi-embedded-report-with-angular7/55687031#55687031 This solution has been implemented in my application. Also i am looking for an export as PDF option in this embedded report but still not get any solution. – Poopandian May 06 '19 at 06:16
  • What version of the PowerBI JavaScript library are you using? – vvvv4d Jul 17 '19 at 18:54
  • Well, I think it was 2.7.3 @vvvv4d – Eray Balkanli Jul 17 '19 at 20:30
  • Is it possible for you to try and upgrade to 2.7.5? I am using 2.7.5 and report.print() triggers printing to occur after you've run powerbi.embed(reportContainer, config); – vvvv4d Jul 18 '19 at 14:58
  • Well, currently it is not possible for me to work on Power BI as it is a commercial product and I changed my company, my new company does not use power-bi. sorry @vvvv4d – Eray Balkanli Jul 19 '19 at 17:24
  • Here is a Chrome extension to do exactly same: https://github.com/OmSao/PowerBI_Visual_Print_Utility – Om Sao Apr 11 '20 at 19:39

3 Answers3

2

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

2

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.

pragyy
  • 96
  • 7
0

I solved this by dynamically rendering all pages in the report as individual iframes, then using css print media queries to format the iframes as print friendly pages. The user can then simply save the browser print preview as PDF.

Although rendering multiple iframes is heavy stuff and not recommended perfomance-wise it is still faster than the built in Power BI PDF export and more customizable!

Jonas Littau
  • 167
  • 2
  • 10