Combining Multiple PDF Files Using a SharePoint Designer Workflow

Related Products

PDF Converter

PDF Converter


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

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

The following steps outline how to create a workflow:

  1. Create a list workflow using SharePoint Designer 2013 and associate it with the relevant document library.

  2. Enter Muhimbi Merge Workflow and click OK to start the new workflow.

  3. 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.

  1. Add the Set Workflow variable to the SharePoint Designer pane. Set the workflow variable index value to 0 and add the Build Dictionary action.

  2. 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.
  1. 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://<SiteUrl>/_api/web/GetFolderByServerRelativeUrl(‘<Document Library Name>’)/Files?$select=ServerRelativeUrl e.g.‘Libraryname’)/Files?$select=ServerRelativeUrl
  • RequestHeaders — Set the RequestHeader workflow variable.
  • ResponseContent — Set the ResponseContent workflow variable.
  • ResponseStatusCode — Set the responseCode workflow variable.
  1. Add a Log to History List action. Log responseCode to the history list so that you know the status of the response.

  2. 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.

  3. 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.
  1. 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%].

  2. 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.

  3. Outside the loop, add the Log to History List action. Log the ListofServerRelativeUrls variable to the history list.

  4. 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.

  5. 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.

Labels: Articles, PDF, PDF Converter, SP2010, Workflow

Have a Question?
We’re Always Happy to Help.

© Muhimbi Ltd. 2008 - 2024
This website uses cookies to ensure you get the best experience. Learn more