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"];
  },

  description:
  {
    name: "Stamp Information",    // Dialog box title
    elements:
    [
      {
        type: "view",
        elements:
        [
          {
            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

This entry was posted in Acrobat, PDF and tagged , , , , . Bookmark the permalink.

30 Responses to More Interactive Dynamic Stamps in Seven Easy Steps

  1. Mike says:

    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. G says:

    I got the same message as Mike.

  3. Jon says:

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

  4. Jon says:

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

  5. khk says:

    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. Gimar says:

    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. artrain says:

    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.
    Thanks.

  8. artrain says:

    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!”
    LOL!

  9. Vickie says:

    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. khk says:

    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. Vickie says:

    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. Vickie says:

    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. Paul says:

    Hi,

    I’m looking for a way to create a new PDF stamp via EXCEL VBA .
    It does not have to be a dynamic stamp, as the stamp then would be altered outside of Acrobat and imported as a new stamp into acrobat.

    Is this possible?

    I’m looking in to the JAvascript API Reference manual (version X) and found on page 44 some info on stamp annottation and the properties a stamp has like:
    Stamp properties => AP, author, borderEffectIntensity, borderEffectStyle,
    contents, creationDate, delay, hidden, inReplyTo, intent, lock,
    modDate, name, noView, opacity, page, popupOpen, popupRect,
    print, readOnly, rect, refType, rotate, seqNum, strokeColor,
    style, subject, toggleNoView, type

  14. Matt Parfitt says:

    Hi,

    I followed the instructions for creating a dynamic stamp like the ExhibitandCase. However the stamp I created won’t open the javascript window before the stamp is placed and so I can’t change the text fields. When I use the ExhibitandCase stamp on a pdf document the javascript opens so it must e something in my stamp that isn’t right but for the life of me I can’t see where. Any chance you might be able to help me please?

  15. Karl Heinz Kremer says:

    Matt, look for the internal stamp name and make sure that you have a unique name, but also that you check for the correct name in the stamp JavaScript code.

  16. Linda says:

    Awesome help – created a stamp for our accounting department for coding invoices – still have to type the information but it is much easier than printing, manual stamping and writing in the coding. Thanks so much for all the tips

  17. Sabrina says:

    Which Acrobat do I need to create my own stamp? Adobe Standard or Pro?

  18. Karl Heinz Kremer says:

    Sabrina, you can create stamps in either Pro or Standard. Pro however has better tools to deal with the process involved for dynamic stamps, whereas you may have to write a few JavaScript tools for Standard to get the same behavior (e.g. JavaScript console and page template support). If you just want to create static stamps, then it does not matter: You can use either.

  19. Ellie says:

    When I try to run the code in Adobe Acrobat Standard XI, I get the error, event.source is null. Help!!

  20. Karl Heinz Kremer says:

    Ellie, this will only work if you are actually placing a stamp. In any other case, the event.source property will not be set correctly.

  21. Lulu says:

    I have one stamp with two fields. I will like to get one pop up with two input sections and I will like the information that I input to show up on the stamps comments as a comment. Is this possible?

  22. Karl Heinz Kremer says:

    Lulu, you can do this using a custom dialog in Acrobat’s JavaScript. See here for more information and sample code: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2Fapp_methods.htm%23TOC_execDialogbc-11&rhtocid=_6_1_8_6_1_10

  23. Phillip says:

    Hi Karl, I’m having some trouble with a dynamic stamp,. Have been reading your blogs for many hours over a few days. I have dynamic stamps that work fine. I have created one from scratch. I have copied the JS from a good one. Problem is it half works. It gets date and time but can’t find the author part, even though it works on a stamp on the same page. Can you help?

  24. Karl Heinz Kremer says:

    Phillip, the first thing you should do is to check the JavaScript console for errors. If you find errors, go from there. If you need my professional help, feel free to get in touch with me via email (my email address is on the “About” page).

  25. Peter says:

    Hi Karl
    Is there any possibillity to create them stamps in Adobe on iPad like this?
    I’ve found nothing helpful in www.

    https://c.web.de/@277457458585146729/rR7lW6ZjRGCxes417R3fUg

    Sincerely
    Peter

  26. Karl Heinz Kremer says:

    Peter, as far as I know, you cannot use custom stamps (or a lot of other interactive content) in mobile PDF viewers.

  27. Jan says:

    I followed all of the steps. I would like a dialog box to pop up so that the user can enter a general ledger account name when approving an invoice. I followed the steps above but the resulting stamp does not launch a dialog box, and the name and date field does not update to the user identity. Instead it says, ‘by foozle at 8:50 Aug 26, 2004″ which is just the example. I made sure the java script references the original stamp name of “Approval stamp”
    How do I get the dialogue box to pop up?

  28. Karl Heinz Kremer says:

    Jan, adding a dialog to a stamp is not trivial. For a simple one field approach take a look at Thom’s tutorial here: https://acrobatusers.com/tutorials/dynamic_stamp_secrets/
    For more elaborate dialogs, you will have to use the execDialog() function in Acrobat’s JavaScript. You can look at sample code in the function’s description in the API documentation: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2Fapp_methods.htm%23TOC_execDialogbc-11&rhtocid=_6_1_8_6_1_10
    If this sill does not help, I would recommend getting Thom’s book. A last option would be to hire somebody to create the stamp for you (or to help you fix your stamp). I try to make as much information available as possible, but I do run a consulting business, so for cases that are not completely covered in my blog posts, feel free to send me an email for a quote.

  29. Jamie says:

    Hi Karl,

    I’m trying to create a stamp that has text fields that can be edited. That way a user can place the stamp in their document, add in a description, amount and their name. I want these field to be editable after they’ve been filled out. Right now, using varAsk I’m able to create a popup when the stamp is placed, but it can’t be edited afterwards. Is there script that creates a stamp that has editable fields?

    Thank you,

  30. Karl Heinz Kremer says:

    Jamie, that is not how PDF stamps work. Once they are placed, they cannot be edited anymore. All edits have to be made before the stamp is placed.

Leave a Reply

Your email address will not be published. Required fields are marked *