9

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.

6
  • Please use this below answer for print the embeded report from web application, stackoverflow.com/questions/54460823/… 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. Commented May 6, 2019 at 6:16
  • What version of the PowerBI JavaScript library are you using? Commented Jul 17, 2019 at 18:54
  • Well, I think it was 2.7.3 @vvvv4d Commented Jul 17, 2019 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); Commented Jul 18, 2019 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 Commented Jul 19, 2019 at 17:24

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

True. On 2/2/2021 print is working as part of API ;)
3

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.

1 Comment

Thank you praggy, it's works! Do you have any idea how I can export the complete report?
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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.