Skip to main content
CarlosCanto
Community Expert
Community Expert
May 29, 2012
Question

Introducing: Insert Page Numbers v 2

  • May 29, 2012
  • 22 replies
  • 45044 views

Hi Everyone, back by popular demand, here's version 2. It now has options for inserting Date, Time, Full Name, and Document Name.

tip: you don't have to click on the "insert" buttons, you can type directly in the input box, for example, type:

Page *page* of *pages* to get Page 1 of 3

download

questions/comments? let me know

enjoy,

CarlosCanto

22 replies

April 12, 2017

this is amazing! thank you! I have a question, and sorry if it has been asked before... can you select which page number you would like it to start from. I have split my document into many files, as it's huge and i don't want to have to wait so long to save it each time, so e.g.  I need the second file to start from page 15, the third file to start from 25 etc
No worries if not.
Thanks again

CarlosCanto
Community Expert
Community Expert
April 14, 2017

yes, it's possible. I'll add that functionality as soon as I have a chance.

stay tuned,

Carlos

Zivago
Participant
February 3, 2016

Great script, many thanks!

Question: can somebody help what part of the script controls page number/text font size, color & type or how I could add it to the script? Or point me to some good tutorials how to learn to do this.

CarlosCanto
Community Expert
Community Expert
February 5, 2016

you're welcome, look here for info on to get started with illustrator scripting

Illustrator Scripting | Adobe Developer Connection

Known Participant
December 29, 2015

Awesome Script Carlos! I use it to quickly label pages with different designs for presentation. Saves tons of time.

Participant
March 18, 2015

FYI, it works perfectly in CC 2014.

Having it create a unique layer for the numbering is brilliant! It makes it dead-simple to select, move and format them all at the same time.

Many, many thanks for this!

Participant
October 30, 2014

Hello Carlos, congratulations for the great work !! I

try to ask a question and I am attaching a picture.

Do you think i can enter the file name and the date on a identification form like the one in the picture, where you see filename dates field?
thank you !!!!!!

Known Participant
October 30, 2014

I guess you would have to make a function to position *Filename* and an other one to position *Date*.

Participant
April 3, 2014

Hi, 1 question here. I'd like to know how do I add pagination to my work, which has 8 artboards? Since this script only add pagination from 1-100, i couldn't find any solution to allow the script to add page 100 and above. I believe I just need to modify a thing or two in the script but i'm totally noob when it comes to computer language LOL. Pls help.

EDIT: Oh never mind. It turns out that it was quite easy to indentify which part I should modify to add page 100 and above. Problem Solved.

Message was edited by: farleonhart

Participant
January 15, 2014

You sir, are amazing awesome.  Thank you!

Participating Frequently
November 27, 2013

Um, how do I install this?

Lena Shore
Participating Frequently
November 27, 2013

