6 Replies Latest reply on Jan 8, 2016 1:49 AM by try67

    Script for adding text to a specified range of pages?

    CNCJohnnie

      Hello,

       

      I have a script that adds a line of text to all pages in a PDF.  I am looking to see if anyone has an example or advice of how to have the script ask for user input for the text and to enter a page range for the script to act on.

       

      Thank you

       

      John C

        • 1. Re: Script for adding text to a specified range of pages?
          try67 MVP & Adobe Community Professional

          Post the script you have and we'll help you adjust it...

          • 2. Re: Script for adding text to a specified range of pages?
            CNCJohnnie Level 1

            Thank you try67,

             

            Below is the script.  I figured out how to prompt the user.  Now I am working on how to prompt the user to select a page range and have the script only run on the specified page range.

             

            Thank you

             

            John C

             

            // note box broken

            //  Lock page data after signature is clicked???

            // fix print button to print to PDF

             

                        var dialogTitle = "Enter the most common drawing list revision level.";

                        var defaultAnswer = "—";

                        var reply = app.response("Enter the most common drawing list revision level.",                                                   dialogTitle, defaultAnswer);

             

            //Create page forward on the SL: text

            var inch = 72;

                        for (var p = 0; p < this.numPages; p++) {

                                   

                                    var f = this.addField("NextPage", "button", p, [242, 610, 290, 633] )//[242, 610, 290, 633]

                                    f.setAction("MouseUp", "this.pageNum++");

                                    f.delay = true;

                                    f.borderStyle = border.s;

                                    f.highlight = "push";

                                    f.textSize = 8;                 // Auto-sized

                                    //f.textFont = font.ZapfD

                                    f.buttonSetCaption("Next Page")      //

            f.textFont = font.Times

            f.fillColor = color.white;

                                    f.delay = false;

            f.strokeColor = color.red;

            getField("NextPage").display = display.noPrint

             

                        var ff = this.addField("PreviousPage", "button", p, [192, 610, 240, 633] )//[242, 610, 290, 633]

                                    ff.setAction("MouseUp", "this.pageNum--");

                                    ff.delay = true;

                                    ff.borderStyle = border.s;

                                    ff.highlight = "push";

                                    ff.textSize = 8;                 // Auto-sized

                                    //f.textFont = font.ZapfD

                                    ff.buttonSetCaption("Previous Page")      //

            ff.textFont = font.Times

            ff.fillColor = color.white;

                                    ff.delay = false;

            ff.strokeColor = color.red;

            getField("PreviousPage").display = display.noPrint

             

            //Print document to PDF button

                 //var w = this.addField("print", "button", p, [242, 693, 320, 663] )

                  // w.buttonSetCaption("PRINT TO PDF")

                  //  w.strokeColor = color.red

                  //  w.highlight = "push";

                   // getField("print").display = display.noPrint

                   

            //w.setAction("MouseUp", "this.getPrintParams()");

                 

                 //    w.fileName = "/c/temp/myDoc.pdf";

            //          w.printerName = "Adobe PDF";

            //          this.print(w);

             

             

            //******************************************************************************

            //var pp = this.getPrintParams();

                        //pp.fileName = "/c/temp/myDoc.pdf";

                        //pp.printerName = "Adobe PDF";

                        //this.print(pp);

            //******************************************************************************

             

             

             

             

            // Insert ACT QA Stamp PDF as button

             

                var name = "act_"+p;

                var act = this.addField(name, "button", p, [492, 681, 525, 648]);

            //act.strokeColor = color.red;

            act.buttonPosition = position.iconOnly

                    var retn = act.buttonImportIcon("/C/temp/ACT A7 QA Stamp/ACT A7 QA Stamp.pdf");

                    if ( retn != 0 ) app.alert("Icon not imported");

             

             

            ///DL = DWG Rev Drop Down

                            var name = "dlrev_"+p;

                            //var type = "combobox";

                            var location = [247, 602, 303, 590];// [242, 602, 300, 590]

                            var dlrev = this.addField(name, "combobox", p, location);

            dlrev.editable = true;

            dlrev.setItems( ["   DL Rev:", "Dwg Rev:"]);

            dlrev.textSize = 9;

            dlrev.editable = false;

            dlrev.fillColor = color.white;

            dlrev.textFont = font.TimesB;

                        

             

            //accept button for date

             

            var g = this.addField("accept_" +p, "button", p,[292, 610, 360, 633] );

            1. g.buttonSetCaption("APPROVE TRAVELER")

            getField("accept_" +p).display = display.noPrint

            getField("accept_" +p).fillColor = color.white;

            getField("accept_" +p).textFont = font.Times;

            getField("accept_" +p).highlight = "push";//************

             

              var i = this.addField("Date_"+p, "text", p, [525, 715, 580, 615]);//good date location

              i.readonly = true;

              i.textSize = 10;i.textFont = font.Times;

              i.userName = "Date"+p;

              i.readonly = true;

              i.textSize = 9;

              i.textFont = font.Times;

              //i.display = noPrint; 

            g.setAction("OnFocus", "var g = this.getField('Date_" + p + "'); g.value = util.printd('mm/dd/yy', new Date());");

              g.strokeColor = color.red;

             

             

            //combo box for REV level

                var name = "comborev_"+p;//

                var location = [302, 602, 328, 590];//[290, 602, 315, 588];

                    var revlevel = this.addField(name, "combobox", p, location);

            revlevel.editable = true;

            revlevel.setItems( ["—", "A", "B", "C", "D","E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]);

            revlevel.defaultValue = reply;

            revlevel.textSize = 10;

            revlevel.editable = true;

            revlevel.fillColor = color.white;

            revlevel.textFont = font.Times; 

                 

             

            1. this.resetForm();

             

             

            //combo box for Notes

                var name = "notes_"+p;

                var location = [373, 590, 538, 610];

                    var notes = this.addField(name, "combobox", p, location);

            notes.editable = true;

            notes.setItems( ["", "Traceability per quality assurance Plan QAP2296 Traceability", " ", " ", " "]);

            notes.textSize = 8;

            notes.editable = true;

                        notes.fillColor = color.white;

            notes.textFont = font.Times; 

            //notes.strokeColor = color.blue;

            getField("notes_"+p).display = display.noPrint

             

             

             

             

            //text box for Notes : set text to 9 and multi line

                var name = "N_"+p; // _"+p;

                var type = "text";

               

                var location = [373, 560, 538, 590];// [360, 560, 535, 590];

                var x = this.addField(name, type, p, location);

                    x.multiline = true;

                    x.textSize = 9;

                    x.textFont = font.Times;

                    x.charLimit = 70;  // only allow two lines of text ****************************************

                 //Traceability per quality assurance Plan "QAP2296 Traceability 

             

             

            }

            • 3. Re: Script for adding text to a specified range of pages?
              try67 MVP & Adobe Community Professional

              Let's simplify it a bit... Do you want the user to enter each page number to process or should it accept range(s) of pages? The latter is much more complex, of course.

              • 4. Re: Script for adding text to a specified range of pages?
                CNCJohnnie Level 1

                Ideally the user would be able to enter a page range ie pages 3-15.

                • 5. Re: Script for adding text to a specified range of pages?
                  try67 MVP & Adobe Community Professional

                  You'll need to process the user's input. What if they enter "3-15,12, 18-21"? What if they enter "1,2,3"? etc.

                  These are quite different and complex situations.

                  • 6. Re: Script for adding text to a specified range of pages?
                    try67 MVP & Adobe Community Professional

                    Let's say they only enter a starting page and and end page, though (such as "3-15").

                    You can process it like this:

                     

                    var userInput = app.response("Enter page range to process:");
                    var startPage = Number(userInput.split("-")[0])-1;
                    var endPage = Number(userInput.split("-")[1])-1;
                    for (var p=startPage; p<=endPage; p++) {
                        // place code here to add text to page p
                    }