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)
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.
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
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)
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:
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)
Print > PDF > myDraft
Since error is related to matching quotes, try deleting and re-entering every "
That worked - thanks!
Unfortunately the direct call of tool.py didn't work. Neither did ./tool.py - it only worked with the full path given. Little bit annoying since I can't copy the whole directory with the .py & workflow script to another computer with a different user without re-editing that stuff.
For portability to other users, see if the $HOME variable works: $HOME/Desktop/tool.py (or ~/Desktop/tool.py)
I am really sorry, and maybe I am a little bit slow on this one. I made a video where you see that it is not working for me 'out of the automator box'.
Any help would be really welcome. Here is the screen recording: http://youtu.be/HEqs-1U9WNU
The Watermark PDF Documents Action is now fixed in OS X 10.11 (El Capitan)
It worked the first time that tried it in Automator, and then consistently failed afterward. This was just after I had upgraded to 10.11.1. Not much room for pilot error in Automator when it works, and then doesn't without changing any Automator settings. I may take a closer look at it over the weekend.
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?
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:
With this result:
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.
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
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.)
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.
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.
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
Many thanks! That's great.
I've written a whole bunch of python Quartz scripts for manipulating PDFs. They are called "PDFSuite" on github.
I'll add this one, if that's OK.
Automator Watermark PDF Workflow