Embedding Office Files as PDFs
Implementation Steps
- Store Files in SharePoint Document Library
Ensure your Word, Power Point, and Excel files are stored in a SharePoint document library. This library will serve as the data source for the Power App - Create a Connection in Power Apps
- Open Power Apps and create a new app or open an existing one
- Go to the Data tab and click Add data
- Search for SharePoint and select it
- Connect to your SharePoint site and select the document library where your files are stored
- Create a Gallery Connected to SharePoint
- Add a Gallery control to your app
- Set the Items property of the Gallery to the SharePoint document library connection you created
- Customize the Gallery to display relevant information, such as the document title or name
- Add a PDF Viewer Control
- Add a PDF Viewer control to your app
- Position it on the screen where you want to display the documents
- Implement Logic to Display Documents as PDF
To display the selected document from the Gallery as a PDF, use the following steps:- Select the Gallery control and ensure it is named appropriately (e.g., GalleryName).
- Set the Document property of the PDF Viewer control to the below formula. This will convert the selected document's URL from a thumbnail to a PDF.
Substitute(GalleryName.Selected.Thumbnail.Large, "/thumbnail", "/pdf")
Output:
One of the PPT is being displayed in PDF Viewer
Comments
-
Embedding Office Files as PDFs
Just realised I asked the question about making these available offline in the wrong blog post (another one of @maqsoftware 's useful posts about converting docs to PDF in power apps).
Top help anyone with the same question as me here is @maqsoftware's helpful response (to save them having to post it again):
2 hours agoFirst, ensure the documents are accessible in a SharePoint library, OneDrive, or any other cloud storage service that PowerApps can connect to.
Enable Offline Capability:PowerApps has offline capabilities that allow data to be cached and used when there is no network connection. This is done using the LoadData and SaveData functions.
Load Documents on App Load:Use the OnStart property of your app to load the documents into a collection. Here’s an example code snippet:
Handle Document Viewing:To view documents offline, you need to download them to the device. Use the Download function to cache the document locally.
For example, when a user selects a document to view, you can download it as follows:
Display Offline Documents:Use a gallery or a list to display the cached documents. When the app is offline, use the LoadData function to load the documents from the local storage:
Check Connectivity:Use the Connection.Connected property to check if the device is online or offline, and switch between online and offline data sources accordingly.
Here is a more detailed example to guide you through setting up offline capabilities for documents in PowerApps:
codeLoadData(LocalDocuments, "DocumentsCollection", true);
/ Assuming the document URL is stored in the variable DocumentURL
Download(DocumentURL);// Assume you have a document list in SharePoint named "Documents"
ClearCollect(LocalDocuments, Documents);
SaveData(LocalDocuments, "DocumentsCollection"); -
-
*This post is locked for comments