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.

Hello
Under 10.6.8, Watermark PDF Documents.action/Contents/Resources/tool.py works happily without any errors when invoked as follows with a.pdf and watermark.png in ~/desktop/test/ :
#!/bin/bash
py='/System/Library/Automator/Watermark PDF Documents.action/Contents/Resources/tool.py'
cd ~/desktop/test || exit
args=(
    --input     a.pdf
    --output    a_wm.pdf
    --verbose
    --over
    --xOffset   0.0
    --yOffset   -150.0
    --angle     300.0
    --scale     0.3
    --opacity   0.1
    watermark.png
"$py" "${args[@]}"
If the said error – ValueError: depythonifying 'pointer', got 'str' – is raised at the line:
provider = CGDataProviderCreateWithFilename(imagePath)
I'd think it is because imagePath is not a C string pointer which the function expects but a CFStringRef or something which is implicitly converted from python string. Since I don't get this error with pyobjc 2.2b3 & python 2.6 under 10.6.8, it is caused by something introduced in later versions.
Anyway, the statement in question may be replaced with the following statements if it helps:
url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, imagePath, len(imagePath), False)
provider = CGDataProviderCreateWithURL(url)
I modified the tool.py with these changes along with other minor fixes and run it successfully under 10.6.8. I'm not sure at all whether it works under later OSes as well. And even if it does, editing tool.py will require the Automator action to be re-codesigned.
Here's the revised tool.py.
#!/usr/bin/python
# Watermark each page in a PDF document
import sys #, os
import getopt
import math
from Quartz.CoreGraphics import *
from Quartz.ImageIO import *
def drawWatermark(ctx, image, xOffset, yOffset, angle, scale, opacity):
    if image:
        imageWidth = CGImageGetWidth(image)
        imageHeight = CGImageGetHeight(image)
        imageBox = CGRectMake(0, 0, imageWidth, imageHeight)
        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)
        CGContextDrawImage(ctx, imageBox, image)
        CGContextRestoreGState(ctx)
def createImage(imagePath):
    image = None
    # provider = CGDataProviderCreateWithFilename(imagePath)    # FIXED: replaced by the following CGDataProviderCreateWithURL()
    url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, imagePath, len(imagePath), False)
    provider = CGDataProviderCreateWithURL(url)
    if provider:
        imageSrc = CGImageSourceCreateWithDataProvider(provider, None)
        if imageSrc:
            image = CGImageSourceCreateImageAtIndex(imageSrc, 0, None)
    if not image:
        print "Cannot import the image from file %s" % imagePath
    return image
def watermark(inputFile, watermarkFiles, outputFile, under, xOffset, yOffset, angle, scale, opacity, verbose):
    images = map(createImage, watermarkFiles)
    ctx = CGPDFContextCreateWithURL(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, outputFile, len(outputFile), False), None, None)
    if ctx:
        pdf = CGPDFDocumentCreateWithURL(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, inputFile, len(inputFile), False))
        if pdf:
            for i in range(1, CGPDFDocumentGetNumberOfPages(pdf) + 1):
                image = images[i % len(images) - 1]
                page = CGPDFDocumentGetPage(pdf, i)
                if page:
                    mediaBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox)
                    if CGRectIsEmpty(mediaBox):
                        mediaBox = None
                    CGContextBeginPage(ctx, mediaBox)
                    if under:
                        drawWatermark(ctx, image, xOffset, yOffset, angle, scale, opacity)
                    CGContextDrawPDFPage(ctx, page)
                    if not under:
                        drawWatermark(ctx, image, xOffset, yOffset, angle, scale, opacity)
                    CGContextEndPage(ctx)
            del pdf
        CGPDFContextClose(ctx)
        del ctx
