Using PDF functions in Power Apps (preview) – creating and viewing multi-page PDFs, saving files, email attachments

スポンサーリンク

PDF Functions

PDF functions are functions that were released as ‘experimental functions’ and allow the creation of PDF file content from screen elements.

Until now, PDFs have often been created via PDFWriter using the Print function, but the PDF function creates PDF content directly, so that multi-page PDFs can be created.

Settings that can be specified with PDF functions.

PDF functions allow the following settings to be specified when creating a PDF.

  • Screen or control name (required): Screen or control to be printed.
  • Size: PDF size
  • DPI: DPI of the PDF (default is 96)
  • Margin: space outside the PDF (default 0.5inch)
  • Orientation: Portrait or Landscape.
  • ExpandContainers: specify whether to include controls in containers or canvases (to create multi-page PDFs) with a bool value.

So I’ll try to use it as soon as possible.

Advance preparation

As a preliminary step, go to [Settings], switch on [PDF Functions] and restart the application.

Displaying created PDF content in PDFViewer

Prepare a container and control with scrolling (multiple pages are required when converting to PDF) as shown in the image,
Call the PDF function on this container from the button and put the created content in the variable ‘glbPDF’.
Then set glbPDF to the Document property of the PDFViewer,
button with the PDF function in it, you will see a multi-page PDF like this.

Set PDF function arguments.

Earlier, I did not specify any arguments for the PDF function, so when I scrolled down to the bottom of the PDF, the bottom label, which says ‘Text 4’, was not on the PDF.
So set the argument ‘ExpandContainers’ to true and run it again,
All elements in the container are converted to PDF.
Besides that, if you set various items as shown in the image (DPI 72, margins 25 mm, landscape orientation) and call the PDF function,
PDF is created as specified.

This is useful!

Save the PDF you have created.

Then save the created PDF to a file.

Since you need to use Power Automate to save the file, first create a flow with a Power Apps (V2) trigger and specify ‘File’ as an argument.
Then from the Power Apps side, call the flow as shown in the image and you are ready to go.
*Specify the file name in *name and the created PDF content in contentBytes (this time, specify the variable since it is in the variable glbPDF).

SharePoint Online document library/OneDrive

When saving to the document library, specify the following from the ‘Create File’ action.

  • File name: The name of the file you put into triggerBody from the ‘Expression’ tab OR The name of the file you want to save.
  • File content: values that can be specified in the ‘Dynamic content’ tab.


*TriggerBody expression to be included in the file name.

triggerBody()['file']['name']
It can be constructed in the same way when storing on OneDrive.
When executed, the PDF is saved.

SharePoint Online Lists Attachments

If the file is to be saved as an attachment to the SPO list, specify as shown in the image.
When executed, it is saved in the list attachment.

Attachment to email in Outlook

If you want to attach it to an email, specify as in the image below.

When executed, it can be sent as an email attachment.

limitation

This is a useful PDF function, but as it is an experimental function, it has some limitations.

Only the controls on the current screen can be converted to PDF

The ability to convert to PDF is restricted to the screen on which the PDF function is executed and the controls within that screen.

Calling the container (Container2) on another screen produces the following error.

Nested galleries are not covered.

In addition, nested galleries cannot be printed.

If a Gallery2 (with numbers up to 5) with nested controls as shown in the image is converted to PDF,
The display is disrupted.
Furthermore, if you try to convert the Gallery2 itself, which is contained within, into a PDF file,
Errors.

Related articles.

コメント

Copied title and URL