8 Replies Latest reply on Mar 6, 2015 2:38 PM by adfrench

    if/then statement for a field to not print content?

    adfrench

      Hi,

       

      I am using Adobe Acrobat Pro XI and would like to have a field not print its content if the form has not been saved since it was opened. I have 2 form fields in my document and below is the java script applied to them:

       

      //<Document-Level>

      //<ACRO_source>Init</ACRO_source>

      //<ACRO_script>

      /*********** belongs to: Document-Level:Init ***********/

      var f = this.getField("DateCreation");

      f.value = "COPY: this copy is for reference only and will expire 7 days from " + util.printd("mm-dd-yy", new Date()) + " or the saved date below, whichever occurs first";

       

      strMsg = "Saved on: " + util.printd("mm-dd-yy",this.modDate);

      this.getField("DateSaved").value = strMsg;

       

      //</ACRO_script>

      //</Document-Level>

       

      //<Document-Actions>

      //<ACRO_source>Document Will Save</ACRO_source>

      //<ACRO_script>

      /*********** belongs to: Document-Actions:Document Will Save ***********/

      strMsg = "  Saved on: " + util.printd("mm-dd-yy",new Date());

      this.getField("DateSaved").value = strMsg;

       

      //</ACRO_script>

      //</Document-Actions>

       

       

      The DateSaved field properties are set to "hidden but printable," but I also want the DateSaved field to NOT print its content if the document has not been saved since it was opened. Is this possible?

       

      Thank you for your help!

        • 1. Re: if/then statement for a field to not print content?
          JoelGeraci_Datalogics Level 3

          Use the doc "dirty" property to detect if the document has been modified since it was opened and then set then "display" property of the field accordingly.

          • 2. Re: if/then statement for a field to not print content?
            adfrench Level 1

            I'm unsure of how to incorporate the doc "dirty" property to detect if the document has been modified since it was opened. I couldn't figure it out by reading the info on "dirty" in the JavaScript for Acrobat API Reference.  My javascript experience is very limited. Thanks again for your help!

            • 3. Re: if/then statement for a field to not print content?
              try67 MVP & Adobe Community Professional

              Simple. If this.dirty is true, the document has been changed and not yet

              saved.

              • 4. Re: if/then statement for a field to not print content?
                adfrench Level 1

                So, the document won't be changing. A person opening the document will only have the option to print it or save as. If they choose to print the document, I don't want the DateSaved field to be displayed on the screen or when printed. However, if they choose to save as, I do want the DateSaved field to be displayed on screen and when printed.

                • 5. Re: if/then statement for a field to not print content?
                  try67 MVP & Adobe Community Professional

                  I don't understand what you mean... Just set the field to be non-printable ("Visible, but doesn't print" under Properties - General), and update it in the Did Save event.

                  • 6. Re: if/then statement for a field to not print content?
                    adfrench Level 1

                    In doing more research on this, I've found another way to accomplish my goal, however I'm still having some trouble with the coding. The following code works perfectly to compare 2 dates and then close the document if it is "expired."

                     

                    // Get Current Date

                    var curDate = new Date ();

                    // Get Final date

                    var finalDate = new Date ("03/02/2010");

                    // Compare Dates

                    if(finalDate.getTime() < curDate.getTime())

                    { // Past closing Date, expire document

                    var nButton = app.alert({

                    cMsg: "This document is no longer valid. Please view in VisualVault",

                    cTitle: "Document Control",

                    nIcon: 3, nType: 0

                    });

                    if ( nButton == 1 )this.closeDoc();

                    }

                    else

                      // Document is obscured by a opague watermark that covers all the pages

                      var ocgs = this.getOCGs();

                      for(var i=0;i<ocgs.length;i++)

                      {

                    if(ocgs[i].name == "Watermark")

                    break;

                      }

                      // Hide watermark so document can be seen 

                    ocgs[i].state= false;  

                    }

                     

                     

                    However, I need the “finalDate” to be the “curDate + 7 days” instead of an exact date, and I can’t figure out the right code for this. Thanks again for any help you can provide!

                     

                     

                     

                     

                     

                    • 7. Re: if/then statement for a field to not print content?
                      try67 MVP & Adobe Community Professional

                      Study the methods of the Date object and you'll figure it out: JavaScript Date Reference

                      • 8. Re: if/then statement for a field to not print content?
                        adfrench Level 1

                        Just in case someone out there goes through the same thing I did, below is the final working script that creates an app alert to state the document is expired and closes the document based on a comparison of two dates, whose values are stored in form fields. I copied all of the script from my document so you can see how the fields and document actions all work together. For the watermark portion of the script to work (see high-lighted script below), follow the instructions listed under the "Expire PDF on a Specific Date" on this website:  Basic Document Level (Document Open) Scripts.

                         

                        //-------------------------------------------------------------

                        //-----------------Do not edit the XML tags--------------------

                        //-------------------------------------------------------------

                        //<Document-Level>

                        //<ACRO_source>Init</ACRO_source>

                        //<ACRO_script>

                        /*********** belongs to: Document-Level:Init ***********/

                        var f = this.getField("DateCreation");

                        f.value = "COPY: this copy is for reference only and will expire 7 days from " + util.printd("mm-dd-yy", new Date()) + "";

                         

                         

                        strMsg = util.printd("mm-dd-yy", this.modDate);

                        this.getField("DateSaved").value = strMsg;

                         

                         

                        var startDate = util.scand("mm-dd-yy", this.getField("DatePlusSevenDays").value);

                        var endDate = util.scand("mm-dd-yy", new Date());

                        // Compare Dates

                        if(endDate > startDate)

                        { // Past closing Date, expire document

                        var nButton = app.alert({

                        cMsg: "This document is no longer valid. Please view in VisualVault",

                        cTitle: "Document Control",

                        nIcon: 3, nType: 0

                        });

                        if ( nButton == 1 )this.closeDoc();

                        }

                        else

                        { // allow document to be shown

                        // This part is optional, and just adds better security

                        // Document is obscured by a opague watermark that covers all the pages

                        var ocgs = this.getOCGs();

                        for(var i=0;i<ocgs.length;i++)

                        {

                        if(ocgs[i].name == "Watermark") break;

                        }

                        // Hide watermark so document can be seen

                        ocgs[i].state= false;

                        }

                         

                         

                        //</ACRO_script>

                        //</Document-Level>

                         

                         

                        //<Document-Actions>

                        //<ACRO_source>Document Will Close</ACRO_source>

                        //<ACRO_script>

                         

                        /*********** belongs to: Document-Actions:Document Will Close ***********/

                        this.dirty = false

                        //</ACRO_script>

                        //</Document-Actions>

                         

                        //<Document-Actions>

                        //<ACRO_source>Document Did Save</ACRO_source>

                        //<ACRO_script>

                         

                        /*********** belongs to: Document-Actions:Document Did Save ***********/

                        strMsg = util.printd("mm-dd-yy", new Date());

                        this.getField("DateSaved").value = strMsg;

                        //</ACRO_script>

                        //</Document-Actions>

                         

                         

                        //<AcroForm>

                        //<ACRO_source>DatePlusSevenDays:Calculate</ACRO_source>

                        //<ACRO_script>

                         

                        /*********** belongs to: AcroForm:DatePlusSevenDays:Calculate ***********/

                        event.value = "";

                        var DateSavedFormat = "mm-dd-yy";

                        if (this.getField("DateSaved").value != "") {

                        // Obtain the value for the date saved

                        var DateSaved = this.getField("DateSaved").value;

                        // convert date string to date object

                        var oDateSaved = util.scand(DateSavedFormat, DateSaved);

                        // Add 7 days from the saved date

                        // Establish one day variable for use in calculation

                        var sevenDays = 7 * 24 * 60 * 60 * 1000

                        // Use one day (x 7) to get 7 days from the saved date

                        // get the time in milliseconds from the date object and add 7 days

                        var DatePlusSevenDays = oDateSaved.getTime() + sevenDays;

                        // convert millisecond result to date object

                        var DatePlusSevenDays = new Date(DatePlusSevenDays);

                        // set the value of the field;

                        event.value = util.printd(DateSavedFormat, DatePlusSevenDays);

                        }

                        //</ACRO_script>

                        //</AcroForm>