×
Menu
Index

Adding Custom Scripts to Stamps

 

Adding Custom Scripts to Stamps that Invoke Entry Dialogue Boxes

 
Sometimes it is more convenient to have a dialogue box appear which allows the user to input the User Name and a specific date when applying a stamp to a document. By utilizing a Java script that is written invoke a user input dialogue box, it is possible to manually enter any User Name and Date each time the stamp is applied.
 
 
In the example below, we will modify the Java scripts used in the previous example "Adding PDF Form Fields to Stamps" to add the dialogue box functionality for user inputs. While many of the steps for field creation are the same, there are some additional details that need to be captured so that the Java scripts run correctly.
 
 
 
1.     Launch a PDF application that is capable of creating PDF forms and open the “DRAFT_COPY.pdf” stamp file that has the auto generated file name.
 
 
 
 
 
 
2.     To start forms editing select FORMS > ADD or EDIT FIELDS.
 
 
 
 
 
 
3.     Right-click on the “Text1” field and select “Properties”.
 
 
 
 
 
 
4.     Select the “Calculate” tab, choose the “Custom calculation script” radio button and then the associated “Edit” button. Enter the following script into the JavaScript Editor and select “OK” then “Close” Text Field Properties:
 
 
Text1 Java Script
 
if(event.source.forReal && (event.source.stampName == "ENTER_PAGE_TEMPLATE_ID_HERE"))
{
   var rgEmpty = /^\s*$/;
   var cName = null;
   var cDfltName = event.value;
 
   while((cName==null) || rgEmpty.test(cName))
   {
       cName = app.response({cQuestion:"Please Enter a Name",
                             cTitle:"CADzation Stamp Data Entry",   // Optional
                             cDefault:cDfltName,                // Optional
                             cLabel:"Name:"                  // Optional
                           });
 
       if((cName==null) || rgEmpty.test(cName))
       {
          app.alert("Please enter a Name",1);
          cDfltName ="";
       }
   }
 
   // Set Name Value
   event.value = cName;
          }
 
 
 
 
 
 
 
 
5.     Since this type of Java script code is dependent on the exact page in the PDF source file, it is necessary to discover and append the script with the “Page Template” ID in the PDF. Page Template ID’s vary from PDF to PDF and can be discovered by closing Forms Editing and selecting the “Page Templates” function.
 
Adobe Acrobat 9
 
ADVANCED > DOCUMENT PROCESSING > PAGE TEMPLATES
 
 
Adobe Acrobat 8
 
ADVANCED > FORMS > PAGE TEMPLATES
 
 
 
Highlight and copy all the characters from the beginning to the “=” sign. In the case for our example that would be:
 
     3f94238e-0acc-42e1-ad0f68e3daa86a8b
 
 
 
 
 
6.     Go back into Forms Editing and insert the “Page Template” ID into the Java script and replace the text “ENTER_PAGE_TEMPLATE_ID_HERE” with the actual ID “3f94238e-0acc-42e1-ad0f68e3daa86a8b” and be sure that it is enclosed in quotes as shown below.
 
 
 
 
 
7.     Repeat steps 4 thru 6 for the “Date1” field with the Java script provided below. The Java script for the “Date1” field is a different script than the “Text1” script. So, please only copy it from below.
 
Date1 Java Script
 
if(event.source.forReal && (event.source.stampName == "ENTER_PAGE_TEMPLATE_ID_HERE"))
{
   var rgEmpty = /^\s*$/;
 
   // Aquire Date Value,
   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:"CADzation Stamp Data Entry", // Optional
                             cDefault:cDfltDate ,           // Optional
                             cLabel:"Date:"             // Optional
                           });
 
       if((cDate==null) || rgEmpty.test(cDate) || (null == util.scand("mmm dd, yyyy",cDate)))
       {
          app.alert("Please enter date as \"mmm dd, yyyy\"\n\nEx: May 18, 2010",1);
          if(cDate != null)
            cDfltDate = cDate;
       }
   }
 
 
 
 
 
 
8.     Close Forms Editing, save the PDF file and Exit.
 
 
 
 
9.     Launch AcroPlot Matrix and test the stamp. When the stamp is applied the first dialogue box that appears allows the user to accept the system date or enter a different one:
 
 
 
 
 
 
The next dialogue box requests a User Name. Any text can be entered which will be applied to the stamp.
 
 
 
 
 
 
Below is how the stamp will appear when applied to the document. Please remember that when a stamp with custom scripts is use, the text cannot be modified after the stamp is place in the document. The stamp text is rendered static when applied. If you need to make changes to the information that was entered at the time the stamp was applied, then you will need to delete the stamp and enter the corrected information with a new one.
 
 
 
 
Done.