6 Replies Latest reply on Jun 25, 2015 10:43 AM by dunnerca

    Javascript in Dynamic Stamp Won't Execute

    dunnerca Level 1

      I have followed directions to create a dynamic stamp that asks for a reference number.  I went into create a custom stamp, chose the stamp image file, saved it to the Dynamic category with a unique name, opened the stamp file from the "user\AppData\Roaming\Acrobat\11.0\Stamps" folder, created a text box, input the custom calculation script, and saved the file.

       

      The javascript executes when creating the dynamic stamp.  However, after saving the stamp and then using it on a PDF file, the stamp shows up but the script doesn't execute.  I just get the image.  I do not get the text box that I created nor does the script run that asks for input.  Anything obvious I should be watching for?  Here is the script that I entered (which I copied and amended for my intended use):

       

      var cResponse = app.response({

      cQuestion: "Enter the working paper reference",

      cTitle: "WP Ref:",

      cLabel: "Working paper ref:"

      });

      if (cResponse == null) {

      event.value = "*INVALID*";

      }

      else

      event.value = cResponse;

       

      Many thanks!

        • 1. Re: Javascript in Dynamic Stamp Won't Execute
          George_Johnson MVP & Adobe Community Professional

          The code should be something like this:

           

          // Custom calculation script for text field on stamp page

          if (event.source && event.source.forReal && event.source.stampName == "#Your stamp name goes here") {

           

              var cResponse = app.response({

                  cQuestion: "Enter the working paper reference",

                  cTitle: "WP Ref:",

                  cLabel: "Working paper ref:"

              });

           

              if (cResponse == null) {

                  event.value = "*INVALID*";

              } else {

                  event.value = cResponse;

              }

           

          }

           

           

          The important piece you have to determine is the name of the stamp in your stamp file and replace "#Your stamp name goes here" in the code above with the correct name. The stamp name is the name of the template page of the stamp in the stamp file. It is everything before the "=" character in the template name. Post again if you have trouble determining it and let us know what version of Acrobat yo're using. Also, see if there are any errors reported in the JavaScript console by pressing Ctl+J.

          • 2. Re: Javascript in Dynamic Stamp Won't Execute
            dunnerca Level 1

            Thanks for your response, George.  I am confused by your instruction that the "stamp name is the name of the template page of the stamp in the stamp file".  The instructions that I've read so far say that this is the file name of the stamp file in the "...\Roaming\Adobe\Acrobat\11.0\Stamps" folder.  Your instructions seem to say that the script should refer to a name within that file.  Am I reading that correctly?

             

            I am using Adobe XI Pro on a Windows 7 machine.  I can get into the JavaScript console

            • 3. Re: Javascript in Dynamic Stamp Won't Execute
              George_Johnson MVP & Adobe Community Professional

              No, it is not the file name. A stamp file can contain more than one stamp, each on a separate page. In Acrobat 11 you'd open the stamp file and select:

               

              Tools > Document Processing > Page Templates

               

              and you should see a list of templates in your stamp file.

              • 4. Re: Javascript in Dynamic Stamp Won't Execute
                Karl Heinz Kremer Adobe Community Professional

                George got you on the right track. There is actually a bit more to the page template name than is obvious. The template name has to be of the following format:

                 

                #InternalName=Display Name

                 

                You would use the internal name in your code, and the Display Name is what gets displayed in Acrobat's stamp user interface.

                 

                The '#' prefix is important for dynamic stamps, it forces Acrobat (or Reader) to run your stamp script every time you place  stamp. So, in your case, one could use one string for the first stamp that gets placed, and a different string for the second stamp. You want to run your script every time the stamp gets placed. That is what the '#' triggers. If you are new to dynamic stamps, you may want to review Thom Parker's excellent introduction here: https://acrobatusers.com/tutorials/dynamic_stamp_secrets

                 

                A while ago I wrote a tutorial about how to create a stamp from scratch. This is not about dynamic stamps, but the basic steps are the same: http://khkonsulting.com/2014/03/creating-pdf-stamp-file-scratch/

                • 5. Re: Javascript in Dynamic Stamp Won't Execute
                  dunnerca Level 1

                  Thanks George.  Yes, I see it now.  I have a few other pressing things so I'll work on this later this evening and let you know how it goes.

                  • 6. Re: Javascript in Dynamic Stamp Won't Execute
                    dunnerca Level 1

                    Thanks for the clarification.  I've opened your tutorial and will have a look at it in relation to what I'm trying to accomplish.  I also went through Thom Parker's article but obviously I've missed something somewhere.  I'll have another go at it.