Watermarking PDF Documents Using a SharePoint Designer Workflow — Part 2

Note that this post was originally written to show how to use the XML based watermarking syntax from a SharePoint Designer workflow. However, the same syntax can be used from our Nintex Workflow Activity, Microsoft Flow / Power Automate, as well as the Automatic Watermarking Facilities.

The Muhimbi PDF Converter for SharePoint contains a powerful watermarking engine that can be used to add watermarks to pages as well as adding headers, footers, page numbering and other recurring items. Multiple watermarks can be applied to the same page and watermarks can be applied to page ranges, page intervals or certain page types such as portrait or landscape.

In part 1 of this series I showed how simple watermarks can be added, one at a time, to a PDF file using a simple SharePoint Designer Workflow Action.  The disadvantage to this approach is that if you wish to combine multiple different shapes, e.g. a Circle, an Image, a barcode and some dynamic text, then a separate watermarking cycle is carried out internally for each shape. This works well and will be fast enough for most occasions, but it is not the most efficient way to do it.

The separate Add Composite Watermark to PDF workflow action allows multiple watermarks to be applied in one go with each watermark made up of 1 or more individual shapes.

The workflow parameters are as follows:

Composite WM Action

The real power comes as part of the watermark.xml field that stores the XML that describes the multiple watermarks and elements. The XML for each individual shape is described below, but before we go into more details let’s start with an example.

The following sample code describes three watermarks.

  • The first adds an image of the company logo (in the foreground) to the top right of each page in the document.

  • The second adds the login-id of the user who created / changed the document to a random location in the background in a semi-transparent way.

  • The third adds an automatically generated page number to the bottom right of each page.

If you wish to run this example then please make sure the imageFilePath attribute is updated to a file on your system.

Watermark element

As the previous example shows, the watermarks element may contain multiple watermark elements. This watermark element again can contain one or more individual shapes such as text and images.

The watermark element acts as a container that determines where the watermark will be located, on which pages, before or behind the text, opacity as well as which page orientations the watermark applies to.

The XML looks as follows ( Please omit any attributes marked as optional from your code when they are not needed. Leaving them in with the ‘optional’ text will cause an error.)

Text element

This watermark can be used to apply text to the foreground or background of one or more pages in the PDF file with full control over the font, style, size and color.

The XML looks as follows ( Please omit any attributes marked as optional from your code when they are not needed. Leaving them in with the ‘optional’ text will cause an error.)

The text stored in the content attribute may contain embedded field codes such as the date or current page number. For details see section 5.5 Embedding field codes in the Text element of the User Guide.

When a lot of content is anticipated then you may want to remove the content attribute and instead place it inside the text element, for example:

SharePoint Designer lookup variables are also supported, which makes it possible for dynamic information stored in workflow variables, or in the Item’s columns, to be embedded in the watermark.

RTF element

The RTF watermark allows simple RTF encoded text to be added as a watermark. This allows more control over the look and feel of individual words in the watermark at the cost of added complexity.

An example of valid RTF is as follows:

{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard

This is some {\b bold} text.\par

}

The XML looks as follows ( Please omit any attributes marked as optional from your code when they are not needed. Leaving them in with the ‘optional’ text will cause an error.)

When a lot of content is anticipated then you may want to remove the rtfData attribute and instead place it inside the rtf element, for example:

Note that unlike the Text watermark, the RTF watermark does not support embedded Muhimbi field codes. However, SharePoint Designer lookup variables are fully supported to make it possible for dynamic information stored in workflow variables, or in the Item’s columns, to be embedded in the watermark.

Image element

Use the Image watermark to add common image types (BMP, JPG, GIF, PNG, TIFF, WMF, EMF / EMF+) as a watermark to a PDF document.

The XML looks as follows ( Please omit any attributes marked as optional from your code when they are not needed. Leaving them in with the ‘optional’ text will cause an error.)

The image at this path parameter expects the full path of the image relative to the current site, e.g. ‘ shared documents/images/company_logo.gif’.

QRCode element

A range of different QR Codes can be added to documents using watermarks, ideal for embedding the document ID, or any kind of other SharePoint meta-data.

The XML looks as follows ( Please omit any attributes marked as optional from your code when they are not needed. Leaving them in with the ‘optional’ text will cause an error.

LinearBarcode element

A range of different barcodes can be added to documents, ideal for embedding tracking numbers, and other metadata.

The XML looks as follows ( Please omit any attributes marked as optional from your code when they are not needed. Leaving them in with the ‘optional’ text will cause an error.

PDF element

Existing PDF files can also be used as a watermark. This could be a dynamic file that is generated from, for example MS-Word, and then converted to PDF using the Muhimbi PDF Converter. Alternatively this could be a static PDF file that has been generated manually.

The XML looks as follows ( Please omit any attributes marked as optional from your code when they are not needed. Leaving them in with the ‘optional’ text will cause an error.)

The pdf file path parameter expects the full path of the PDF name relative to the current site, e.g. ‘ shared documents/static watermarks/company_logo.pdf’.

Rectangle element

A simple rectangle can be added as a watermark. The XML looks as follows ( Please omit any attributes marked as optional from your code when they are not needed. Leaving them in with the ‘optional’ text will cause an error.)

Line element

A line can be added as a watermark. The XML looks as follows ( Please omit any attributes marked as optional from your code when they are not needed. Leaving them in with the ‘optional’ text will cause an error.)

Ellipse element

A circle or ellipse can be added as a watermark. ( Please omit any attributes marked as optional from your code when they are not needed. Leaving them in with the ‘optional’ text will cause an error.)

Labels: Articles, pdf, 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