Skip navigation
Currently Being Moderated

how do i place a textframe central to the artboard

Apr 15, 2012 12:38 PM

Tags: #illustrator #cs5 #help #text #javascript #artboard #align_text #textframes

This is my very first attempt at a script:

all tips are greatfully recieved





* this script will prompt  the user for a file name and location and then

    save the current file as a .pdf with secure save options*/

var curDoc = app.activeDocument;

var destName = prompt ("Enter a Filename Daniel", "", "Save With  Security");

var destFolder = Folder.selectDialog('Select which folder to save to :');

saveFileToPDF(destFolder+ '/' + destName); // not sure if i need this here ?





/* this will annotate the document with a breadcrumb trail

    then resave the file with the same security settings*/





                                        // i need to find a method of placing this central to the artboard, but as the text has random dimensions its proving difficult also there are multiple artboards

var pointTextRef = curDoc.textFrames.add();

pointTextRef.contents = + '  ' + curDoc.fullName; = 735;

pointTextRef.left = 20;

saveFileToPDF(destFolder+ '/' + destName); // i need this here





function saveFileToPDF (dest) {

var doc = app.activeDocument;

if ( app.documents.length > 0 ) {

var saveName = new File ( dest );

saveOpts = new PDFSaveOptions();

saveOpts.requirePermissionPassword = true;

saveOpts.permissionPassword = "test";

doc.saveAs( saveName, saveOpts );






i can do the math of (artboard width)-(text width) / 2 is start point of text but how do i find out the text width and the artboard width?


Message was edited by: tonyxamax

  • Currently Being Moderated
    Apr 16, 2012 2:19 AM   in reply to tonyxamax

    For your artboards which one do you intend to place the text on first, last all?


    As for your text… It is by default point text therefore you could position the point and centre align the contents ( thats what I would do )


    There are several scripts already knocking about that add such fluff like name & path to a file…

    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 3:29 AM   in reply to tonyxamax

    This should help you along…


    #target illustrator
    app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
    var doc = app.activeDocument;
    doc.artboards.setActiveArtboardIndex( 0 );
    var abRect = doc.artboards[0].artboardRect;
    var txt = doc.textFrames.add();
    txt.position = [ abRect[2]/2, abRect[3]/2 ];
    txt.textRange.paragraphAttributes.justification = Justification.CENTER;
    txt.contents = 'Some strings…'; 
    Mark as:
  • Currently Being Moderated
    Apr 16, 2012 6:01 AM   in reply to tonyxamax

    Only the people who demand a script or solution ( like it's there right ) are frowned upon… Those wanting help almost never… You will find in all the scripting forums here people are willing to help those who want to learn… ( the teach a man to fish approach ). Im muppet cos thats what I was when I was a noob asking here… still am…


    The numbers in the square brackets indicate an item of an array ( list ) the rectangular bounds of an artboard are a 4 item Array [ '0', '0', '200', '100' ] javascript is zero based so first item is [0] and so on…

    Mark as:
  • Currently Being Moderated
    Apr 26, 2012 9:21 AM   in reply to tonyxamax

    .fullName is the entire file path to the file. It will return the same form with a few less parts if it is located on your local hard drive. Try making a file and saving it to your desktop and then run your script. If you only want the name of the file and not the path to the file then just use .name.


    The "%20" is just computerese for a space character.

    Mark as:
  • Currently Being Moderated
    Apr 26, 2012 9:31 AM   in reply to Larry G. Schneider
    decodeURI( docRef.fullName );
    Mark as:
  • Currently Being Moderated
    Apr 26, 2012 12:48 PM   in reply to tonyxamax

    That would depend on where you looked? What resources are you using to help you?

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points