@Fredrik71 Dang it! I sort of suspected that was my issue but I didn’t realize I needed to add the alloc()'s init() after it. I had tried…
theAnnotation's current application's PDFAppearanceCharacteristics's setRolloverCaption:"caption-text"
and different variations on that, but never thought to initialize it. Thanks for your help @Fredrik71, I 'll give this another try and hopefully I can get it to work now.
One thing i’m still not understanding is I see you’re creating a variable called “appearance” and applying the rollover caption to that, but where/how does that ever relate to the annotation that is being created? I’m not seeing any lines that tie the “theAnnotation” and “appearance” together.
I’m starting to think I have the wrong item. I tried the code you suggested @Fredrik71, and it works without error but it doesn’t seem to do what I was hoping for.
If you open a PDF in Acrobat that has a form field item, there is an option labeled “Tooltip”, by the name and description I thought the rolloverCaption was going to be the same thing. However, after running the code you supplied, I’m not seeing my value in that section of the newly created widget.
Any thoughts on what I need to do to add the “Tooltip” to the annotation?
set appearance to current application's PDFAppearanceCharacteristics's alloc()'s init()
appearance's setRolloverCaption:"caption-text"
I don’t see where in this sample code that the rollover caption is being applied to theAnnotation. It doesn’t seem to me like we are relating the instance of PDFAppearanceCharacteristics’s to theAnnotation. If I’m not associating it to my annotation, am I not just creating a random appearance object?
If your PDF was made by any Adobe app or PDFKit, your annotation has no rolloverCaption property.
Try this:
use framework "Foundation"
use framework "PDFKit"
use scripting additions
set theURL to current application's NSURL's fileURLWithPath:"/Users/you/Desktop/aaa.pdf"
set thedoc to current application's PDFDocument's alloc()'s initWithURL:theURL
set theAnnotation to ((thedoc's pageAtIndex:0)'s annotations())'s objectAtIndex:0 -- change the indexes if needed
--return theAnnotation's annotationKeyValues() as record
theAnnotation's setValue:"Some rollover string" forAnnotationKey:"/TU"
theAnnotation's valueForAnnotationKey:"/TU"
thedoc's writeToFile:"/Users/you/Desktop/bbb.pdf"
If it does not work, uncomment the commented line and post the resulting record here.
@ionah. Thanks for the post. I had been working on this but couldn’t get a functional script. The setValue:forAnnotationKey: method is where I was stuck.
I tested your script on a sample PDF (see bottom of script for link) and it seems to work fine. I wish we had a sample PDF with a tooltip (as the OP wants) but I couldn’t find one. Anyways, great work
use framework "Foundation"
use framework "PDFKit"
use scripting additions
-- set annotation
set theURL to current application's NSURL's fileURLWithPath:"/Users/you/Desktop/aaa.pdf"
set thedoc to current application's PDFDocument's alloc()'s initWithURL:theURL
set theAnnotation to ((thedoc's pageAtIndex:0)'s annotations())'s objectAtIndex:0 -- change the indexes if needed
-- return theAnnotation's annotationKeyValues() --> /TU:"First name"
theAnnotation's setValue:"Some rollover string" forAnnotationKey:"/TU"
theAnnotation's valueForAnnotationKey:"/TU"
thedoc's writeToFile:"/Users/you/Desktop/bbb.pdf"
-- check annotation
delay 1
set theURL to current application's NSURL's fileURLWithPath:"/Users/you/Desktop/bbb.pdf"
set thedoc to current application's PDFDocument's alloc()'s initWithURL:theURL
set theAnnotation to ((thedoc's pageAtIndex:0)'s annotations())'s objectAtIndex:0 -- change the indexes if needed
return theAnnotation's annotationKeyValues() --> /TU:"Some rollover string"
-- Test PDF
-- http://foersom.com/net/HowTo/data/OoPdfFormExample.pdf
I really appreciate you showing me this example. I learn so much more with getting “hands on” and tinkering with code as I try and understand what’s happening.