31 May 2009

More Interactive Dynamic Stamps in Seven Easy Steps

Posted by khk


Please visit the same post on my business site. The comments are closed here, so if you want to comment, you have to head over to http://khkonsulting.com/2009/05/more-interactive-dynamic-stamps-in-seven-easy-steps/

A while ago I tried to create an interactive dynamic stamp in Acrobat. These are dynamic stamps (like for example a stamp that automatically puts the current date into a field that is part of the stamp), but with a UI component that pops up and queries the user for some information that also gets embedded as part of the stamp (e.g. a phone number or a name).

I was not very successful. I could not figure out how to make sure that the UI only gets triggered when the stamp gets applied, and not when the stamp file gets loaded by Acrobat.

Then I came across an article by Rick Borstein titled “Add Dynamic Exhibit Stamps in Acrobat using a free stamp set” on the Acrobat for Legal Professionals blog. It had all the parts that are required, it even came with a couple of sample stamps. It also gave credit to the original source for that information: Acrobat JavaScript Guru Thom Parker

Thom provides all the theory behind why this works – very interesting to read if you are into that kind of stuff. It’s however not required to understand all that if you just want to use these stamps. You can just download Rick’s sample files and modify them until they fit your needs.

However if you want a dynamic stamp that shows more than just one line of interactively provided information, the examples do not work. They only provide one one-line input field and then put that one line on the PDF document. I wanted a stamp that could actually take several lines of user input and use that in a stamp. I had some work to do…

Acrobat’s JavaScript does allow to create custom user interfaces by creating a data structure and then calling executeDialog() with that data as parameter. Instead of a simple call to app.response() like in Thom’s and Rick’s examples, I needed to create a more complicated UI structure and embed that in the examples.

Here is the original code from the example:

var cAsk = "Enter Exhibit Number" ;
var cTitle = "Exhibit Number:  ";
if(event.source.forReal && (event.source.stampName == "#UdzyXagRctZoS5p43TZ43C"))
  var cMsg = app.response(cAsk, cTitle);
  event.value = cMsg;
  event.source.source.info.exhibit = cMsg;

