Skip to main content
CarlosCanto
Community Expert
Community Expert
May 29, 2012 7:58 PM UTC
Question

Introducing: Insert Page Numbers v 2

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

67 replies

Apr 12, 2017 12:41 AM UTC

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

Translate
CarlosCanto
Community Expert
Community Expert
Apr 14, 2017 4:44 AM UTC

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

stay tuned,

Carlos

Translate
Zivago
Participant
Feb 3, 2016 2:22 PM UTC

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.

Translate
CarlosCanto
Community Expert
Community Expert
Feb 5, 2016 7:24 AM UTC

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

Illustrator Scripting | Adobe Developer Connection

Translate
Known Participant
Dec 29, 2015 4:47 PM UTC

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

Translate
Participant
Mar 18, 2015 5:40 AM UTC

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!

Translate
Participant
Oct 30, 2014 8:48 AM UTC

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 !!!!!!

Translate
Known Participant
Oct 30, 2014 9:29 AM UTC

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

Translate
Participant
Apr 3, 2014 2:34 AM UTC

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

Translate
Participant
Jan 15, 2014 8:13 PM UTC

You sir, are amazing awesome.  Thank you!

Translate
Participating Frequently
Nov 27, 2013 2:28 PM UTC

Um, how do I install this?

Translate
Lena Shore
Participating Frequently
Nov 27, 2013 2:46 PM UTC

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)

Translate
Known Participant
Dec 5, 2013 7:43 PM UTC

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

I'm on a Mac running CS6.

Translate
Lena Shore
Participating Frequently
Oct 17, 2013 1:11 PM UTC

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*

(:

Translate
CarlosCanto
Community Expert
Community Expert
Oct 17, 2013 2:40 PM UTC

thanks Lena

Translate
Known Participant
Nov 20, 2013 11:10 AM UTC

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;

}

Translate
Participant
Jun 23, 2012 5:43 PM UTC

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;

}

Translate
CarlosCanto
Community Expert
Community Expert
Jun 24, 2012 3:06 AM UTC

no problem, thanks for posting

Translate
Participant
Jul 9, 2012 5:59 AM UTC

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

Translate