1

I am completely a novice at this, and borrowed part of a script from a sample online.

I am working a stamp with a dialogue box prompting for the date, and defaulting to the current date if no response. I have gotten it to display the dialogue box and the default date. But, the results don't end up on the stamp. Could someone please assist on resolving the issues?

if(event.source.forReal && (event.source.stampName == "#2Nw2jMn7S5l9QIPW-WGOHB"))
{
   var rgEmpty = /^\s*$/;
   var cDate = null;
   var cDfltDate = null;
   if((event.value != null)  && !rgEmpty.test(event.value) && util.scand("mmm dd yyyy",event.value))
      cDfltDate = event.value;
   else
      cDfltDate = util.printd("mmm dd yyyy",new Date());
   while((cDate==null) || rgEmpty.test(cDate) || (null == util.scand("mmm dd yyyy",cDate)))
   {
       cDate = app.response({cQuestion:"Please Enter the Date",
                             cTitle:"Stamp Date Entry",
                             cDefault:cDfltDate ,
                             cLabel:"Date:"
                           });
       if((cDate==null) || rgEmpty.test(cDate) || (null == util.scand("mmm dd yyyy",cDate)))
       {
          app.alert("Please enter date as \"mmm dd yyyy\"\n\nEx: Apr 15 2020",1);
          if(cDate != null)
            cDfltDate = cDate;
       }
   }
}

Also, I would like to distribute the final stamp to my coworkers as a template rather than them creating the script. Can I share the stamp pdf, and have them create one off my template without them having to modify the script?

Thank you!

Jguy
  • 583
  • 1
  • 11
  • 33
Javy
  • 11
  • 1

2 Answers2

0

First take a look at the following; https://acrobatusers.com/tutorials/dynamic_stamp_secrets

1) You should have a separate pdf file, that is the stamp file. This file can then be distributed to your coworkers if they copy the stamp file in the correct location, to find out the correct location run following code;

app.getPath ("app", "stamps");
app.getPath ("user", "stamps");

2) This stamp file should contain "fields", these fields can be filled in by a script that is attached to the stamp file, so you only need to distribute the stamp file that includes the script.

3) In your script you don't have a statement event.value = ...; if this is linked to a field it will fill in the field with the inputted date or current date.

Hope this is a help.

0

Thank you! I was able to solve the issue with assistance on another thread. Here is the last post there:

IT WORKS!!!

The date is required in oder to be official, and this specific format is also required. So, I think the exit of simply clicking OK is good enough because it gives a default date automatically.

Last thing to test is that an end user can just copy it directly into the stamps folder and start using it. I will test that out this morning when someone is available and follow up.

Thank you for your help!

Here is the code that worked:






        console.println("Stamping:" + event.source.StampName);

        if(event.source.forReal && (event.source.stampName == "#StampTemplate"))
        {
           var rgEmpty = /^\s*$/;
           var cDate = null;
           var cDfltDate = null;
           if((event.value != null)  && !rgEmpty.test(event.value) && util.scand("mmm dd yyyy",event.value))
              cDfltDate = event.value;
           else
              cDfltDate = util.printd("mmm dd yyyy",new Date());
           while((cDate==null) || rgEmpty.test(cDate) || (null == util.scand("mmm dd yyyy",cDate)))
           {
               cDate = app.response({cQuestion:"Please enter date as \"mmm dd yyyy\"\n\nFor Example: Apr 15 2020",
                                     cTitle:"Stamp Date Entry",
                                     cDefault:cDfltDate ,
                                     cLabel:"Date:"
                                   });
               if((cDate==null) || rgEmpty.test(cDate) || (null == util.scand("mmm dd yyyy",cDate)))
               {
                  app.alert("Please enter date as \"mmm dd yyyy\"\n\nFor Example: Apr 15 2020",1)
               }
               else
                  event.value = cDate;
               }
        }




Javy
  • 11
  • 1