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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Solution Authors