Fill a PDF Form with Microsoft Power Automate

In our previous blog post, we extracted PDF form data and stored it in a SharePoint List using Power Automate.

In this blog, we are “Fill PDF Forms” using SharePoint List data and  Muhimbi “Import PDF Form data” Power Automate action.

Scenario:

We have a SharePoint List with data, we want to loop through all the list items and Import the data in a PDF Form Template. We do not want to Flatten the PDF Form as the Form should be editable after the data is imported.

For this Demo – I will using the Form below –

Before we begin, please make sure the following prerequisites are in place:
  • Power Automate subscription.
  • Muhimbi PDF Converter Services Online Free, full or trial subscription (Start trial).
  • Appropriate privileges to create Power Automate Flows.
  • Working knowledge Power Automate.

Note – With Muhimbi’s “Import PDF Form data” action, you can Import XML, FDF, and XFDF data in the PDF Forms. For this particular demo, I will Import XML data into a PDF Form.

Part 1 – Get the Form Structure from an existing PDF Form.

Option 1 – To get the Form Structure in XML, you can export the Form to XML using Adobe DC by using the “Export Form Data” option.

Option 2 – Create a Power Automate to Export the PDF Form Data as XML(screenshot below)

Note: Muhimbi “Processed file content” returns a Base64  and we need to use the formula below to Convert it to a String.

base64ToString(outputs(‘Export_PDF_Forms_Data’)?[‘body/processed_file_content’])

<?xml version="1.0" encoding="utf-8"?>
<fields xmlns:xfdf="http://ns.adobe.com/xfdf-transition/">
  <GivenNameTextBox xfdf:original="Given Name Text Box">Clavin</GivenNameTextBox>
  <FamilyNameTextBox xfdf:original="Family Name Text Box">Fernandes</FamilyNameTextBox>
  <Address1TextBox xfdf:original="Address 1 Text Box">Sai Jewel</Address1TextBox>
  <HousenrTextBox xfdf:original="House nr Text Box">Central Park</HousenrTextBox>
  <Address2TextBox xfdf:original="Address 2 Text Box">Kharghar</Address2TextBox>
  <PostcodeTextBox xfdf:original="Postcode Text Box">410210</PostcodeTextBox>
  <CityTextBox xfdf:original="City Text Box">Navi Mumbai</CityTextBox>
  <CountryComboBox xfdf:original="Country Combo Box">India</CountryComboBox>
  <GenderListBox xfdf:original="Gender List Box">Man</GenderListBox>
  <HeightFormattedField xfdf:original="Height Formatted Field">180</HeightFormattedField>
  <DrivingLicenseCheckBox xfdf:original="Driving License Check Box">Yes</DrivingLicenseCheckBox>
  <FavouriteColourListBox xfdf:original="Favourite Colour List Box">Yellow</FavouriteColourListBox>
</fields>

Now that we have the Template as an XML let’s create a Power Automate Flow to “Import the SharePoint List item” in a PDF Template.

SharePoint List items we want to Import in the PDF Template

From a “High level” our flow will look like the screenshot below –

Step 1 – Create a new Flow using the ‘Instant cloud flow‘ option and use the “Manually trigger a flow” Trigger.

Step 2 –  Add the SharePoint “Get items” action to the Flow canvas and configure it with reference to the details below:

  • Site Address: Specify the path to the SharePoint Online site-collection which holds the file.
  • List Name: Select the SharePoint list you want to get the items from.

Note: If you have a large list you might need to configure the action “Settings” and turn “On” the Pagination option and setting the “Threshold” to a site collection.

Step 3 –  Add the SharePoint “Get file content using path” action to the Flow canvas and configure it with reference to the details below:

  • Site Address: Specify the path to the SharePoint Online site-collection which holds the Form Template.
  • File Path: Select the File Path to your PDF Form Template

Step 4 –  Add the “Compose action” on to the Flow canvas:

  • Paste in the “XML template” we exported in the section “Get the Form Structure from an existing PDF Form“.
  •  Insert the various list fields from the “Get items” action in the appropriate places between >< element in the XML.

Tip – If you have an Yes\No column in SharePoint it will return you a True\False . For it to be updated into a checkbox field in your form you will need to Convert it to Yes\No using the formula below –

if(equals(items(‘Apply_to_each’)?[‘DrivingLicense’],True),’Yes’,’No’)

Change the “DrivingLicense” with “Your Field  Internal Name“.

Step 4 – Inside the “Apply to Each” loop add the Muhimbi “Import PDF Form data” action to the Flow canvas and configure it with reference to the details below.

  • Source File name: “Title”.xml  the output from the “Get items” action.
  • Source file content: “Outputs” of the “Compose” action.
  • PDF Form file Content: “File Content” is the output of the “Get file content using path” action.
  • Flatten: No (We need the form to be editable).
  • Read-Only: No

You can find the full details for the “Import PDF Form Data” action here.

Step 5 –  Inside the “Apply to each loop ” add the “Create file” SharePoint action to create the PDF document in the SharePoint document library.

  • Folder Path: Specify the output path to write the PDF file to.
  • File Name: “Base File Name”.pdf  is the output variable of the “Import PDF Form data” action.
  • File Content: “Processed file content” is the output variable of the “Import PDF Form data” action.

All Done!  Start your Flow “Manually”  and after a few seconds, each list item from the SharePoint List will be Imported into a Template and  PDFs will be created in the destination library.

Subscribe to this blog for the latest updates about SharePoint Online, Nintex, Microsoft Flow, Power Apps, and document conversion and manipulation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s