In one of my previous blog post, I created a Flow to Merge Multiple documents into Single PDF. So the question may arise in your mind as to why am I writing another blog post on Merge?
This post shows how to use the Muhimbi REST API and the Microsoft Flow HTTP action which will help you Merge all documents within a SharePoint Online document library to a single PDF. If the document is not already in PDF Format it will convert the file as part of the merging process.
The main reason for using the above approach is better performance, as we are going to send all the Merge files – by their URL – in a single HTTP request, rather than looping through the documents one at a time. An additional benefit is that this request only takes up a single Muhimbi Operation, so is a lot more economical, and it gets around the file size limitations in Flow.
A prerequisite is that both the source files and destination file will need to be located in SharePoint Online. Also, Muhimbi’s SharePoint Online App must be installed in the SharePoint Online Site Collection, AND be linked to the same subscription as the Muhimbi (Flow) subscription.
Prerequisites:
Before you begin, please make sure the following prerequisites are in place:
From a High level our Flow will look like:
Let’s have some fun and build a Flow!
Step 1:
Step 2:
Using “Get files (properties only)” you can also filter down to the items that match a condition. For e.g. You can use ODATA orderBy query for specifying the order of entries or specify the total number of entries to retrieve. For more details see.
Step 3:
Note: I have used this convoluted approach with 3 variables as – at the time of writing – Flow does not allow ‘self-referencing’ when setting the value of a variable. Please vote for this Flow Idea
Step 4:
Note: Steps 5, 6 and 7 all need to be inserted inside the ‘Apply to each’ loop.
Step 5:
We will build the path to the file to merge or URL of web page to convert. (e.g. /sites/Finance/Shared Documents/Some Folder/Some file.docx).
The Next variables ;true:”Name” are optional. They are used to create the Bookmark.
For more details see below:
Step 6:
Step 7:
Step 8:
Method: POST
URI: https://api.muhimbi.com/api/v1/operations/merge_to_pdf (Muhimbi Merge Endpoint)
Headers:
Body:
{ "fail_on_error": true, "use_async_pattern": true, "sharepoint_file": { "site_url": "https://tenantname.sharepoint.com/sites/site-collection-name", "source_file_url": "@{variables('Merge String')}", "destination_file_url": "/sites/site-collection-name/Librarname/filename.pdf" }, "document_start_page": "Starts on the default page" }
To better understand the JSON Body see Muhimbi Github Merge sample code.
Your Merge Flow is now ready. Thanks for reading…
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.