Watermark your PDFs (Reloaded)


Tue 06 December 2016 By Michael Vachette

A few months ago my colleague Thibaud Arguillere wrote a great blog about watermarking PDF files. As you may know, watermarks are used to make it difficult to copy a document or to produce another document and pretend it's authentic. It also helps in identifying the owner (or copyright controller) of the document. Organizations may watermark their documents for different purposes depending on their need. In a use case that we came across, watermarks were used in PDFs to quickly identify obsolete content.

Back when Thibaud wrote the blog, we used a custom plugin to watermark PDFs but a few days ago that plugin was merged in the master branch of the platform and this feature will now be a part of our upcoming Nuxeo Platform LTS 2016. This feature will be reusable and can be called from an API. Several improvements to the feature have also been added, which will make it easier to use in production.

Earlier, you had to pass absolute coordinates for the watermark, such as 200px from the left and 100px from the bottom of the page. This does not play well with different page sizes. It also makes it difficult to align the watermark (for example, setting the watermark in the center of the page).

To do away with this limitation, the Nuxeo Platform LTS 2016 will introduce relative coordinates for watermarking operations. This will enable you to easily put a watermark at the center of the page, or in a corner, irrespective of the size of the page. This will also maintain the specified position of the watermark even if it is rotated.

Here‘s an example showing a text watermark centered and rotated clockwise at 45 degrees.

- PDF.WatermarkWithText:
    watermark: "WATERMARK"
    properties:
      rotation: "45"
      xPosition: "0.5"
      yPosition: "0.5"
      relativeCoordinates: "true"
      alphaColor: "0.7"
      hex255Color: "#dcb242"
      fontFamily: "Helvetica"

Setting the relativeCoordinates to true and the xPosition and yPosition to 0.5 tells the platform to center the watermark both horizontally and vertically.

Text content

As you can see from the above screenshot, it does not matter that the pages have different sizes or that the text is rotated. The watermark will always be in the center. The same thing applies to image watermarks, as you can see in the image below.

- PDF.WatermarkWithImage:
    image: "@{myWatermarkImageBlob}"
    properties:
      xPosition: "0.5"
      yPosition: "0.5"
      relativeCoordinates: "true"
      alphaColor: "0.7"

Text content

This feature will be available as part of the upcoming LTS release but if you can’t wait to try it, you can build it from the nuxeo-pdf-utils repository for the Nuxeo Platform FT 8.3!

That’s all for today. Stay tuned for more updates on PDF related features in the Nuxeo Platform LTS 2016.


Tagged: Nuxeo Platform, Nuxeo Plugin, Document Management, How to