Introducing: Insert Page Numbers

Adobe Community Professional ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

Hi all, about three weeks ago a user asked about something like this, I thought it was a good idea to have it scripted.

Have a use for it? Let me know if there are questions, bugs...

MTools_InsertPageNumbers.png

#target illustrator

// script.name = UI_insertPageNumbers.jsx; // works with CS4 & CS5

// 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 // 11/14/11;

// script.elegant = false;

// 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");

                    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 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,"Insert Page");

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

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

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

                    radRight.value = radBottom.value = true;

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

                    panelMargins.spacing = 3;

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

 

                    win.helpTip = "Coded by CarlosCanto";

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

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

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

 

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

                                                            btnOk.onClick = function(){

                                                                      doSomething(); // call main function

                                                                      win.close(); // close when done

                                                             }

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

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

                                                            btnPage.onClick = function(){

                                                                      footer("*page*");

                                                             }

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

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

                                                            btnPages.onClick = function(){

                                                                      footer("*pages*");

                                                             }

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

                                                            win.center();

                                                            win.show();

 

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

                    function footer (page) //

                              {

                                        txtFooter.text = txtFooter.text + page;

                              }

                    function doSomething()

                              {

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

                                        var idoc = app.activeDocument;

                                        var ilayer = idoc.layers.add();

                                        ilayer.name = "Page Numbers";

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

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

 

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

                                        //$.writeln(margins);

 

                                        for (i = 0; i<idoc.artboards.length; i++) // loop thru all artboards, and add input text from UI

                                                  {

                                                            footerPage = footerPages.replace("*page*",i+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;

                                                                      }

                                                  } // end for loop thru all artboards

                              } // end function doSomething();

     }

else

    {

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

    }

Views

67.5K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

I can't believe it. Works just great.

I don't susally do page layouts in Illustrator, but to number a set of logo proposals to send to the client this will come handy as well. Thanks so much.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

thanks Monika

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

Do you mind if I send the link for this thread to someone at Adobe?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

I don't mind, thanks

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 24, 2017 Jul 24, 2017

Copy link to clipboard

Copied

Many Thanks CarlosCanto

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

Hey Carlos

How do I use the script?

I did not notice a download link to where the script is located.

Paal Joachim

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

Paal,

All you do is open Applescript or Javascript, copy Carlos' text and paste it into your new script file. Save that in CS5's Scripts folder or wherever you want. When using the script you go to the file menu - Scripts - Other Scripts and navigate to your new script and viola!

Hope this helps

Jeff

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

Thanks Jeff!

I also received a reply from Carlos:

"Hi Paal, the script is the text in colors below the image, copy starting from "#target illustrator" all the way down to the last closing bracket "}", then open the ESTK or any text editor, paste it there and save it with a sugested name "UI_insertPageNumbers.jsx" or any other name. Make sure you save it with a "JSX" extension. Save it in you default "scripts" folder and it will show in the Illustrator "File->Scripts" menu, next time you restart illustrator."

I tested this out and here are some of my findings:

I pasted the code into the default TextEdit mac text editor. Format -> Make Plain Text. Saved it as a .jsx file.

Placed the file into Adobe Illustrator CS5 -> Scripting.

Reopened Illustrator. Opened a file (you need to open a file first). Looked in the File -> Scripts (it was not visible) -> Other Scripts and found the file.

A dialog box opens and you can test out how it works.

To get page numbers remove the text in the box and click Insert Page.

A follow up to this wonderful script.

What about changing the font and size of the page numbers?

Thank you for the script Carlos! Hopefully Adobe can purchase it from you and add to to the next version.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

Paal Joachim wrote:

[..]

A follow up to this wonderful script.

What about changing the font and size of the page numbers?

Perhaps Carlos can create a default paragraph style -- or lets the user select an existing one -- and apply that?

(Gosh Illy's Paragraph Style dialog is clunky. What's with that, they *still* Do Not Talk to InDesign's developers?)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

Hi jongware,

Perhaps Carlos can create a default paragraph style -- or lets the user select an existing one -- and apply that?

well, the script uses "the" default paragraph style. Selecting an existing paragraph style sounds doable, but wouldn't it be the same as selecting it in Illustrator?....Unless after applying it, the text gets out of place.

what do you think?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

It actually uses the default character style (at least in my test).

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 15, 2011 Nov 15, 2011

Copy link to clipboard

Copied

Hi Larry, thanks for checking. What takes precedence? character or paragraph? I think with Illustrator defaults, one is based on the other.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 15, 2011 Nov 15, 2011

Copy link to clipboard

Copied

Paragraph always takes precedence in AI. (Which is backwards compared to Indesign).

Honestly, due to limitations of both Character and Paragraph styles in Illustrator I'd strongly reccommend not including them. Once a style in Illustrator is set, there's absolutely no way to break the link to the style. Better to not have a style than a style you can't strip from the text in my opinion.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 15, 2011 Nov 15, 2011

Copy link to clipboard

Copied

thanks for the pointer Scott, I didn't know, I hardly ever use either one.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 16, 2011 Nov 16, 2011

Copy link to clipboard

Copied

Well it's certainly about time the programmer teams stop fighting and get their heads together to produce a coherent "suite" then!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 29, 2012 May 29, 2012

Copy link to clipboard

Copied

Hi guys, version 2 is out, find it here

http://forums.adobe.com/thread/1013711

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

What about changing the font and size of the page numbers?

I thought about it, but I figured there wouldn't be any difference in chosing options in my script than chosing options in Illustrator.....

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

You cn also go the the Utilities Folder in the Application Folder and use the Adobe Utilties>Extended Script Tool to complie the script by pasting ther as well and do a save as the .jsx is the dfault so not much thinking is required.

On the PC I am not sure where the Adobe Utilities Folder is located.

Here is a screenshot of the script utilitis UI

Screen Shot 2011-11-14 at 5.13.36 PM.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 14, 2011 Nov 14, 2011

Copy link to clipboard

Copied

Copy the above text. Open a text editor which can save a plain text file (or the Adobe ESTK [ExtendScript ToolKit]) and paste the text. Save it as a plain text file with a .jsx file extension. Move the file to Applications/Adobe Illustrator CS4 or CS5/Presets/en_US/Scripts and restart your AI app. This is an ExtendScript file and will not work in the AppleScript editor.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2014 Feb 24, 2014

Copy link to clipboard

Copied

Thank you so much, saved me lots of time!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 07, 2014 May 07, 2014

Copy link to clipboard

Copied

Thanks for this Carlos. The script works, however, I am unable to close the window as it has no close window button and so have to force quit Illustrator, thereby making it impossible to save what this wonderful script does. I'm on a Mac, using CS6. Any ideas how to close the script window after running it?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 07, 2014 May 07, 2014

Copy link to clipboard

Copied

you're welcome, press "Esc" key to close, sorry about not being clear enough.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 07, 2014 May 07, 2014

Copy link to clipboard

Copied

Doh! Sorry, didn't think of that. Works great! Thanks!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 07, 2014 May 07, 2014

Copy link to clipboard

Copied

you should use version 2 of the script, the link is 2 posts up above yours.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines