Re-size Artboards on multiple files (quickly)

Explorer ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

Community,

I have thousands of PDF files (Illustrator editable) that need to have the first Artboard resized. Completing this manually would consume too many man hours and is unfeasible.

The Actions panel cannot re-size Artboards so I cannot use that method.

I am aware of the scripting potential that is available with Adobe Illustrator. Does anyone have a script that can possibly assist me with my dilemma?

Any sort of assistance would be greatly appreciated.

Thanks,

Views

869

Likes

translate

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

correct answers 1 Correct Answer

Adobe Community Professional , Jul 04, 2019 Jul 04, 2019
I put together a script to resize the 1st artboard of pdf and ai files in a supplied folder.   **WARNING** the script will overwrite your files, please make back ups if your files are valuable...you've been warned.   // script.name = batchResizeArtboards.jsx; // script.description = opens all files in selected folder and resizes first artboard // script.requirements = open illustrator before running the script // script.parent = CarlosCanto // 07/04/2019; // script.support = canto29@gmail.com;  ...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

Can you share a sample file?

Which version of Illustrator are you using?

Likes

translate

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
Explorer ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

I am trying to resize the first artboard which is an 8.5 x 11 to (5.625 x 4.87).

I am using the latest version.

https://brandmd.box.com/s/0yrd0era89tla6qq0p9q7o1u555wwmaj

Likes

translate

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 ,
Jul 04, 2019 Jul 04, 2019

Copy link to clipboard

Copied

It should be possible to modify the action that has been discussed in this thread:

Action to add specific dimension to left and right side of current Artboard?

Then you could execute it in batch mode.

Likes

translate

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 Employee ,
Jul 04, 2019 Jul 04, 2019

Copy link to clipboard

Copied

Hi there,

I am moving this discussion to Illustrator Scripting forum so that you can get some more responses from our scripting experts.

Regards,

Srishti

Likes

translate

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 ,
Jul 04, 2019 Jul 04, 2019

Copy link to clipboard

Copied

Srishti,

I think it would be appropriate to copy move this topic to the scripting forum (though the action I mentioned would certainly work when one modifies it a bit).

Your link, however, goes to a completely different place (FAQ) that will probably not help at all in that case.

Likes

translate

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 ,
Jul 04, 2019 Jul 04, 2019

Copy link to clipboard

Copied

I put together a script to resize the 1st artboard of pdf and ai files in a supplied folder.

 

**WARNING**

the script will overwrite your files, please make back ups if your files are valuable...you've been warned.

 

// script.name = batchResizeArtboards.jsx;

// script.description = opens all files in selected folder and resizes first artboard

// script.requirements = open illustrator before running the script

// script.parent = CarlosCanto // 07/04/2019;

// script.support = canto29@gmail.com;

 

 

 

 

function main () {

    // DEBUG ONLY, press shift to set donate flag to false and force bringing up the donate dialog, otherwise, read the preference file to get the flag from it

    var forceShowDialog = false;

    if (ScriptUI.environment.keyboardState.shiftKey) {

        forceShowDialog = true;

    }

 

 

    var sourceFolder = getPreselectFolder ('resizeArtboards', 'sourceFolder');

  

    if (sourceFolder) {

    }

    else {return};

 

 

 

 

    var files = sourceFolder.getFiles (/\.(pdf|ai)$/i); // get files

      

    var filecount = files.length;

  

    if (filecount == 0) {

        alert('no files found in selected folder');

        return;

    }

 

 

    // skip open options window, open file with defaults

    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

  

    var inches = 72;

 

 

    var title = "Resize First Artboard";

  

    var width = Number(Window.prompt ("Enter New Artboard Width in inches", 5.625, title))*inches;

    var height = Number(Window.prompt ("Enter New Artboard Height in inches", 4.87, title))*inches;

 

 

    var idoc;

      

    for (var k=0; k<files.length; k++) {

        idoc = app.open(files[k]);

      

        artboardProperties (idoc.artboards[0], width, height, true, false);

                      

        app.activeDocument.close (SaveOptions.SAVECHANGES);

    }

  

    donate (File($.fileName).displayName, forceShowDialog);

  

    app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;

}

 

 

main ();

 

 

 

 

// resizes the active artboard, returns the new document origin

function artboardProperties (ab, width, height, resize, fromTop) {

 

 

    var abBounds = ab.artboardRect;// left, top, right, bottom

 

 

    var ableft = abBounds[0];

    var abtop = abBounds[1];

    var abright = abBounds[2];

    var abbottom = abBounds[3];

  

    var abwidth = abBounds[2] - ableft;

    var abheight = abtop- abBounds[3];

 

 

    var abctrx = abwidth/2+ableft;

    var abctry = abtop-abheight/2;

 

 

    if (width && height) {

        if (fromTop) {

            var ableft = abctrx-width/2;

            var abtop = abtop;

            var abright = abctrx+width/2;

            var abbottom = abtop-height;

          

            var abctry = abtop-(abtop- abbottom)/2;

        }

        else {

            var ableft = abctrx-width/2;

            var abtop = abctry+height/2;

            var abright = abctrx+width/2;

            var abbottom = abctry-height/2;

        }

  

        var abwidth = abright - ableft;

        var abheight = abtop- abbottom;

      

        if (resize)

            ab.artboardRect = [ableft, abtop, abright, abbottom];

    }

    return {left:ableft, top:abtop, right:abright, bottom:abbottom, centerx:abctrx, centery:abctry, width:abwidth, height:abheight}

}

 

 

 

 

