1 Reply Latest reply on May 13, 2010 4:10 AM by Harbs.

    Create rectangle the size of page + bleed

    Steven.. Level 3

      I recently had to create a rectangle the size of a page + the bleed. I figured I'll post the code to see if anyone would benefit from it or maybe describe a better way to do it.

       

      These are the considerations

        • Unknown ruler unit origin
        • Unknown Unit type
        • Unknown if facing pages
        • Unknown if uniform bleed is being used
        • The rectangle cant go on to the other page, which means internal bleed should be ignored

       

       

      This is the function

       

      var CreateFullPageFrameIncludingBleed = function(doc,page){
           
           var docPrefs = doc.documentPreferences;
           var pageBleed = [];
           if(docPrefs.documentBleedUniformSize) {
                pageBleed = [docPrefs.documentBleedTopOffset,docPrefs.documentBleedTopOffset,
                     docPrefs.documentBleedTopOffset,docPrefs.documentBleedTopOffset];
           }
           else{
                pageBleed[0] = docPrefs.documentBleedTopOffset;
                pageBleed[2] = docPrefs.documentBleedBottomOffset;
                if(docPrefs.facingPages && page.side == PageSideOptions.LEFT_HAND){
                     pageBleed[1] = docPrefs.documentBleedOutsideOrRightOffset;
                     pageBleed[3] = 0;
                }
                else{
                     if(docPrefs.facingPages){
                          pageBleed[1] = 0;
                     }
                     else{
                          pageBleed[1] = docPrefs.documentBleedInsideOrLeftOffset;
                     }
                     pageBleed[3] = docPrefs.documentBleedOutsideOrRightOffset;
                }
           }
      
           var rect = page.rectangles.add();
           gm = rect.geometricBounds;
           rect.geometricBounds = [gm[0] - pageBleed[0], gm[1] - pageBleed[1], gm[0] + docPrefs.pageHeight + 
                pageBleed[2], gm[1] + docPrefs.pageWidth + pageBleed[3]];
      
           return rect;
      }
      

       

      and here is a stub to call the function

       

      var page = app.activeWindow.activePage;
      var doc = app.activeDocument;
      CreateFullPageFrameIncludingBleed(doc,page);
      
      

       

      An important part, is that the default placement of a rectangle or frame is at the top left corner of the page. So we build everything off that co-ordinate.

       

      Let me know if where the weakness is or if it helped you

       

      Steven