Watermark PDF

I want to add a watermark to a PDF document.
What methods might I write an Applescript to simulate either:

  1. Watermark PDF Documents action in Automator
  2. PDFAnnotation method in pdfkit, described at https://developer.apple.com/documentation/pdfkit/pdfannotation

In general, Automator or ASObjC seem the best way to do this. However, just to provide an alternative, the OP could use the cpdf command-line utility, which is commercial software available free for non-commercial use:

https://community.coherentpdf.com

A simple AppleScript example is:

set logoFile to quoted form of "/Users/Robert/Working/logo.pdf"
set sourceFile to quoted form of "/Users/Robert/Working/source.pdf"
set outFile to quoted form of "/Users/Robert/Working/new.pdf"

do shell script "/usr/local/bin/cpdf  -stamp-on " & logoFile & " -center " & sourceFile & " -o " & outFile

Advantages of cpdf are 1) it has a great many options both as to the logo and the PDF and 2) implementing these options in an AppleScript is easily done. A disadvantage of cpdf is that it’s expensive for commercial use and is not cost-effective for this simple task.

Thank you for your wonderful recommendation and link to Coherent PDF’s binaries. Your alternative works quite well.

Thank you, peavine. It works!


--
--	Created by: peavine @macscripter.net
--	Created on: 2020/06/04
--	Modified by: Takaaki Naganoya @ Piyomaru Software
--	cpdf
--	https://community.coherentpdf.com

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use pLib : script "choosePathLib" --http://piyocast.com/as/asinyaye

set mesList to {"Logo PDF", "Source PDF"}
set defaultLocList to {"~/Movies", "~/Desktop"}

set cRes to choose multiple path main message "Drag & Drop to set target" sub message "" with titles mesList with default locations defaultLocList dialog width 800

set outFile to POSIX path of (choose file name with prompt "Select Output PDF File name")

copy cRes to {logoFile, sourceFile}

set logoFile to POSIX path of logoFile
set sourceFile to POSIX path of sourceFile

--check file extension = file type
if logoFile does not end with ".pdf" then error "Logo path is not pdf"
if sourceFile does not end with ".pdf" then error "Source file is not pdf"
if outFile does not end with ".pdf" then error "output path is not pdf"

try
	do shell script "/usr/local/bin/cpdf  -stamp-on " & quoted form of logoFile & " -center " & quoted form of sourceFile & " -o " & quoted form of outFile
end try

A watermark can be an image or text, it depends on the users what they want. To add a watermark to a PDF file user must have a trusted application that can watermark every page of the PDF. The Pcinfotools PDF Watermark Tool can help with adding the watermark to a PDF file.