Merge document array to PDF

Overview

The 'Merge document array to PDF' flow merges up to 1000 documents provided in a JSON array to a single PDF document. 

Please refer to the Supported Document Types articles for a complete list of the different file formats / document types which are supported for conversion.

Default Parameters

The default 'Merge document array to PDF' flow action parameters are detailed below:

  • PDF Filename: The filename to assign to the resulting PDF document (including file extension).
  • Documents: A JSON array containing a filename and a Base64 encoded string for each document which should be merged.

1.jpg

Documents - JSON Schema 

The JSON provided within the documents parameter should conform to the following schema:

{
      "fileName": "filename including extension",
      "fileContent": "File contents (Base 64 string)"
}

Troubleshooting

Please review the following article if you experience an issue executing the 'Merge document array to PDF' action: Errors processing Document Arrays

Creating the JSON Array

Flow provides the actions required to build the JSON array which is required by the 'Documents' parameter. The following example shows how to retrieve documents from a SharePoint folder and dynamically build the array.

1. Utilise the 'Get Files (properties only)' action to retrieve a list of target files

3.jpg

2. Create a new variable which will be utilised to store the JSON we will provide to the 'Documents' parameter.

5.jpg

3. To build the array we will create a loop using the 'Apply to Each' action which will process each item from the SharePoint 'Get Files (properties only)' action. The 'value' variable is passed from the SharePoint 'Get Files (properties only)' result. 

mceclip1.png

4. Add a 'Get file content using path' action to retrieve the file. 

4.a Site Address: Set as per the site address from step #1

4.a. File Path: Select the 'Folder Path' and 'File name with extension' properties from the SharePoint 'Get Files (properties only)' result.

mceclip2.png

5. Add an 'Append to array variable' action to add the JSON for the current document to the variable created in step #3.

5.a Add the following JSON to the Append to array variable' actions 'Value' property:

{
"fileName": ,
"fileContent":
}

mceclip0.png

5.b Place the cursor as per the image and select the 'FilenameWithExtension' property from the SharePoint 'Get Files (properties only)' result.

mceclip3.png

5.c. Place the cursor as per the image:

mceclip6.png

5.d Click 'Expression' and type 'base64()'

mceclip7.png

 5.e Click 'Dynamic Content' and insert the 'File Content' property from the SharePoint 'Get file content using path' result into the 'Base64()' expression.

mceclip8.png

5.f Click 'OK'

mceclip9.png

The competed JSON value is as follows:

{
"fileName": @{items('Build_the_Document_Array_(JSON)')?['{FilenameWithExtension}']},
"fileContent": @{base64(body('Get_file_content_using_path'))}
}

6. Add the 'Merge document array to PDF' action underneath the 'Apply to each' action

update3.png

7. Provide a 'PDF Filename' value, click the 'Switch to input entire array' icon

update1.png

8. Pass the 'FilesForMerge' variable created in step #2

update2.png

9. Add a SharePoint 'Create file' action passing the returned filename and 'File Content' return values from the 'Merge document array to PDF' action.

11.jpg

Operation Count

The final merge operation count is determined using the following calculation:

Merge Action (1) + No. of Documents Converted to PDF (n) =  Total Operation Count (1+n)

Advanced Parameters

The advanced 'Merge document array to PDF' flow action parameters are detailed below:

  • Remove Markup: Sets whether comments and tracked changes should be removed from the document(s) upon conversion. This option is only executed for Microsoft Office documents.
  • PDF/A Compliant: Sets whether the resulting document should conform to PDF/A format.
  • PDF/A Compliance Level: Sets the required level of PDF/A compliance.
  • Final Operation: (Advanced) Sets whether the this is last Encodian flow action, please refer to: Flow Action Return Options: File Content vs. Operation ID

2.jpg

Have more questions? Submit a request

2 Comments

  • 0
    Avatar
    Landon Patterson
    I was trying to follow this tutorial and I get the invaid expression error when I try to use:
    @{items('Build_the_Document_Array_(JSON)')['{FilenameWithExtension}']}

    Seems like the @{} is causing the issue. Do you have any guidance on how to fix this error?
  • 0
    Avatar
    Jay Goodison

    Hi Landon,

    We've modified the article, the @{} is added by Flow when you enter an expression, the simple fix is to remove them. You'll see after adding the expression that the actual string added to the JSON is wrapped by @{}

    Thanks for spotting and feeding back.

     

     

Please sign in to leave a comment.
Powered by Zendesk