Combining multiple PDF files using a SharePoint Designer Workflow

Related Products

PDF Converter

PDF Converter

Share

Hi, I’m Nicolas and today I will show how to merge multiple PDF files using a SharePoint Designer workflow using the PDF Converter for SharePoint and the Workflow Power Pack.

Update: Please note that as of version 5.0 of the PDF Converter it is also possible to merge PDF Files using the SharePoint User Interface as well as via direct Web Service calls.

A quick introduction for those not familiar with the product: The Muhimbi Workflow Power Pack for SharePoint allows custom C# or VB.NET code to be embedded in SharePoint Designer Workflows without the need to resort to complex Visual Studio based workflows, the development of bespoke Workflow Activities or long development cycles.

The solution presented below shows how to create a SharePoint Designer workflow and attach it to a document library. This workflow is triggered when adding or modifying an item in the library, for example after converting a document using the PDF Converter. This example is particularly useful when you want to automatically add a cover page or Appendix to each and every PDF file in the system.

The workflow checks if the file extension for the current item is “pdf”. If this is the case then it uses the Workflow Power Pack to execute some C# code that carries out the actual appending of PDF files. The solution provided in this post works in SharePoint 2007 as well as 2010.

Create the workflow as follows:

  1. Download and install the Muhimbi Workflow Power Pack for SharePoint

  2. Download and install the Muhimbi PDF Converter for SharePoint

  3. We need to be able to access functionality in the Muhimbi.SharePoint.DocumentConverter.PDF assembly. Add this reference to the relevant Web Application using the Workflow Power Pack Central Administration screens as described in the Administration Guide.

  4. Make sure you have the appropriate privileges to create workflows on a site collection.

  5. Create a new workflow using SharePoint Designer.

  6. On the Workflow definition screen associate the workflow with the Shared Documents library, tick the boxes next to both “ Automatically start….” options and proceed to the next screen.

  7. We only want to act on files of type PDF. Although we could have put this validation in the code, in this example we use a workflow condition for it so add a Compare Any Data Source condition and:

    a. Click on the first value followed by the display data binding (fx) button.

    b. Select Current Item as the Source and select File Type in the Field. Click the OK button to continue.

    c. Click on the second value and enter pdf. (Use lower case as the compare option is case sensitive).

  8. Click the Actions button and insert the Execute Custom Code action.

  9. Click parameter 1 and enter a relative or absolute path to the PDF file you want to append to the current workflow item. For example /sites/PDFConversion/Shared%20Documents/appendix.pdf  or Shared%20Documents/appendix.pdf

  10. Optionally, click parameter 2 to specify a second PDF file to append.

  11. Insert the C# based code listed below by clicking this code in the workflow designer.  Note that copying this code using Internet Explorer may remove line breaks. Preferably use Chrome or Firefox to copy the code or alternatively paste it from Internet Explorer into Windows Wordpad and then copy it from there into SharePoint Designer.

  12. Click the Actions button, select Log to History List, click this message and enter PDF content appended to current item.

  13. Close the Workflow Designer.

  14. Update an existing PDF or add a new PDF file to your document library to trigger the workflow and append contents from the files defined in parameter 1 and parameter 2.

    Files to append

  15. The workflow should look something like this.

    Workflow

Of course this is just a sample, feel free to play around with the code, change which parameters are passed into the workflow, use different document libraries as source and destination of PDF documents, change the sequence in which documents are appended, etc.

Please leave a comment if you’re trying to do anything specific or if you want to share your experience with this approach.

As always, feel free to contact us using Twitter, our Blog, regular email or subscribe to our newsletter.

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

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

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