“Printing” in Canvas app – Leveraging Onedrive

  1. Introduction
  2. Solution
  3. Demo
    1. Step 1
    2. Step 2
    3. Step 3

Introduction

I’ll see if I can manage this in 20 minutes. I’m currently at a terminal in O’Hare, about to head to Las Vegas for the Power Platform Conference, and I’ve just thought of an intriguing scenario for which I recently devised a solution in a canvas app.

The print functionality in Canvas Apps, while serviceable, is not the best. I found a workaround by utilizing OneDrive’s native capabilities to print a PDF.

Solution

For demonstration purposes, my example is abbreviated. Initially, I had to generate a PDF using Power Automate and Microsoft Word templates, which would then be printable by the user. In the first version, I created the PDF and emailed it to the user, who could then print the attachment. However, this method necessitated that they access Outlook to retrieve the email.

My second approach was to determine how to print the PDF directly from the app, maintaining the format as it appeared when generated in Word. I considered creating a PCF but decided against it due to budget constraints. I experimented with opening and closing the PDF in OneDrive via the browser, attempting to manipulate the URL parameters for use in the app to prompt the browser to initiate printing. Unfortunately, this method was unsuccessful.

As I reflected, I began to count the number of clicks. As developers, our aim is to reduce the number of clicks required for a user to complete a task, since an excess can lead to irritation. My objective was to enable users to complete the printing task in fewer than five clicks, with the app managing the interaction directly, rather than having to press a button, wait for an email, retrieve the attachment, and then print.

I utilized Power Automate to create a Word document, convert it to PDF, save it to OneDrive, retrieve the sharing link for the app, launch the PDF in a new tab, and then print the document.

This enabled me to achieve my objective of printing the document in fewer than five clicks.

Demo

Again our demo is a bit short

Step 1

Add your document library as your data source.

Step 2

Use a button to set a global variable by employing a lookup function linked to your document library, utilizing the ID as the lookup criterion to fetch a single record. Apply dot notation and set the variable using ‘Link to item’ as the parameter.

Encapsulate the variable within the Launch function, set the target to ‘new’ to open a new tab, and it will initiate the launch of your PDF.

Step 3

Click the print button.

Leave a Reply

Discover more from Duke DeVan

Subscribe now to keep reading and get access to the full archive.

Continue reading