Add Multiple Watermarks to PDF Document using Microsoft Flow

If you find yourself with a need to protect documents, and you’ve got a lot of files to process, then a common solution is to apply watermarks. Watermarking your PDF documents can signify whether the PDF document is a copy or an original, identify the owner or just classify the documents.

The Muhimbi Microsoft Flow actions provide us with 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.

A number of individual, and very user friendly, Flow watermark actions are provided by Muhimbi (Add image, add text, add barcode etc). However, for complex situations where you need a lot of control, AND combine multiple watermarks, a more complex action is available that accepts instructions using XML syntax.

Before we begin, please make sure the following prerequisites are in place:


Now that we have all the prerequisites in place, lets get going

The sample code below 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 Text “Confidential” to the Center location in the background.
  • The third adds an automatically generated page number to the bottom right of each page.

If you wish to use this example then please make sure the imageFilePath attribute is updated to a an anonymous file URL in your system.

<watermarks>
  <!-- ** First watermark contains a single image element with the logo -->
  <watermark 
    hPosition="right" 
    vPosition="top" 
    width="200"
    height="73"
    zOrder="1"
    opacity="100"
    pageOrientation="both">
    <image
      width="200"
      height="73"
      scaleMode="maintainaspectratio"
      imageFilePath="http://www.muhimbi-online.com/Content/Images/Muhimbi-logo.png"/>
  </watermark>
  <!-- ** Second watermark places the user's name in the background -->
  <watermark 
    hPosition="Center" 
    vPosition="Middle" 
    width="500"
    height="500"
    zOrder="-1"
    rotation="-45"
    pageOrientation="both">
    <text
      width="500"
      height="500"
      fillColor="#000000"
      content="Confidential"
      fontFamilyName="Times New Roman"
      fontSize="24"
      fontStyle="bold|italic"
      wordWrap="word"
      />
  </watermark>
  <!-- ** Third watermark adds page numbering -->
  <watermark 
    hPosition="right" 
    vPosition="bottom" 
    width="100"
    height="40"
    zOrder="1"
    pageOrientation="both">
    <text
      hPosition="left"
      vPosition="top"
      width="100"
      height="40"
      content="Page {PAGE} of {NUMPAGES}"
      fontFamilyName="Arial"
      fontSize="11"
      hAlign="left"
      vAlign="top"
      />
  </watermark>
</watermarks>

Here is the final Watermarked PDF that we will get:

Use Case:

In this article we will demonstrate how to Convert a document to PDF and Add Multiple Watermarks to that PDF with the help of the Muhimbi Microsoft Flow Add Composite Watermark action.

Step 1: Open the MS Flow designer, create a flow and find the “SharePoint — When a file is created” trigger. Using this trigger will allow you to start the flow when adding a file into a folder.

  • In the action, specify the path to the SharePoint Online Library to monitor for new items.

Step 2: Add the Muhimbi “Convert document” action to the Flow Canvas and configure it with reference to the details below:

  • Source File name: “File name” the output from the “When File is created in a Folder”.
  • Source file content: “File Content” the output of the “When File is created in a Folder”.
  • Output Format: PDF

Step 3: Add the Muhimbi “Add Composite Watermark” action to the Flow Canvas.

  • Source file content: “Processed File Content” the output of the “Convert document” action.
  • Watermark data: Copy and Add the sample Watermark XML mentioned above.

Step 4: Use the “Create file” SharePoint action to create the PDF document into SharePoint document library.

  • Folder Path: Specify the output path to write the processed file to. Make sure this is different to the folder of the input file to prevent ‘recursive’ flows.
  • File Name: “Base file name“.pdf  (output variable of the “Convert document” action.
  • File Content: “Processed file content” (output variable of the “Add Composite Watermark ” action).

That is it. Publish your Flow and upload a file (e.g. an MS-Word document) to the folder that is monitored by the configured SharePoint trigger. After a short wait, you can find the fully watermarked document in the output folder.

For more details about the various watermarking facilities in the Muhimbi PDF Converter, see this Knowledge base article.

Subscribe to this blog for the latest updates about SharePoint Online, Microsoft Flow, Power Apps and document conversion and manipulation.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s