I’ve replaced that code with the following:
var dialog = {
  retString: "",

  commit:function (dialog) { // called when OK pressed
    var results = dialog.store();
    this.retString = results["stxt"];

    name: "Stamp Information",    // Dialog box title
        type: "view",
            name: "Enter Multi-line Information: ",
            type: "static_text",
            item_id: "stxt",
            type: "edit_text",
            multiline: true,
            width: 300,
            height: 80
            type: "ok_cancel",
            ok_name: "Ok",
            cancel_name: "Cancel"

if(event.source.forReal && (event.source.stampName == "#UdzyXagRctZoS5p43TZ43C"))
  if ("ok" == app.execDialog(dialog))
    var cMsg = dialog.retString;
    event.value = cMsg;
    event.source.source.info.exhibit = cMsg;

And here are the instructions to change the first stamp in Rick’s example to the new style:

  1. Open the “Exhibit+Stamp.pdf” document in Adobe Acrobat Pro
  2. Go to the second page in this document – that’s the first stamp
  3. Select the TouchUp Object Tool (e.g. via Tools>Advanced Editing>TouchUp Object Tool)
  4. Right-click on the lower part of the stamp (where the UserData1 field) and select Properties… from the menu
  5. Select the Options tab and check the “Multi-line” checkbox
  6. Select the Calculate tab and click on the Edit button next to the custom calculation script and replace the old script with the one from above
  7. Save the script with the OK button, then close the properties dialog

That’s it – just install the stamp file as described in Rick’s document. Done.

Of will of course be hard to see two or more lines in the relatively small stamp, so you may have to change the layout of the stamp to actually make use of the additional lines.f

Subscribe to Comments

17 Responses to “More Interactive Dynamic Stamps in Seven Easy Steps”

  1. When I paste in your script and press ok, I get the following error message:

    missing ) after condition
    40: at line 41

    I am using Acrobat Pro 9.



  2. I got the same message as Mike.



  3. To fix the error above, replace the “&&” with “&&”.



  4. Line 41 should read:
    “if(event.source.forReal && (event.source.stampName == “#UdzyXagRctZoS5p43TZ43C”))



  5. There seems to be a problem with how WordPress shows the “&” in the code segment above – they show up as & amp; (I’m adding a space to fool WordPress) – so, just replace every instance of & amp; with an ampersand (“&”).
    Thanks Jon.



  6. I was wondering if you have tried to add an icon when adding the stamp or if you know how to do it.
    I was trying to create a stamp that had a text variable (user entry) and an icon. So, when the stamp is placed in the document an input window comes up first, so the user can enter the text data and then a browse icon screen to choose what image the user wants to assign to a button.
    I can create this on a pdf but when I do it as a stamp, it just works if I have the stamp file open?
    Any thoughts?



  7. When I right-click on the lower part of the stamp and select Properties, my options do not include an Options tab. Can you assist me? I have gone to the TouchUp panel in the Preferences of Adobe and specified an object editing application that I downloaded called First Object.



  8. I would like to express my gratitude to KHK for assisting me with getting my stamp to work and format correctly. I am just tickled to have found this site and look forward to learning more about all the functionality of Adobe.
    Besides, the IT guy that we use said that this was “IMPOSSIBLE!”



  9. I never could figure out when you add a new image how to get that file name, so I just edited his page and was going to do different files but that doesn’t seem to work either because it doesn’t recognize the second file I it is because I guess it is because both files are calling the same file names exampe
    (event.source.stampName == “#UdzyXagRctZoS5p43TZ43C”))
    The instructions I have found to find the file names when adding a new stamp were to
    Open the Exhibit Stamp.pdf (see file locations above) in Acrobat. Choose Advanced—> Page Templates. Each stamp will have its own, randomly generated ID number:

    But I do not know how to find the Page Templates

    I am using Acrobat 8 Professional

    Any help



  10. In Acrobat 8, the “Page Templates” menu item is only available when
    – the current document contains at least one form field
    – the “Select Object Tool” is active (Tools>Advanced Editing>Select Object Tool)”

    Then the Page Templates menu item can be found in the “Forms” menu.



  11. Thanks that worked. Now I have tried adding the new stamp but the only names showing up is the two that were the original and also how can I change these names or can I.



  12. http://blogs.adobe.com/acrolaw/?p=108#more-108

    Above is the link with instructions I have followed to try do several of my own. I have edited the file to use one of my stamps it works fine. I tried to change the name and it doesn’t like that also I need two more stamps and I couldn’t get them to work with along with the ones I have. What I have been doing is using two different files 1 with the 1 stamp and the other with 2 stamps. But I have have on only file in the locations where the stamps are kept I figured this one cause both files referred to the same original file names. So I tried going into the Page template and added new names and now I can used both files but the problem I am having whether I use two different files or add all the stamps to the same file is I can only use the stamp once then it doesn’t work until I close the file and open again I am having that trouble with the files I think because of having to rename stamps.

    I was hoping you could help me out with the template.



  13. Hi sir,

    Nice mail and very informative.
    I have prepared a stamp file which looks likes a form having various fileds for data entry. In one of the field’s Action value I have kept some code. I have kept this file at default file location of pdf for stamps. Now when I open any pdf and try to put stamp, I get a pop up for data entry and as i press OK after filling data that appears in stamp correctlt. But data is not saved in souce stamp file. I want that when i put next stamp last entered data should appear popup dialog. Please help me.



  14. […] a custom dialog, which can be a bit involved. Here’s a sample with links to more information: http://www.khk.net/wordpress/2009/05/31/more-interactive-dynamic-stamp s-in-seven-easy-steps/ Related […]

  15. Hi,

    I’m trying to create a stamp where it has more than just 2 fields (the case number and exhibit number) also I would like to rename those fields to something else. How do I go about creating a new stamp with say 12 fields and each of them to be able to dynamically type in data just like what you have in the case and exhibit number?

    greatly appreciated.



  16. If I understand right Acrobat creates a random filename for each stamp. This filename can be changed afterwards.

    But changeing the filename does not affect this code line:

    event.source.stampName == “#UdzyXag….”

    How do you change the internal name of the stamp after it was created?

    It will not work if more than one dynamic stamp have the same internal stampName…



  17. Karl,

    When using dynamic stamps the first time you can enter a number, then if the next time you use it in that document and you hit cancel instead of entering anything it repeats the same number you used before. But if Adboe isn’t set up right this function doesn’t work. How do you got about getting this to work again once already setup.