Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
pej
Regular Visitor

Exporting report to PDF using REST API returns blank file

Hello guys,

I'm trying to export a paginated report to PDF file using Power BI REST API. My account is currently in free trial, but I've created Premium Per User workspace, where I have my Paginated Report:

pej_0-1695647023718.png

I'm calling these API endpoints:

1. Export To File (to initialize exporting)

2. Get Export To File Status (for polling status)

3. Get File Of Export To File (retrieve the file)

 

When I try to export .PDF file, I get just blank pages. However, when I tried to export to simple .CSV, it works. Also tried .PPTX and when trying to open file it says it's corrupted.

 

I'm trying to also read through consideration and limitations for exporting paginated reports, but that wasn't that much helpful and it doesn't explain why the CSV would work and PDF not.

 

Any help will be appreciated. Thanks!

1 ACCEPTED SOLUTION

Found an error in my implementation. When using Axios for getting binary file data, I need to specify 

responseType: 'arraybuffer'

in the config. So it wasn't really a problem in the APIs itself, just my implementation. Full sample code:

const config = {
  headers: {
    Authorization: `Bearer ${authToken}`,
  },
  responseType: 'arraybuffer'
};

// Send the GET request
axios.get(apiUrl, config)
  .then((response) => {
    // Handle the response data here
    const pdfFilePath = path.join(__dirname, 'ExportedReport.pdf');
    fs.writeFileSync(pdfFilePath, response.data);
  })

 

View solution in original post

5 REPLIES 5
lbendlin
Super User
Super User

Try the same through Power Automate.  Note that the PDF export is especially prone to rendering timeouts.

Seems like that didn't work as well. For some reason, I wasn't able to send the PDF file as attachment to email using Power Automate, but Exporting to a PDF file generated some output like:

{"statusCode":200,.......,"body":{"$content-type":"application/pdf","$content":"JVBERi0xLjc............"}

I just tried to save the decoded $content to a .PDF file manually, but that didn't work.  

pej
Regular Visitor

I managed to make it work with Power Automate in such flow:

pej_0-1695801963584.png

It successfully export the Paginated Report to PDF and upload it to SharePoint site (for some reason sending an email with attachment didn't work for me). 

However, that really doesn't solve my issue of using simple REST API calls. This is a sample code of how I'm executing the 3rd API call to get the file content and save it:

axios.get(apiUrl, config)
  .then((response) => {
    const pdfData = response.data;
    const pdfFilePath = path.join(__dirname, 'ExportedReport.pdf');

    fs.writeFileSync(pdfFilePath, pdfData);
  })

, where apiUrl is Get File Of Export To File endpoint with exportId and reportId parameters. 

Not clear what you still need to do. The Power Automate action shields all the complexity from you.  If you want to do it all manually then you need to work through the complexity.

Found an error in my implementation. When using Axios for getting binary file data, I need to specify 

responseType: 'arraybuffer'

in the config. So it wasn't really a problem in the APIs itself, just my implementation. Full sample code:

const config = {
  headers: {
    Authorization: `Bearer ${authToken}`,
  },
  responseType: 'arraybuffer'
};

// Send the GET request
axios.get(apiUrl, config)
  .then((response) => {
    // Handle the response data here
    const pdfFilePath = path.join(__dirname, 'ExportedReport.pdf');
    fs.writeFileSync(pdfFilePath, response.data);
  })

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.