📄

Generating PDF Documents in PowerApps

Sep 21, 2024,

Generating PDF Documents in PowerApps

Overview

  • Purpose: Learn to generate a PDF directly from PowerApps.
  • Two scenarios:
    1. Email the PDF as an attachment.
    2. Provide an option to download the PDF directly from PowerApps.
  • No flows involved.

PowerApp Setup

  • Example: Issue tracking PowerApp.
  • Homepage lists data from the data source using modern table control.
  • User can select a record; actions available in the toolbar (e.g., View).

PDF Generation Process

  • Form Screen Setup:
    • Built with a modern screen template (header and form).
    • Responsive experience using responsive container controls.

Steps to Create PDF

  1. Insert a Horizontal Container:
    • Set a defined height of 50 and disable flexible height.
    • Add action buttons (e.g., "Email PDF" button with a mail icon).
  2. Enable PDF Functionality:
    • Go to settings, search for PDF, and enable the PDF function.
  3. Send Email with PDF Attachment:
    • Use the formula: Office365Outlook.SendEmailV2.
    • Parameters:
      • To: User.Email (current logged-in user's email)
      • Subject: Title of the issue from home screen's table.
      • Body: Provide additional details; can include HTML.
      • Attachments:
        • Name: Title of the issue + ".pdf"
        • Content Bytes: Use the PDF function targeting the form container (e.g., FormContainer1).
        • Expand containers option set to true.
  4. Notify User:
    • Use Notify function to inform the user that the email was sent.

Testing the Email Functionality

  • Click "Email PDF" button to send email.
  • Check mailbox for email with PDF attachment: includes details from the form.
  • Behavior on different devices:
    • Tablet experience: better layout for PDFs.
    • Mobile device: single column layout with back button included in the PDF.

Handling Visibility of Buttons

  • Use a variable (varPDFGen) to manage visibility of the button container.
    • Set to true when generating PDF, then set back to false after notification.
    • This variable can also be used to style the generated PDF (e.g., changing background color).

Loading Screen Implementation

  • Insert a vertical container for loading screen.
  • Set visibility based on varPDFGen.
  • Include a loading GIF for user feedback during PDF generation.

Direct PDF Download Option

  • Use the same logic for generating PDF.
  • Set a variable (PDFContent) to hold the generated PDF content and convert it to JSON.
  • Use attachments control to allow users to download the PDF.
    • Utilize PowerApps feature to paste code for the attachments control.
    • Set visibility of the download button based on whether PDFContent is blank.

Conclusion

  • Successfully demonstrated generating PDFs from PowerApps and sending them via email or providing download options.
  • Encouraged viewers to engage with the video content.