First - use the download link at the top of the page in the first post (http://pastebin.com/UvNKrZgP)

Then place it here: Applications --> Adobe Illustrator --> Scripting --> Page Numbering (this folder includes both the downloaded files)

Known Participant
December 5, 2013

Didn't work for me, I get this error:

I'm on a Mac running CS6.

Lena Shore
Participating Frequently
October 17, 2013

You are absolutely the BOMB DIGGITY! Thank you SO SO much for this. This is something that I have wished for over and over when working on logo designs.

*virtual warm chocolate chip cookies*

(:

CarlosCanto
Community Expert
Community Expert
October 17, 2013

thanks Lena

Known Participant
November 20, 2013

Great job! nevertheless, I dared to insert a dirty modification (not a programer myself) to allow user insert page range and first number (for those cases in which the document's got  front page, index, etc), copied bellow.

#target illustrator

//#targetengine main

// script.name = insertPageNumbers_v2.jsx; // works with CS4 & CS5 &C S6

// script description = Inserts page numbers (or any other text) to all artboards in the active document;

// script.required = at least one open document

// script.parent = CarlosCanto // 5/25/12;

// script.elegant = false;

// script.updates = added options to insert Date, Time, Full File Name, & File Name;

//                                      added a button to clear previous entered data;

//                                       dialog stays open, to be able to input data in multiple locations

//                                       only one layer is created on multiple runs

// Notes: The script creates a new layer (Page Numbers) then adds a text frame per Artboard that act as footer or header text.

//              Its primary function is to insert Page Numbers, but it could be used to insert any other kind of information.

if (app.documents.length > 0) // continue if there's at leat one document open

    {

                // start building User Interface

                var win = new Window("dialog","mTools - Insert Page Numbers v 2");

                var panelMargins = win.add("panel", undefined, "Margins");

                var lblMargins = panelMargins.add("statictext",undefined,"How far from the edge:");

                var txtMargins = panelMargins.add("edittext",undefined, 0.25);

                var lblUnits = panelMargins.add("statictext",undefined,"inches");

                var panelLocation = win.add("panel", undefined, "Location");

                var radTop = panelLocation.add("radiobutton",undefined,"Top");

                var radBottom = panelLocation.add("radiobutton",undefined, "Bottom");

               

                    var trgtPages = win.add("panel", undefined, "Target Pages");

                    var lblfrstP = trgtPages.add("statictext",undefined,"From:");

                    var frstP = trgtPages.add("edittext",undefined, 1);

                    var lbllstP = trgtPages.add("statictext",undefined," - To:");

                    var lstP = trgtPages.add("edittext",undefined,app.activeDocument.artboards.length);

                    var pNlabel = trgtPages.add("statictext",undefined,"First Number");

                    var pN = trgtPages.add("edittext",undefined, 1);

                var panelAlignment = win.add("panel", undefined, "Alignment");

                var radLeft = panelAlignment.add("radiobutton",undefined,"Left");

                var radCenter = panelAlignment.add("radiobutton",undefined, "Center");

                var radRight = panelAlignment.add("radiobutton",undefined, "Right");

                var panelFooter = win.add("panel", undefined, "Text to insert");

                var grpPages = panelFooter.add("group");

                var btnPage = grpPages.add("button",undefined,"P");

                var btnPages = grpPages.add("button",undefined,"Ps");

                var btnDate = grpPages.add("button",undefined,"D");

                var btnTime = grpPages.add("button", undefined, "T");

                var btnFullName = grpPages.add("button", undefined, "fFn");

                var btnFile = grpPages.add("button", undefined, "Fn");

                var txtFooter = panelFooter.add("edittext"); //,undefined, "[Type text to insert here]");

                var btnClear = panelFooter.add("button", undefined, "C");

                btnPage.size = btnPages.size = btnDate.size = btnTime.size = btnFullName.size = btnFile.size = btnClear.size = [31,24]; // on Mac [31, 21] = round buttons, [31,24] = square buttons

                var btnOk = win.add("button", undefined, "Ok");

                radRight.value = radBottom.value = true;

                win.alignChildren = panelFooter.alignChildren = "fill";

                btnClear.alignment = "left";

                panelMargins.spacing = 3;

                panelMargins.orientation = panelLocation.orientation = panelAlignment.orientation = "row";

              

                win.helpTip = "\u00A9 2012 Carlos Canto";

         btnOk.helpTip = "Press Esc to Close";

                btnPage.helpTip = "Adds *page* keyword, it represents a single page";

                btnPages.helpTip = "Adds *pages* keyword, it represents total number of pages";

                btnDate.helpTip = "Adds *date* keyword, it represents today's date";

                btnTime.helpTip = "Adds *time* keyword, it represents current time";

                btnFullName.helpTip = "Adds *fname* keyword, it represents Full File Name (including path)";

                btnFile.helpTip = "Adds *file* keyword, it represents File Name";

                btnClear.helpTip = "Clears input text area";

                txtFooter.helpTip = "Type \r\t'Page *page* of *pages*' \rto get \r\t'Page 1 of 3' \rfor example";

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

                // text place holder by Jongware / Marc Autret

                var wgx = win.graphics;

                var grayPen = wgx.newPen(wgx.PenType.SOLID_COLOR,[.67,.67,.67], 1);

                txtFooter.onDraw = function(/*DrawState*/)

                {

                        var gx = this.graphics;

                        gx.drawOSControl();

                        this.text || this.active || gx.drawString("[Type text to insert here] Press Esc to close", grayPen, 0, 0);

                };            

              

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

                                                btnOk.onClick = function(){

                            if (txtFooter.text != "")

                                                        doSomething(); // call main function

                                                        //win.close(); // close when done

                                                 }

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

              

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

                                                btnClear.onClick = function(){

                                                        txtFooter.text = ""; // call main function

                                                        //win.close(); // close when done

                                                 }

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

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

                                                btnPage.onClick = function(){

                                                        footer("*page*");

                                                 }

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

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

                                                btnPages.onClick = function(){

                                                        footer("*pages*");

                                                 }

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

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

                                                btnDate.onClick = function(){

                                                        footer("*date*");

                                                 }

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

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

                                                btnTime.onClick = function(){

                                                        footer("*time*");

                                                 }

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

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

                                                btnFullName.onClick = function(){

                                                        footer("*fname*");

                                                 }

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

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

                                                btnFile.onClick = function(){

                                                        footer("*file*");

                                                 }

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

                                                win.center();

                                                win.show();

                                              

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

                function footer (page) //

                        {

                                txtFooter.text = txtFooter.text + page;

                        }

                function doSomething()

                        {

                                //alert("I'm doing something");

                                var idoc = app.activeDocument;

                                try {

                                        var ilayer = idoc.layers["Page Numbers"];

                                } catch(e) {

                                        var ilayer = idoc.layers.add();

                                        ilayer.name = "Page Numbers";

                                }

                                var pages = idoc.artboards.length; // number of artboards

                                var datee = getdate ();

                                var timee = gettime ();

                                var fname = idoc.path == '' ? "Full Name: <unsaved document>" : idoc.fullName;

                                var file = idoc.name;

                              

                                var footerPages = (txtFooter.text).replace("*pages*",pages);

                                //$.writeln(msg);

                                footerPages = footerPages.replace("*pages*",pages); // replace the "*pages*" keyword with the actual number fo pages (artboards)

                                footerPages = footerPages.replace("*date*",datee);

                                footerPages = footerPages.replace("*time*",timee);

                                footerPages = footerPages.replace("*fname*",fname);

                                footerPages = footerPages.replace("*file*",file);

                              

                                var margins = Number(txtMargins.text)*72; // get margins in points

                                //$.writeln(margins);

  var n =Number(pN.text)-1;

                                                                      

                                for (i = Number(frstP.text)-1; i<Number(lstP.text); i++) // loop thru all artboards, and add input text from UI

                               

                                        {

                                                footerPage = footerPages.replace("*page*",n+1); // replace "*page*" keyword with the actual page Number

                                      

                                                var itext = ilayer.textFrames.add();

                                                itext.contents = footerPage; //"page 1 of 1";                         

                                                var fontSize = itext.textRange.characterAttributes.size;

                                              

                                                var activeAB = idoc.artboards;

                                                var iartBounds = activeAB.artboardRect;

                                              

                                                var ableft = iartBounds[0]+margins;

                                                var abtop = iartBounds[1]-margins;

                                                var abright = iartBounds[2]-margins;

                                                var abbottom = iartBounds[3]+margins+fontSize;

                                              

                                                var abcenter = ableft+(abright-ableft)/2;

                                                              

                              

                                                if (radRight.value == true)

                                                        {

                                                                //var msg = "right";

                                                                itext.left = abright;

                                                                itext.textRange.paragraphAttributes.justification = Justification.RIGHT;

                                                        }

                                                else if (radCenter.value == true)

                                                        {

                                                                //var msg = "center";

                                                                itext.left = abcenter;

                                                                itext.textRange.paragraphAttributes.justification = Justification.CENTER;

                                                        }

                                                else

                                                        {

                                                                //var msg = "Left";

                                                                itext.left = ableft;

                                                                itext.textRange.paragraphAttributes.justification = Justification.LEFT;

                                                        }

                                                if (radTop.value == true)

                                                        {

                                                                //var msg = "top";

                                                                itext.top = abtop;

                                                        }

                                                else

                                                        {

                                                                //var msg = "bottom";

                                                                itext.top = abbottom;

                                                        }

                                                    n=n+1;

                                        } // end for loop thru all artboards

                                app.redraw();

                        } // end function doSomething();

     }

else

    {

        alert ("there's no open documents");

    }

function getdate() {

        var date = new(Date);

        var m = date.getMonth()+1;

        var d = date.getDate();

        var y = date.getFullYear();

        var datemdy = m+"/"+d+"/"+y;

        return datemdy;

//alert(date);

//alert(m+"/"+d+"/"+y);

}

function gettime() {

        var time = new(Date);

        var hours = time.getHours();

        var minutes = time.getMinutes();

        if (minutes < 10){

                minutes = "0" + minutes

        }

        if(hours > 11){

                ampm = "PM";

        } else {

                ampm = "AM";

        }     

        var curtime = hours + ":" + minutes + " " + ampm;

        return curtime;

}

Participant
June 23, 2012

Hey Carlos I made a change to the time function to display in 12-hour format hope that is alright, and I wanted to post it in case others would like to use it as well.

function gettime() {

          var time = new(Date);

          var hours = time.getHours();

          if(hours > 11){

                    ampm = "PM";

          } else {

                    ampm = "AM";

          }

              if(hours > 12){

                  hours = hours - 12;

          }

          var minutes = time.getMinutes();

          if (minutes < 10){

                    minutes = "0" + minutes

          }

          var curtime = hours + ":" + minutes + " " + ampm;

          return curtime;

}

CarlosCanto
Community Expert
Community Expert
June 24, 2012

no problem, thanks for posting

Participant
July 9, 2012

Carlos,

Your Page Numbering Script is PHENOMINAL!!!

It works flawlessly in CS6.

Question: How can one alter the font style, weight, size, color, etc of the page numbering text prior to it being populated into the artboards?

Would also be beneficial to have the dates appear in different formats, examples:

July 9, 2012

07.09.2012

07/09/2012

7/9/2012

7/9/12

2012.07.09

Thank you for taking the time to create this.

-Tory