Adding a watermark to a PDF file from a SharePoint Workflow

Related Products

PDF Converter

PDF Converter

Share

We get a great amount of interest from our existing PDF Converter customers for the Workflow Power Pack for SharePoint. I am not really surprised as there is a lot of of synergy between the two.

Last week I described how to configure PDF Security settings from a SharePoint workflow. This time I’ll describe another common request; adding a watermark to a PDF File.

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 executes a workflow whenever a PDF file is added or updated. As part of the workflow it loads portrait and landscape based watermarks and applies the relevant template to each page of the document. The workflow author can specify if the watermark goes in the foreground or the background, the SharePoint location of the watermarks as well as the level of transparency. As the code is well documented it is easy to make further changes and customisations, e.g. the PDF file that needs to be watermarked may not be the file the workflow is acting on.

Update: An article describing the use of dynamic text in the watermark is now available as well . As of version 3.5 the PDF Conversion Service also supports a native watermarking interface.

WatermarkedPages

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.

    Note that you need version 3.1.2.18 or newer, older versions do not allow watermarking.

  3. Download this article’s source code and sample watermarks.

  4. We need to be able to access functionality in the Muhimbi.SharePoint.DocumentConverter.PDF and System.Drawing assemblies. Add these references to the relevant Web Application using the Workflow Power Pack Central Administration screens as described in the Administration Guide. Make sure to place each reference on a new line.

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

  6. Create a new workflow using SharePoint Designer.

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

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

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

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

  10. Optionally click parameter 1 and enter a relative or absolute destination path. Leave the parameter empty to save the watermarked file on top of the existing PDF file. For details about how paths are handled, see this post and search for the words ‘this url’.

  11. Insert the C# based code embedded in step #3’s download (also listed below) by clicking this code.

  12. Click the Actions button, select Log to History List, click this message and enter File watermarked.

  13. Close the Workflow Designer.

  14. In the Shared Documents library create a sub folder named Watermarks and copy the 2 watermark files that are part of step #3’s download into it. If the watermarks are named differently or stored in a different location then update the paths in the script accordingly. Note that the sample watermarks are exactly A4 sized but they work fine on differently sized documents.

  15. Update an existing PDF or add a new PDF file to your library to trigger the workflow and apply the watermarks.

WaterMarkScript

Naturally this is just a simple example. Feel free to play around with the code, change which parameters are passed into the workflow, modify where watermarked files are written to or add dynamic text as a watermark. Leave a comment below if you are trying to do anything specific.

.

Labels: Articles, PDF Converter, Watermarking, 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