These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Dynamic Stamp Weirdness

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Answered

Hello. I've managed to create a dynamic stamp that is behaving strangely and was wondering if someone might have some insight as to the cause. I've created a simple stamp that consists of two buttons and two text fields. In one of the fields there is a custom calculate script that sets the value of the text to which it is attached, and for debugging purposes, shows this value with an app.alert. I've set it up so it (should) only execute when the stamp is being applied. For example:
 
if (event.source.forReal && event.source.stampName == "myStampName") {
...code goes here
}
 
The alert happens when the stamp is applied, which I would expect. The weirdness is the script is also triggered whenever the stamp is rotated, even if I save the stamped document, close Acrobat, reopen the document that I stamped, and rotate the stamp. It is not triggered when the stamp is moved or resized.
 
Something even weirder is whenever the stamp is rotated, Acrobat adds a document-level icon to the document, with a name like: stampname-ENU-13
 
where "stampname" is the name of the stamp and the number at the end so far has been 0, 1, 13, 22, 34, and 45. I tried modifying other dynamic stamps with the same code and they do not behave the same way. It's a Frankenstamp.
 
The same stamp behaves the same way both on my Windows 7 machine (9.3.4) and Mac 10.6.6 (9.4.0). I haven't tried anything else yet.
 
I'm going to be troubleshooting this more tomorrow and will provide a sample file if I don't find anything and anyone is interested, but I thought I'd first see if anyone has experienced anything similar.
 
And no, I'm not drunk, just a little tired.
 
Thanks for reading!

My Product Information:
Acrobat Pro
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Hey George, you may have found an Easter Egg.

This strangeness goes far beyond the odd bug stage. The fact that Acrobat is both calling the original code and creating document level icons implies a deliberate intent. All form fields, code, etc. are destroyed when the stamp is placed. Have you examined the stamp annot dictionary to see if anything is saved there? If nothing is saved in the stamp then the only connection back to the original stamp code is the stamp name. Have you tried removing the stamp file altogether to see if it still reacts to a rotate? What is the stamp name? Something has to be triggering the actions. The most likely candidate is the name.


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Thom,

Thanks for responding. I hoped you would as I figured if anyone has seen this, it'd be you.

The template name is in the form: "com.example.stampname1=Stamp 1"

When I remove the stamp file from the stamp directory and then rotate the stamp on a stamped page, the stamp appearance becomes a large black X, and no alert. No alert makes sense. So I think you're right that there's some sort of link established between the stamp annotation and the stamp in the stamp file. Very weird.

I won't be able to do more work on this until later tonight, but I'll update this topic if I find anything of interest. If you'd be interested in looking at a sample, let me know.

George
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes please! I'd like to see that stamp file. For some reason Acrobat is going back to the original to redraw the stamp, that's why the stamp script is being called. Acrobat should not do this. Unless maybe there is something special about the stamp that tells Acrobat to go back to the original to redraw.

Whatever it is I'm sure it's undocumented and not for the casual user.

I notice that you did not prefix the stamp name with #. The "#" tells Acrobat to call the stamp script each time the stamp is placed. Otherwise, Acrobat only calls the stamp script once, when it is first placed.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
That's right, there is no # at the beginning, which was an oversight on my part.

I'll send a sample later today.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
Got it sussed out. If the stamp name is not prefixed with "#", then a rotate action causes Acrobat to go back to the original stamp to recreate the appearance, calling the stamp script in the process. I've consistently recreated this behavior in Acrobat 8. I cannot fathom why Acrobat would do this. It makes no sense. I can see a use for dynamically recreating a stamp. Just not on a rotate and nothing else. You'd hope that if they really needed a mechanism for recreating a stamp appearance that there would be a function for it.

Except, I just did some testing where I changed the stamp rotation from code run in the console window. The stamp script runs when the rotation is changed to any value except 0. So you could force Acrobat to recreate the appearance for a stamp by rotating to 1 degree and then rotating it back to 0. This could be handy, if it was a real feature and not a bug. I don't know which it is:-(

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Yeah, there must be some reason they do this, so it seems unlikely that it's merely a bug. The document icons *might* be added as a way to implement some sort of undo function, or otherwise keep track of changes, though I haven't bothered yet to look at the icons to see if this makes sense. This may have something to do with the reason they wipe out document-level icons when you do a Save As, which was a *very* unwanted change they made a while back...

It is quite interesting though. Have you imagined a useful application for this behavior yet? :^)

It doesn't sound like I need to send a sample, correct?

Thanks for taking the time to mess around with this. Very helpful.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Nope, don't need a sample anymore.

I do have a possible application. I've had a couple of clients that wanted a method for modifying the contents of a dynamic stamp. In fact, I've seen this request a few times on the forums. So that's one application. But the behavior is odd. I need the script to run when the stamp is placed. If the script only runs when the stamp is rotated, you're in the position of having to nudge the stamp each time you want the appearance updated. And what happens if a user who doesn't have the stamp file rotates it? No this behavior is not good for real use.


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script