Combining Multiple PDF Files Using a SharePoint Designer Workflow
This blog post will demonstrate how to combine multiple PDF files using a SharePoint Designer workflow.
Note that as of version 5.0 of PDF Converter, it’s also possible to merge PDF files using the SharePoint user interface (UI), as well as via direct Web service calls.
Prerequisites for SharePoint On-Premises Servers
-
An active full or free trial license for PDF Converter for SharePoint On-Premises
-
The SharePoint Workflow Manager
-
Appropriate privileges to create workflows
Workflow Manager in SharePoint Server uses a new workflow service that introduces features such as REST-based web service calls without writing custom code. Starting with SharePoint 2007, a workflow engine is installed automatically whenever SharePoint is deployed.
The optional Workflow Manager introduced in SharePoint 2013 requires a separate installation.
When you create a workflow in SharePoint Designer 2013, you must select the platform type — either SharePoint 2010 Workflow or SharePoint 2013 Workflow. This post uses the latter.
The same options are available when building workflows in SharePoint Online. However, in SharePoint Online, it isn’t possible to invoke third-party workflow components in the 2010 workflow, so always select the 2013 workflow option.
Prerequisites for SharePoint Online
-
An active full or free trial license for PDF Converter for SharePoint Online
-
Workflow actions
-
Appropriate privileges to create workflows
The following steps outline how to create a workflow:
-
Create a list workflow using SharePoint Designer 2013 and associate it with the relevant document library.
-
Enter Muhimbi Merge Workflow and click OK to start the new workflow.
-
Add the local variables as shown below:
-
FileList (String) — This variable stores the list of file URLs that will be merged into the PDF.
-
ResponseContent (Dictionary) — This variable stores the response received from the web service.
-
responseCode (String) — The response status (OK/Failed) is returned from the web service call and stored in this variable.
-
RequestHeader (Dictionary) — This will be used as a header for web service calls.
-
ListofServerRelativeUrls (String) — This is used to temporarily store file URLs and is also used in the loop.
-
CurrentServerRelativeUrls (String) — This is used to store the current URL and is also used in the loop.
-
Index (Integer) — This is used to store the file count and is used in the loop.
Note: Some (other) variables will automatically be created when you add the various SharePoint Designer actions.
-
Add the Set Workflow variable to the SharePoint Designer pane. Set the workflow variable index value to 0 and add the Build Dictionary action.
-
Click this and add the key-value pairs listed below:
-
Accept — application/json;odata=verbose
-
Content-Type — application/json;odata=verbose
-
Set the Output to variable to RequestHeader.
-
Add the Call HTTP Web Service action. Once inserted, select the line that contains the web service workflow action and click the Properties button in the ribbon. Configure the parameters in the properties window using the details below:
-
Address — https://
/_api/web/GetFolderByServerRelativeUrl(‘ ’)/Files?$select=ServerRelativeUrl e.g. https://tenantname.sharepoint.com/sites/sitecollectionname/_api/web/GetFolderByServerRelativeUrl(‘Libraryname’)/Files?$select=ServerRelativeUrl -
RequestHeaders — Set the RequestHeader workflow variable.
-
ResponseContent — Set the ResponseContent workflow variable.
-
ResponseStatusCode — Set the responseCode workflow variable.
-
Add a Log to History List action. Log responseCode to the history list so that you know the status of the response.
-
Add an If any value equals value condition and set it to If responseCode equals OK. This checks for the web service response code and proceeds only if it’s successful.
-
Follow the steps below when the If condition evaluates to
true
.
-
Add the Get an Item from the Dictionary action, click on the items by name or path link, and type d/results. Then, set the from variable to the ResponseContent workflow variable and output it to the FileList workflow variable.
-
Add the Count Items in Dictionary action, click on the dictionary link and set the variable to the FileList workflow variable, and set the output to the variable count.
-
Add the Log to History List action. Log Count to the history list so that you know the total number of files you need to merge.
-
Add the Loop n times action and set The Contents of this loop will run to Variable: Count. Add the Get an Item from the Dictionary action. Click the items by name or path link and type d/results/([%Variable:index%])/ServerRelativeUrl. Then, set the from variable to the ResponseContent workflow variable and output it to the Current ServerRelativeURL workflow variable. Add the Set Workflow Variable action and set the workflow variable to ListofServerRelativeUrls. Then, use the string builder to set it to [%Variable:ListofServerRelativeUrls%].
-
Add the Do Calculation value action. Set the value to the workflow variable Index plus 1, and set the output to the calc variable. Add the Set Workflow Variable action, and set the workflow variable to index and the value of the workflow variable to calc.
-
Outside the loop, add the Log to History List action. Log the ListofServerRelativeUrls variable to the history list.
-
Add the Muhimbi Merge Documents to PDF action and set the these documents field to the ListofServerRelativeUrls workflow variable and this field to Merged.Pdf.
-
Set Transition to Stage and go to End of Workflow.
Now it’s time to test your workflow. Upload a few documents to the library to manually start the workflow. Check the workflow history list and make sure there are no errors. Once the workflow has completed, the merged file should appear in the specified location.
Clavin is a Microsoft Business Applications MVP who supports 1,000+ high-level enterprise customers with challenges related to PDF conversion in combination with SharePoint on-premises Office 365, Azure, Nintex, K2, and Power Platform mostly no-code solutions.