4 Replies Latest reply on Jul 5, 2014 12:12 AM by Chinnadk

    JavaScript fill curent layout color Black

    markc0

      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

        • 1. Re: JavaScript fill curent layout color Black
          Chinnadk Level 4

          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

          • 2. Re: JavaScript fill curent layout color Black
            markc0 Level 1

            many thanks , thats exactly what i wanted

            • 3. Re: JavaScript fill curent layout color Black
              markc0 Level 1

              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

              • 4. Re: Re: JavaScript fill curent layout color Black
                Chinnadk Level 4

                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[i].pages.length;j++)
                    {
                        var x1, y1, x2, y2;
                        var width = doc.documentPreferences.pageWidth;
                        var height = doc.documentPreferences.pageHeight;
                        y1 = _spreads[i].pages[j].marginPreferences.top;
                        y2 =  _spreads[i].pages[j].marginPreferences.bottom;
                        var rect = _spreads[i].pages[j].rectangles.add({fillColor:"Black"});
                        if(_spreads[i].pages[j].side  == PageSideOptions.RIGHT_HAND)
                        {
                            x1=_spreads[i].pages[j].marginPreferences.left;
                            x2 = _spreads[i].pages[j].marginPreferences.right;
                            rect.geometricBounds = [x1, y1,height - y2,width-x2];
                            }
                        else if (_spreads[i].pages[j].side  == PageSideOptions.LEFT_HAND)
                        {
                            x2=_spreads[i].pages[j].marginPreferences.left;
                            x1 = _spreads[i].pages[j].marginPreferences.right;
                            rect.geometricBounds = [x1, y1,height - y2,width-x2];
                            }
                        }
                    }
                

                 

                Regards,

                Chinna