Skip to main content
Known Participant
June 23, 2014
Question

JavaScript fill curent layout color Black

  • June 23, 2014
  • 2 replies
  • 780 views

hello, i have a javascript to setup a new document to the correct page size etc.

BUt i want it also to have a colour black background and not white, is this possible with Javascript and the document setup?

Thanks

This topic has been closed for replies.

2 replies

markc0Author
Known Participant
June 23, 2014

many thanks , thats exactly what i wanted

Chinnadk
Legend
June 23, 2014

Hi,

You can get the black background by changing the [Paper] color. Include the below lines to your code it will change the paper color to black.

var paper = app.activeDocument.swatches.item("Paper")

paper.colorValue = [0,0,0,100];

Regards,

Chinna

markc0Author
Known Participant
July 4, 2014

Hi Chinnad

Sorry to open this back up but just a question, if i had a top and a bottom margin on the page could i just fill in black the margins?

Thanks

Chinnadk
Legend
July 5, 2014

Hi Mark,

Try this. It will add a 'Black' filled rectangle on all master pages.

var doc = app.activeDocument;

var _spreads = doc.masterSpreads;

for(var i=0;i<_spreads.length;i++)

{

    for(var j=0;j<_spreads.pages.length;j++)

    {

        var x1, y1, x2, y2;

        var width = doc.documentPreferences.pageWidth;

        var height = doc.documentPreferences.pageHeight;

        y1 = _spreads.pages.marginPreferences.top;

        y2 =  _spreads.pages.marginPreferences.bottom;

        var rect = _spreads.pages.rectangles.add({fillColor:"Black"});

        if(_spreads.pages.side  == PageSideOptions.RIGHT_HAND)

        {

            x1=_spreads.pages.marginPreferences.left;

            x2 = _spreads.pages.marginPreferences.right;

            rect.geometricBounds = [x1, y1,height - y2,width-x2];

            }

        else if (_spreads.pages.side  == PageSideOptions.LEFT_HAND)

        {

            x2=_spreads.pages.marginPreferences.left;

            x1 = _spreads.pages.marginPreferences.right;

            rect.geometricBounds = [x1, y1,height - y2,width-x2];

            }

        }

    }

Regards,

Chinna