def main(argv):
    verbose = False
    readFilename = None
    writeFilename = None
    under = False
    xOffset = 0.0   # FIXED: changed to float value
    yOffset = 0.0   # FIXED: changed to float value
    angle = 0.0     # FIXED: changed to float value
    scale = 1.0     # FIXED: added
    opacity = 1.0
    # Parse the command line options
    try:
        options, args = getopt.getopt(argv, "vutx:y:a:p:s:i:o:", ["verbose", "under", "over", "xOffset=", "yOffset=", "angle=", "opacity=", "scale=", "input=", "output=", ])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for option, arg in options:
        print option, arg
        if option in ("-i", "--input") :
            if verbose:
                print "Reading pages from %s." % (arg)
            readFilename = arg
        elif option in ("-o", "--output") :
            if verbose:
                print "Setting %s as the output." % (arg)
            writeFilename = arg
        elif option in ("-v", "--verbose") :
            print "Verbose mode enabled."
            verbose = True
        elif option in ("-u", "--under"):
            print "watermark under PDF"
            under = True
        elif option in ("-t", "--over"):    # FIXED: changed to "-t" from "t"
            print "watermark over PDF"
            under = False
        elif option in ("-x", "--xOffset"):
            xOffset = float(arg)
        elif option in ("-y", "--yOffset"):
            yOffset = float(arg)
        elif option in ("-a", "--angle"):
            angle = -float(arg)
        elif option in ("-s", "--scale"):
            scale = float(arg)
        elif option in ("-p", "--opacity"):
            opacity = float(arg)
        else:
            print "Unknown argument: %s" % (option)
    if (len(args) > 0):
        watermark(readFilename, args, writeFilename, under, xOffset, yOffset, angle, scale, opacity, verbose);
    else:
        shutil.copyfile(readFilename, writeFilename);
def usage():
    print "Usage: watermark --input <file> --output <file> <watermark files>..."
if __name__ == "__main__":
    print sys.argv
    main(sys.argv[1:])
All the best,
H