function getPreselectFolder(scriptname, strfolder, extension) {

    var folderStrPref = 'aiscripts.com/'+scriptname+'/'+strfolder;

    var preselectFolder = Folder(app.preferences.getStringPreference (folderStrPref));

    if (!preselectFolder.exists) {

        var preselectFolder = new Folder('~/Desktop');

    }

 

 

    if (extension) {

        var sourceFile = preselectFolder.openDlg('Select Source file...', '*.'+extension, false); // select source file

        if (sourceFile==null) {  // exit if press cancel in either dialog

            alert('Cancelled by user');

            return;

        }

        var folder = sourceFile.parent;

        app.preferences.setStringPreference (folderStrPref, folder.fsName);

        return sourceFile;

    }

    else {

        var folder = preselectFolder.selectDlg('Select '+strfolder+'...'); // select source folder

    }

 

 

    if (folder==null) {  // exit if press cancel in either dialog

        alert('Cancelled by user');

        return;

    }

    app.preferences.setStringPreference (folderStrPref, folder.fsName);

    //preselectFolder = Folder(app.preferences.getStringPreference (folderStrPref));

  

    //return preselectFolder;

    return folder;

}

 

 

 

 

function donate(thisScript, forceShowDialog) {

    var donateStrPref = 'aiscripts.com/donate/'+thisScript;

  

    // press shift to set donate flag to false and force brign up the donate dialog, otherwise, read the preference file to get the flag

    var donated;

    if (forceShowDialog) {

        donated = false;

        app.preferences.setStringPreference (donateStrPref, 'false');

    }

    else {

        donated = app.preferences.getStringPreference (donateStrPref);

    }

  

    if (donated != 'true') {

        var showAgain = showDonateWindow ();

        if (showAgain) {

            //alert('checked');

            app.preferences.setStringPreference (donateStrPref, 'true');

        }

    }

}

 

 

function showDonateWindow() {

    var win = new Window('dialog', 'https://www.paypal.me/aiscripts');

    var lblDonate = win.add('staticText', undefined, 'Do you find the script valuable?\nDo you use the script commercially?\n\nPlease consider donating.', {multiline:true});

    var grp = win.add('group');

    var btnCancel = grp.add('button', undefined, 'Cancel');

    var btnDonate = grp.add('button', undefined, 'Donate');

    var chk = win.add('checkbox', undefined, "Do not show me this message again");

 

 

    btnDonate.onClick = function(){

        openURL( 'www.paypal.me/aiscripts' );

        win.close();

    }

 

 

    win.center();

  

    if(win.show() == 2){

        //alert("pressed Cancel");

        return chk.value;

    } else {

        //alert('pressed donate');

        return chk.value;

    }

    

    function openURL( address ) {

        var f = File( Folder.desktop + '/aiOpenURL.url' );

        f.open( 'w' );

        f.write( '[InternetShortcut]' + '\r' + 'URL=http://' + address + '\r' );

        f.close();

        f.execute();

        f.remove();

    };

}

Likes

translate

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
Explorer ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

CarlosCanto,

I greatly appreciate you sharing this script with me. It worked exactly as intended which is a huge relief for me. The only issue I have now is; re-sizing everything based off a search as opposed to pointing the script to a specific folder.

Would this be possible to accomplish?

Any assistance would be greatly appreciated!

Likes

translate

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 ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

if you're on Windows there might be hope.

in the meantime is it feasible to move the searched results to a temp folder?

Likes

translate

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
Explorer ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

I can technically move the searched results to a temp folder, but my concern is placing them back to their respective folder. Unless you have a some sort of trick up your sleeve?

Likes

translate

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 ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

true, restoring files would be a problem. sorry no I don't have a quick alternative.

so, win or mac?

Likes

translate

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
Explorer ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

I am using Windows 10 Pro.

Likes

translate

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 ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

Carlos,

Nice work! Your skill and generosity is a wonderful tandem and is appreciated.

 

Pete

Likes

translate

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 ,
Mar 17, 2021 Mar 17, 2021

Copy link to clipboard

Copied

Thanks for you example Carlos. Do you know if it is possible to detect if the document / artboard has a bleed area and its size from scripting? I've checked the documentation but couldn't find anything.

 

In my case, I want to change the artboard width and height to include the bleed area.

 

Regards,

Lucas

Likes

translate

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