You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator Watermark PDF Workflow

Seems with every major upgrade, Apple breaks the Automator Watermark PDF Workflow.

Can someone test this workflow in Yosemite so I know if the problem I'm having is with OS X 10.10.

OS X Yosemite (10.10)

Posted on Oct 22, 2014 9:43 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 22, 2014 11:04 AM

I may agree with you. 😠 Can't get it to work as drag/drop application, with a rename after the watermark — or as a Printer plugin as below.


I create a Print plugin in Automator. Two actions:

  • Watermark PDF Documents

    Image: draft.jpg (will not allow you to select a draft.pdf with the chooser, but you can drag/drop one in the well - doesn't work either)

  • Set Application for Files - Preview


Print > PDF > myDraft


User uploaded file

53 replies

Jan 18, 2016 5:19 AM in response to VikingOSX

I have the same problem.


I am creating a banner image file from metadata. That all works well. When the image file (png) is passed into the watermark routine, it does not work. The log shows that the image file is being converted to a pdf before or during the watermark process. Not sure if that is the problem but haven't found a way around it. Any suggestions?

Jan 18, 2016 6:17 AM in response to crkdln1

I just created an Automator watermark application. I used a .png (and .jpg) image for my watermark, and chose the Draw watermark over PDF option. A very low opacity (0.09) value was used. The workflow consisted of the following:

  1. Ask for Finder Items
  2. Watermark PDF Documents
  3. Copy Finder Items (to Desktop with overwrite)


With this result:

User uploaded file

The only observation is that the watermark was placed correctly, but behind the text, not over it as selected in the watermark action. Also, the final PDF was not overwritten as requested, but made a generational foo 2.pdf name. Neither an issue for me. Tested on OS X 10.11.2.

Jan 18, 2016 9:40 AM in response to VikingOSX

Thanks.


This does work. When I then add the Set PDF Metadata and Get PDF Metadata and create image steps it does not work. If I run the Set PDF Metadata, Get PDF Metadata and create image as a separate workflow and then run your workflow, it does create a watermark. I will run them as separate steps but would be nice to have it in one workflow

Aug 12, 2016 3:41 AM in response to VikingOSX

Has anyone produced a python script to watermark a PDF with text, rather than an image?


I've been looking at CoreText, but it seems ludicrously complex. I'm almost tempted to have python create a PostScript file with the text, convert it to PDF, and then add it to the existing page.


(I'm looking at automatic page numbering for PDFs.)

Aug 12, 2016 8:14 AM in response to benwiggy

Have you looked at PDFAnnotationStamp in PDFKit? The old PDF Annotation Editor source code has an example of applying a stamp. It uses a PDF for the stamp though, and code would need to be added for scaling and rotation of the stamp box.


You could extend the tool.py in Automator's Watermark PDF Documents action with an additional command-line switch for -text, and the PDFAnnotationStamp functionality.


I could not find any existing watermark/stamping examples that used text instead of images or PDF, after several Google searches.

Aug 12, 2016 8:19 AM in response to VikingOSX

Thanks, I'll have a look at that. I've not found much via web searches either. Adding text to a Core Graphics context used to be easy, but Apple have deprecated all the easy APIs, in favour of CoreText, which is monstrous.


I've produced python scripts to combine, rotate, add graphics, count pages, make booklet spreads, apply quartz filters, etc, etc to PDFs, all using CoreGraphics, and I'm determined to persevere with adding text!!!


It can be done if you download some cross-patform python PDF library, but I don't really want to do that.

Aug 12, 2016 7:19 PM in response to benwiggy

Hello


Here's sample pybojc code to draw text watermark using Core Text CTLine as a proof of concept.



#!/usr/bin/python # coding: utf-8 import math from Quartz.CoreGraphics import * from CoreText import * def drawWatermarkText(ctx, line, xOffset, yOffset, angle, scale, opacity): # CGContextRef ctx # CTLineRef line # float xOffset, yOffset, angle ([degree]), scale, opacity ([0.0, 1.0]) if line: rect = CTLineGetImageBounds(line, ctx) imageWidth = rect.size.width imageHeight = rect.size.height CGContextSaveGState(ctx) CGContextSetAlpha(ctx, opacity) CGContextTranslateCTM(ctx, xOffset, yOffset) CGContextScaleCTM(ctx, scale, scale) CGContextTranslateCTM(ctx, imageWidth / 2, imageHeight / 2) CGContextRotateCTM(ctx, angle * math.pi / 180) CGContextTranslateCTM(ctx, -imageWidth / 2, -imageHeight / 2) CGContextSetTextPosition(ctx, 0.0, 0.0); CTLineDraw(line, ctx); CGContextRestoreGState(ctx) # parameters ifile = 'input.pdf' ofile = 'output.pdf' text = 'Watermark Sample' xOffset, yOffset, angle, scale, opacity = 0.0, 400.0, 60.0, 2.0, 0.2 # create CoreText line (CTLine) font = CTFontCreateWithName('Helvetica', 36.0, None) astr = CFAttributedStringCreate(kCFAllocatorDefault, text, { kCTFontAttributeName : font }) line = CTLineCreateWithAttributedString(astr) # create output pdf context ourl = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, ofile, len(ofile), False) ctx = CGPDFContextCreateWithURL(ourl, None, None) # create input pdf document iurl = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, ifile, len(ifile), False) pdf = CGPDFDocumentCreateWithURL(iurl) if pdf: for i in range(0, CGPDFDocumentGetNumberOfPages(pdf)): page = CGPDFDocumentGetPage(pdf, i + 1) if page: mbox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox) if CGRectIsEmpty(mbox): mbox = None CGContextBeginPage(ctx, mbox) CGContextDrawPDFPage(ctx, page) # elementary test CGContextSetTextPosition(ctx, 10.0, 10.0) CTLineDraw(line, ctx) # using general function drawWatermarkText(ctx, line, xOffset, yOffset, angle, scale, opacity) CGContextEndPage(ctx) del pdf CGPDFContextClose(ctx) del ctx




Briefly tested with pybojc 2.2b3 and python 2.6.1 under OS X 10.6.8.


Good luck,

H

Automator Watermark PDF Workflow

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.