It sounds like your Power Automate flow is successfully generating the PDF and saving it to SharePoint, but the issue occurs when downloading it directly from Power Apps. Since the first page is downloading while the rest isn't, it could be a timing issue or an issue with how the Download() function is handling the file retrieval.
Here are a few things to check and possible solutions:
1. Ensure Power Automate Flow Completes Before Downloading
If the PDF is still being written when Download() tries to fetch it, it might result in an incomplete file. Try introducing a delay before downloading the file by adding a Wait action in Power Automate.
Steps to Add a Delay in Power Automate:
- After creating the PDF and saving it to SharePoint, insert a "Delay" action.
- Set it to 5-10 seconds to allow enough time for the file to be completely written.
- Then, return the file URL or content back to Power Apps.
Alternatively, instead of a fixed delay, you can use a "Do Until" loop that checks whether the file size stops changing.
2. Try Downloading from the SharePoint URL Instead
Rather than passing the content directly from Power Automate, return the file URL from SharePoint and download it from there:
Modify Power Automate to Return URL:
- Instead of returning
contentBytes, return the SharePoint file path.
- Update the Power Apps
Download() function to fetch the file using the URL.
This ensures that Power Apps downloads the fully created file.
3. Verify the File Content Type in Power Automate
Ensure that Power Automate is returning the file in the correct format. In the "Create File" step:
- Set Content Type to
"application/pdf" explicitly.
- Confirm that
contentBytes is correctly passed.
4. Check If the File is Corrupted
Since you're seeing an error message when opening the downloaded file, test by:
- Manually downloading the PDF from SharePoint.
- If it works fine, then the issue is in how Power Apps retrieves it.
- If it is corrupted from SharePoint itself, the issue is in Power Automate's PDF generation.
5. Use Power Automate’s "Get File Content" Action Instead of contentBytes
If contentBytes isn't fully loading, modify your Power Automate flow:
- Instead of returning
contentBytes directly, add a "Get File Content" action after the file is created.
- Use that output to send back to Power Apps.