You are currently viewing How to use pdf function in PowerApps?
PowerApps PDF function

How to use pdf function in PowerApps?

  • Post author:
  • Post category:Power Apps
  • Reading time:11 mins read

In this blog post, we will learn how to work with pdf function in PowerApps.

There are many custom solutions to generate PDFs within PowerApps using various techniques such as HTML to PDF Conversion that generate an HTML representation of the content you want in the PDF within PowerApps, and then convert that HTML to a PDF, but many of these approaches require might require some level of technical expertise. So in this post we will introduce a simple function to generate Pdf documents in PowerApps.

What is PDF function in PowerApps?

  • The PowerApps PDF function till the date of this post is an experimental feature that isn’t meant for production use and may have restricted functionality.
  • Pdf Function used to generate a PDF document from the contents of a screen or certain types of controls inside your app.
  • You can Download the generated document or send in an email or send to a flow “You can pass the generated file to an action connector”

Enable Power Apps PDF function

As we said it is an experimental feature that available for use before an official release, so in order to enable the function follow theses steps:

  1. Open the app you want to use the PDF function
  2. Select Settings and then select Upcoming features.
  3. You will find it on the Experimental tab, turn on PDF function. now you can use the pdf function inside your screen.

Limitations of Power Apps PDF function

  1. You can only generate a PDF from content existing on the screen where you have invoked the PDF function.
  2. There are some controls that aren’t currently supported include charts, Power BI tile, Map, and some configurations of third-party PCF controls.
  3. Nested Galleries aren’t supported.
  4. Nested Galleries aren’t supported.

Syntax:

PDF (ScreenName or controlName [,{Size, DPI, Margin, Orientation, ExpandContainers}])
  • ScreenName or controlName – Required , the content to use to generate the PDF.
  • Size: Optional. the dimensions of the generated PDF, A4, A6,A1,letter,Creditcard ,….etc
  • DPI: Optional. (value greater than 0) the scaling/resolution of the generated PDF (default is 96)
  • Margin: Optional. The size of the space between the content and the outer edge of the generated PDF (The default value is 0.5 inch (12.7 mm) for all margins).
  • Orientation: Optional. a portrait (vertical) or landscape (horizontal) orientation
  • ExpandContainers: Optional. Boolean. Controls whether certain containers with contents that exceed their allocated size expand to display all content in the generated PDF.

Enable PDf function

  • Click the App setting .
  • In the upcoming feature search for pdf and enable the pdf function.
pdf function in PowerApps

PowerApps PDF function examples

  • Generate PDF document of a selected screen
PDF('Your Screen Name')

this will create a pdf document from the visible contents of Screen

You can view the pdf object on PDf viewer or send to an email or a flow ,…etc.

Set(varpdf, PDF('Home Screen'));Navigate(screen1)

This will display the PDF object in the pdf viewer placed on screen1, it display only the visible content of the screen. and not expanded the controls.

pdf2 | Power Platform Geeks
pdf3 | Power Platform Geeks

You can use the {ExpandContainers: true} property to expand the data in the controls “in the gallery” displayed in your screen

Set(varpdf, PDF('Home Screen',{ExpandContainers: true}));Navigate(screen1)

This will generate pdf document containg all the items displayed on the gallery.

  • Generate PDF document from a form control on the current screen

You can generate a pdf document for a form either display or edit form in PowerApps

Set(varpdf, PDF(EditForm1,{ExpandContainers: true}));Navigate(screen1)
pdf4 | Power Platform Geeks

Sending the exported PDF document in an email message

You can send the generated pdf document from PowerApps as attached document to the user email using the Office365Outlook connector as shown in the below formula.

Office365Outlook.SendEmailV2(
    "Hebakamal87@outlook.com",
    "TNI PDF",
    "Kindelly see the attached PDF Document",
    {
        From: User().Email,
        Attachments: Table(
            {
                ContentBytes: PDF(
                    EditForm1,
                    {
                        Orientation: PaperOrientation.Landscape,
                        Size: PaperSize.A4,
                        ExpandContainers: true 
                    }
                ),
                Name: "TNIDetails.pdf"
            }
        )
    }
)

In your mail you will find the attached file that you generated from the pdf function in PowerApps

pdf5 | Power Platform Geeks

Generate PDF from gallery Contain nested galleries

One of the PDF function limitation is the nested galleries, but you can work around this limitation by generating HTML table that contain the main gallery and the sub galleries inside it and you can generate the pdf using Power Automate.


Concatenate(
    "<table border='1'><thead><tr>",
    "<th>Header1</th>",
    "<th>Header2</th>",
    "</tr></thead><tbody>",
    Concatenate(
        ForAll(
            Gallery2.AllItems, /* Iterate through the outer gallery items */
            Concatenate(
                "<tr>",
                "<td>", ThisRecord.title, "</td>",
                
                "</tr>",
                /* Nested gallery data */
                Concat(
                    ForAll(
                        ThisRecord.Gallery4.AllItems, /* Iterate through the inner gallery items */
                        Concatenate(
                            "<tr>",
                            "<td>", ThisRecord.'Skill Category'.Value, "</td>",
                            
                            "</tr>"
                        )
                    ),""
                )
            )
        )
    ),
    "</tbody></table>"
)

Conclusion

The PDF function in PowerApps allows you to generate PDF documents from the data within your PowerApps application. You can create PDFs from forms, galleries, or other controls, making it easier to capture and share structured data.

See Also
Join us

Heba Kamal

Microsoft MVP, MCT, Technical Speaker, Blogger, and Microsoft 365 and Power Platform Consultant.