Everything is wonderful when we develop Canvas apps in Power Platform until it is time to import documents in PDF format.

There is no upload control for PDF documents!

There is no upload control for PDF documents!

To solve this challenge, we propose a simple solution:

Borrow attachment control from forms

An important detail to keep in mind is that this method is valid using both classic and modern forms.

This idea is based on a solution proposed by Reza Dorrani. When the need arose to carry out their idea, we saw that it was unfeasible given that we do not have access to the client’s Sharepoint. It is for this reason that we adapt your solution to be carried out completely from Dataverse.

Importing PDF documents from Canvas App Axazure

How do we get the attachments control?

The first step to retrieve the attachments control is to create a table or use an existing one that contains a file type column.

Importing PDF documents from Canvas App Axazure
Importing PDF documents from Canvas App Axazure

Once we have the table, the next step is to insert the edit form control in our Canvas app and select the chosen table as a data source.

Importing PDF documents from Canvas App Axazure
Importing PDF documents from Canvas App Axazure

With the edit form inserted and configured to use the table with the file type column as a data source, we only need to add this field to the form and we will have the attachments control in our app.

Importing PDF documents from Canvas App Axazure
Importing PDF documents from Canvas App Axazure

Since we don’t need to work with the form, we borrow the control and delete the form.

Importing PDF documents from Canvas App Axazure
Importing PDF documents from Canvas App Axazure
Importing PDF documents from Canvas App Axazure

When removing the form control, the errors tab alerts us that there are corrections to be made. Specifically, we need to modify the following properties:

  • BorderColor
  • DisplayMode
  • Items
  • Tooltip
  • Y
Importing PDF documents from Canvas App Axazure

After following these steps, we now have the attachments control to import PDF documents into our Canvas app.

How can we use the attachments control?

Before moving forward with the use of the control, it is necessary to consider its functionality. This control uploads the attachments to a BLOB storage and the result is materialized in a table with the following schema:

Importing PDF documents from Canvas App Axazure

A very useful way to transport documents is using Base64 encoding. Next, the magic tricks we have to do to encode the document.

Importing PDF documents from Canvas App Axazure

We look at the result of using the attachments control through the PDF viewer and a label control to check the BLOB storage address.

Importing PDF documents from Canvas App Axazure
Importing PDF documents from Canvas App Axazure

To convert the document to a Base64 encoded string, we first insert an image control and set it to “display” the PDF.

Importing PDF documents from Canvas App Axazure

By using a button and the JSON function, we perform the transformation and store it in a local variable.

Importing PDF documents from Canvas App Axazure

Finally, we can see the result in the label control showing the local variable. It shows the Base64 encoded string of the PDF document imported through the attachment control.

Importing PDF documents from Canvas App Axazure

I hope you find this article useful and you can apply it in your future developments. See you next time!  😊

About the Author: Adrián Camargo

Importing PDF documents from Canvas App Axazure
D365FO TECH

Do you want to share?