Similar Messages

  • Automator: Watermark PDF Documents not supplied required data?

    I want to create a letterhead background on a Numbers document so I can email a Numbers document on my letterhead. I haven't found an easy answer so far until I came across the Watermark PDF Document feature in Automator. That would work perfectly, problem is, I can't get it to work at all. No matter what I have added, subtracted or rearranged I get the same results....The action "Watermark PDF Document" was not supplied with the required data. I'm really not sure what I'm doing wrong. Can someone walk me through what it is suppose to look like? I want it as a printer workflow so I can just take the document I'm working on in Numbers, go to the print menu, as if I was going to "print" it in to Preview, and it will convert it to PDF then put the watermark on it. I have done lots of research to try and figure out what I am doing wrong...and I hope it's something really silly because I am getting so frustrated.
    Thanks!

    I couldn't find the QuickLook folder but I took a screen shot.
    What I am asking for is someone to tell me what the workflow should look like.
    I have tried
    -Get Specified Finder Items
    -Launch Application (Preveiw)
    -Watermark PDF Documents
    -Move Finder Items
    -Rename Finder Items/Rename PDF Documents
    -View Results
    ..and all combinations of those items. I tried Watermark PDF Documents by iteslef as a Print Plugin...it gets to Preview but there is no watermark.
    No matter what I try the same result happens "The action 'Watermark PDF Documents' was not supplied with the required data."
    I have tried JPEG and PNG images, several different files with different sizes, shapes and colors. I even tried the images you supplied above. It never works.
    I'd love for someone to be able to make it work on their computer then tell me how they did it so I can duplicate it. If if still doesn't work for me then I'll know it's something to do with my computer.

  • Automator - Watermark PDF Documents

    Since Lion, I'm unable to use the Auromator Action "Watermark PDF Documents"
    I can select a .png file for the watermark, but it does not list in the action (see below)
    Can someone confirm that they are also unable to get this action to work, as I would like to isolate this as a Lion issue and not a system issue on my end.

    The answer to your problem is also on this page:
    http://superuser.com/questions/384967/add-a-header-to-every-page-in-a-pdf
    You can use the Watermark PDF documents action in Automator to add an image on every page of a PDF file. You can specify location, scale, rotation, and opacity.
    Manually fixing the workflow for Mac OS X Lion
    Set up the entire automator workflow as you would, but skip adding the watermark image (you can't). Save the workflow to a file. Right-click the workflow in Finder and select Show Package Contents and navigate into Contents. Opendocument.wflow in a text editor, e.g. TextMate.
    The actual parameters and their values are stored in the ActionParameters dictionary. The relevant key isfilenames. By default, it looks like this:
    <key>ActionParameters</key> <dict> <key>angle</key> <integer>0</integer> <key>fileNames</key> <array/> <key>onePDF</key> <false/>
    Just edit the <array/> declaration and add all files as <string>s, like so:
    <key>fileNames</key> <array> <string>/Users/danielbeck/Desktop/test.png</string> </array>
    Save the file, and reopen the workflow in Automator. The image will be correctly listed, and you can fix its position and other properties, before you apply it.
    Remember that the workflow does not replace the input file as many others do, the output is written to a temporary file. Use the Move Finder Items action afterwards.

  • Automator Watermark PDF Document

    WIth Lion I'm unable to add a .png file (or any image file) as a Watermark in the Automator action: PDF->Watermark PDF Document.
    This Worked for me in Snow Leopard.
    Can someone see if they get this to work?
    Tony

    Thanks.
    I already filed a bug report. 
    If you would like to also: http://www.apple.com/feedback/macosx.html

  • Automator Watermark PDF Issues

    I just updated to Yosemite (OS X 10.10) and the Watermark PDF function in Automator has stopped working. Each time it gets to this function, it returns an error message. I have tried replacing the function and even rewriting the Automator sequence but have not had any luck. I have also confirmed that it is not a renaming issue with the file or a problem with the picture itself. Has anyone had this problem or could they suggest a solution?

    I have exactly the same problem!
    Upgraded to Yosemite last night (to 10.10.1 actually) and this morning the Watermark PDF does not work anymore!
    Exactly the same automator file that still worked yesterday!
    Although this is a simple automator sequence (open folder, get all the files, watermark and put the files in a different folder), it is mission critical for me.
    I'll post this problem in a few places and see if I get a response, if not its back to Mavericks tonight. Fortunately I have a Time Machine backup....

  • How can I add a picture to the Automator Action "Watermark PDF Documents.action"

    Looks like a bug: under 10.7.2 i cannot add a picture to the Automator Action "Watermark PDF Documents.action".
    Works perfectly under 10.6.8.

    Its a verified bug (Automator - Watermark PDF Documents).
    Please report to http://www.apple.com/feedback/macosx.html
    As a workaround, if you saved the Action in SL, option-click the action, navigate to the file "document.wflow", open in TextEdit, search for the key "fileNames" and replace your old image with the new

  • Problem using Automator to create "Watermark PDF Documents"

    After having updated our macs from Mavericks to Yosemite, the "Watermark PDF Documents" using Automator is no longer working.

    Hi Miykael,
    Do you have flash player installed on your system for that browser? Did you tried accessing that pdf file from a different browser?
    I would also recommend you to refer this KB Document : https://helpx.adobe.com/acrobat/using/display-pdf-browser-acrobat-xi.html
    Regards,
    Rahul

  • Automator/PDF Workflow to create 11x17 pages?

    Is there any existing Automator action or PDF workflow to print a standard Pages or Word doc, or 8.5x11 PDF, to an 11x17 workflow? I have a newsletter I've created using Word 2008 that is in the standard letter-size format. I can print it to PDF using the built-in PDF workflow, but what I would like to do is print it as a booklet using 11x17 paper folded in half. Basically, page 4 and 1 on one side, and 2 and 3 on the other. Right now the only option I know of is to save each page as an image and then use Pixelmator to save the images side-by-side in two 11x17 canvasses, and then use Preview to merge them into one PDF file to send to a printing company, but am sure there has to be an easier way. I would pay $20-50 just to get an Automator action or PDF workflow to do this step for me. Does such exist?

    Wow! Thanks so much. I even have that workflow and never thought about it's usefulness for doing that with 8.5x11 pages. I use it all the time for 5.5x8.5 pages but for some reason never thought about this use for it. Awesome!

  • Watermark PDF Action (Offset x,y now working)

    I can create a watermarked PDF just fine, however, Automator freezes when I try to change the x and y offsets. As soon as I put the cursor in the box and try to change the value from 0, Automator will freeze.
    Any workarounds?

    I have played with that myself. Although it does seem to crash when you try to change those values you can still get it to work. For example, if I wanted to change the x offset to 50 I would select the current x offset then type 50. You'll see that when you type 50 it doesn't appear in the field and seems to lock up Automator... but that's OK. What you need to do after typing 50 press command-s on your keyboard to save the workflow, then press command-q to quit automator.
    Now just open the automator workflow again and you will see that 50 is in the x offset field. So although it does appear to lockup, you can still save your change and quit automator. It's not a good solution but it works. You just have to save and quit and re-open the workflow every time you make a change.

  • Can Automator run a workflow on many folders, one at a time?

    Hello,
    In a parent folder, I have a bunch of subfolders with image files (BMP, JPG or PNG).
    I want each of these subfolders to become a PDF combining the original image files.
    I also want the resulting PDFs to be named as the original subfolder.
    Is there a way to do it with Automator, or do I have to dive into Applescript (I am totally new to both)?
    In Automator, the following 3-step workflow does almost what I want:
    #1 - Ask for Finder Items (I provide the parent folder)
    #2 - Get folder contents
    #3 - New PDF from images
    However, I get only one huge PDF combining the contents of all subfolders (I need one PDF per subfolder) and I must give for step #3 a specific file name (I need the filename to be that of the containing folder).
    Am I on the right path? I tried using the 'Loop' action and the 'Path' variable but I didn't progress.
    More generally, can Automator run a workflow on a bunch of folders one folder at a time, or is that a job for Applescript?
    Thank you very much for you help.
    W.

    Unfortunately, the text field in the *New PDF from Images* action doesn't support variables, and the *Rename Finder Items* action doesn't either (I wish Apple would get on the stick with updating their actions). There is this macosxhints article about hacking the workflow plist, but that doesn't always work.
    I have a couple of actions that could be used - the Get Names of Finder Items action can be used to get the folder name (to put into a variable), and the Change Name of Finder Items action does accept variables to change the name.

  • PDF workflow : pre-press preparations in Illustrator interfere  :  Suggestions?

    Our packaging graphics group adopted a PDF workflow which has eliminated the clutter common of art file submissions. However, one print provider must preform additional preparations to the artwork, inserting supplier insignia and adding special press markings in addition to the customary trim marks and such. These final pre-press preparations are performed in Illustrator. Consequently, Illustrator ignores our PDF's embedded fonts. Unless the supplier has the same fonts installed, the PDF won't output accurately when it's saved/distilled again.
    Any suggestions on how to retain a PDF workflow when pre-press preparations involve adding content?

    You might look at inserting these objects as a watermark in PDF format?
    Your choice is slightly limited with Acrobat but Enfocus Pitstop might
    help? You can create a page mark action which will detect the trim box
    and then append custom information outside for the pre-press
    requirements ...
    Jon

  • Watermark PDF Documents Service error

    Hello,
    I created a workflow application to watermark PDF's, and now I'm trying to create a service that does the same thing. The workflow works as an application, but the service is getting an error that reads: "The action “Move Finder Items” encountered an error." The service is included below. Please advise how to fix this, thanks!
    Watermark PDF Documents
    Compress Images in PDF Documents (as jpeg)
    Move Finder Items (to desktop, replacing existing files)
    Rename PDF Documents (replace existing files)
    Message was edited by: edawg467

    You're developing an application? Perhaps post here:
    Discussions > Developer Forums > Software Development 101
    http://discussions.apple.com/forum.jspa?forumID=728

  • Automator and pdf

    How (with which logic) does Automator combine pdf 's in one? How can I force a precise sequence of pages of origina pdf 's?
    Thanks

    Photoshop allows you to rearrange the images you want to put in a multipage PDF within the source file selection dialogue box but it is very fussy about what file types you give it - basically they have to be created or saved as PSDs.
    As for Automator, it takes the source files within a folder in alphabetical order, so your best bet is to rename them before creating your multipage PDF.
    However this only works if you offer it a source folder to start with (so use the Get Folder Contents action first). If you bung a load of files at it (even if they are the contents of one folder) it will arrange them in an apparently random fashion.
    If you don't want to move various PDFs into one folder you can get Automator to create a temporary folder on the desktop, copy the various PDFs there, sort and rename them by date created and then pass this folder into the Composite PDF maker. You can also let Automator trash the temp folder once the job is done, or leave it on the desktop in case you want to rename files to get them in the right order and put that folder into the process.
    After creating the composite PDF you can also get Automator to move it to the desktop and rename it (using the Sequential option allows text entry such as New PDF-01) to avoid having to Save As in Preview as somebody suggested in another thread.
    Just today I created workflow for this purpose and saved as a Finder plugin. Now I can right-click any folder of PDFs and create a single composite PDF. As this was only my second ever Automator session I am a little proud and quite excited (though frustrated that I can't create PDFs from other source files).
    Hope this helps.

  • Flyleaf and end paper aren't shown up in pdf workflow

    Hi
    I want to order a book, but I'm hesitating. The book jacket appears on the pdf workflow but flyleaf and end paper don't. Instead of this page two reproduces a white ground with the book title on it.
    Should this be so ?
    Aperture theme is modern style and big hardcover.
    Any help appreciated
    Thanks
    Martin

    when i start my computer, firefox update automatically to 3.6.8 then i can't open firefox anymore. when i click firefox icon, nothing happen.
    please help! Fyi: i'v installed add on download helper and easy youtube download. I'm using Mac OSX 10.6.4.
    Please help!
    reply to my email: [email protected]
    Thanks
    Engel

  • Export PDF Workflow with Applescript and CS3

    Hello,
    I am setting up some PDF workflow with Applescript.
    On a given moment, as my script runs and after getting some user-input answers to questions in some dialogs, my script tells InDesign CS3 to open the Export Adobe PDF window for the current document. I copied and pasted that small part of the script:
    tell application "Adobe InDesign CS3"
    tell document 1
    export format PDF type to "Macintosh_HD:Test01.pdf" using "somePreset" with showing options
    end tell
    end tell
    When you run this small part of my Applescript, InDesign opens the Export Adobe PDF window (as expected) waiting for me to click on "Export". That is exactly what I want, since the user is given here a last opportunity to change some values (for example page range, or spreads). When all is set, the user can click on Export to close the dialog and finish the script.
    Problem: I was hoping that the Adobe PDF Preset "somePreset" would be selected in the first pull-down menu of the Export Adobe PDF window when this window is opened by the script. Unfortunately the last used preset is always selected by default. Anyone suggestions or help?
    Kind regards,
    Bertus Bolknak.

    My operators enter the page range and filename into a dialog box. Then I set those in the script. I use the Press Quality preset to start with and then set the changes I want into a export variable. I set things like bleed, marks, page range, etc.
    Here is an example:
    set theProps to properties of PDF export preset "[Press Quality]"
    try
    delete PDF export preset "Schmidt PDF"
    end try
    set theStyle to {name:"Schmidt PDF", acrobat compatibility:acrobat 7, bleed top:"0.125i", bleed bottom:"0.125i", bleed inside:"0.125i", bleed outside:"0.125i", page marks offset:"0.125i", include ICC profiles:Include None, effective PDF destination profile:use no profile, effective PDF X profile:"No Color Conversion"} & theProps
    make PDF export preset with properties theStyle
    set properties of PDF export preferences to theStyle
    set color bitmap sampling of PDF export preferences to none
    set grayscale bitmap sampling of PDF export preferences to none
    set page range of PDF export preferences to (item i of myPageList) as string
    export document 1 format PDF type to (PrinergyFolder & myJobNumFinal & "_" & VerCode & ".pdf") as Unicode text without showing options
    I am also doing this in Quark.

Maybe you are looking for

  • No signal after sleep

    My mac Mini awakes from sleep (I think) but my Viewsonic display shows "no signal".  I cannot see anything in the documents to suggest an adjustment that would help.

  • How to share variable between jsp and JSF?

    hi: I have code : <h:dataTable binding="#{Tables.dataTable}" value="#{Tables.query}" var="currentRow"> <h:column> <h:outputText value="#{currentRow['factorycode']}"/> </h:column> <% //here I want get upon variable currentRow and process some field. /

  • Problem (ugly display) with Samsung syncmaster 2243

    Hello I just plug my Samsung Syncmaster 2243BW on the mac mini (DVI). The resolution set is the good one : 1680x1050 @ 60hz, but the display isn' t clear, accurate, especially with the fonts. any ideas thanks in advance

  • How to improve Performace of this data.

    Hi All, We have ticket_master table with 200,000 currently and grows 2000 records per day. structure is ticket_no VARCHAR2(20) PK, trip_id VARCHAR2(20) RK refers to trip_master(trip_id), passenger_name,fare,boarding etc... second table is Ticket_canc

  • [VB][CS] Bug - why myStory.Contents myStory.Texts.Item(1).Contents ?

    hi for me it is bug - but maybe there is logical explanation ... it occurs in ID CS2 and CS4 - so probably in CS3, too let's say we have only one TextFrame in document with contents: Line1<enter> Line2<#> and run something like this (VBScript/VB6 exa