Automate export from Power BI file to PDF
I have a power BI report that uses SQL server and python script as the data sources. I need to export this to PDF and send it out on a daily basis to a few selected people.
Is there a way to do the following using python:
- Open the Power BI desktop file
- Hit the "Refresh" button to refresh the datasets
- Click on the "Export to PDF" option
- Mail the exported PDF to a group of people
I know that something similar can be achieved using Power BI Service but when I published the power BI report and installed a personal gateway, I got the following error:
I had installed the personal mode gateway and entered my email address but when I opened the gateway again, it asks me to sign in every time (I'm not sure if this is normal.)
Solution 1:
The gateway is fine as long as you have it set as "Running" in your dataset settings, once you login, you don't have to open it again:
For exporting the Power Bi report as PDF, there is an API dedicated to that https://docs.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file The drawback is that you need Power BI Premium to use it.
In case you had the Premium, then you could send a Post request using Python's module "Requests" to extract the pdf using that report's ID.