7 Replies Latest reply on Jun 26, 2012 9:59 AM by ted42

    [JS][CS5]Test if point is on Page/Bleed/...


      I would like to test for a given point x, y if it is on the page, the bleed or outside. To do so I need to know how to access the bleedsize /pagesize.

      Is there maybe a convenience function?



      1. How do I get the Boundingbox of the bleed/Page?

      2. Is there a convenience function to test if a point/object is inside another? (If not I can easily roll my own, once I know how I get the page corner/bleed corner coordinates)


      This problem partly steems from the fact that I find the objectmodel still very confusing, is there any good reference that shows you those things graphically, explains the properites better than the adobe help?

        • 1. Re: [JS][CS5]Test if point is on Page/Bleed/...
          ted42 Level 1

          I came up with a solution: thanks to the searchable help in chm from jongware: (Iam reposting ithere so people searchng can find the answer)


          I wonder where the format as code button is...

          This checks weather a given pooint is on the printable area/bleed or not.


          If you know of a more elegant way to check if an element has an attribute please let m know(I am sure there is one)



              @param point  [x,y]

              @param page object that is child in some form of page (page has to be reachable by walking up the tree with parent)


          function pointOnPage(point, page) { 

              while(!hasProperty(page,'parentPage')) {

                  page = page.parent;



              page = page.parentPage;


              var pages = page.parent.pages;

              var docPrefs = app.activeDocument.documentPreferences;


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

                  var bounds = pages[i].bounds;

                  //take bleed into account

                  bounds[0] += docPrefs.documentBleedTopOffset;

                  bounds[1] += docPrefs.documentBleedInsideOrLeftOffset;

                  bounds[2] += docPrefs.documentBleedOutsideOrRightOffset;

                  bounds[3] += docPrefs.documentBleedBottomOffset;


                  if(pointInRect(point, bounds) ) {//y x y2 x2

                      return true;




              return false;



          function hasProperty(obj, prop) {

                  var properties = obj.reflect.properties;


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

                      if( properties[i].name == prop ) {

                          return true;




                  return false;




              @param point [x,y]

              @param rect [y1,x1,y2,x2] //see page bounds for the wiredness


          function pointInRect(point, rect) {

              //includes borders

              return rect[1] < point[0] && point[0] < rect[3] &&

                  rect[0] < point[1] && point[1] < rect[2];


          • 2. Re: [JS][CS5]Test if point is on Page/Bleed/...
            Laubender Adobe Community Professional & MVP

            @Ted – be aware that the visual representation of an object on the page can easily exceed its visual or geometric bounds.
            Examples: effects like drop shadows, tables, even glyphs.


            To check for those cases only rendering the page in pixels would be a starting point for  thiese limits.



            • 3. Re: [JS][CS5]Test if point is on Page/Bleed/...
              ted42 Level 1

              there is a sign mistake the margins for top and left need to be subtracted


              Thanks for the hint, in my case it does not Matter, I am just checking for points of a path and round the corners if they are on the page.


              By the way I don#t understand why there should be issues with Tables. FOr the Dropshadows one could surely calculate the bounding box from the original box and the boundingbox settings, if one needed too?


              As for glyphs I have no Idea how to go about these, but I would like to see that firs before I even bother, but tis quest is done, these are purely educational concerns...

              • 4. Re: [JS][CS5]Test if point is on Page/Bleed/...
                Laubender Adobe Community Professional & MVP

                @Ted – an example for a table exceeding the geometricBounds (visualBounds as well) of the text frame:


                Bildschirmfoto 2012-06-21 um 07.50.34.png

                The second example in the screen grab shows the same table, strokes set to none: if you would calculate geometricBounds of objects only, you will not detect, that table 1 is going out of the page. If you calculate the table width without considering fill and strokes of cells, you will get a false positive in table 2, because the effective object is the text, that's well inside the page.


                Btw. I forgot another important case:
                objects with fill color white on white background!
                Also good for a "false positive".


                • 5. Re: [JS][CS5]Test if point is on Page/Bleed/...
                  ted42 Level 1


                  I can catch most of your gotchas with the minimum of frame/object, I guess. This Does not consider Tables made to big but thats not an issue. In my case I have just a modifcation of th round cornes script (which seems to be written horrible at a first glance, at least for rounding only I could reduce the code drastically (considering just the rounding code, not the other effects). I Round all corners of Image frames that are on the page. This gives the look of a cut off rounded rectangle. I don't want to roun corners on the bleed or outside.


                  As for your short text in long table case, I would still consider this overset, if the user does not want that behaviour he has to make the table smaller. Thanks for your visual examples and insights. Should I ever consider making scripts for general use 8and have the time for that I will sure ask you to rule out the corner cases  )


                  kind regards


                  • 6. Re: [JS][CS5]Test if point is on Page/Bleed/...
                    Muppet Mark Level 5

                    Why don't you use the corner options to round… A hard coded snippet for a sample A5 DPS… Works here…


                    #target indesign
                    var doc = app.activeDocument;
                    var rects = doc.spreads[0].rectangles;
                    for ( var i = 0; i < rects.length; i++ ) {
                        var pp = rects[i].paths[0].entirePath
                        for ( var j = 0; j < pp.length; j++ ) {
                            if ( pp[j][0] > 0 && pp[j][0] < 297 && pp[j][1] > 0 && pp[j][1] < 210 ) {       
                                switch ( j ) {
                                    case 0: rects[i].topLeftCornerOption = CornerOptions.ROUNDED_CORNER; break;
                                    case 1: rects[i].bottomLeftCornerOption = CornerOptions.ROUNDED_CORNER; break;
                                    case 2:  rects[i].bottomRightCornerOption = CornerOptions.ROUNDED_CORNER; break;
                                    case 3:  rects[i].topRightCornerOption = CornerOptions.ROUNDED_CORNER;
                    • 7. Re: [JS][CS5]Test if point is on Page/Bleed/...
                      ted42 Level 1

                      @muppet mark


                      I copied from cornerEffect.js


                      In short yours is easier and I was totally unaware of it, however I am glad I copied (and changed slightly), since now I do not care if I get rects or other shapes.


                      My Java is a bit rusty but ouldn#t something like


                      cornors=['topLeftCornerOption', 'bottomLeftCornerOption', 'bottomRightCornerOption', 'topRightCornerOption'];


                      for ....

                          rects[i][cornors[j]] = CornerOptions.ROUNDED_CORNER;


                      work as well?


                      thanks for showing me an alternative, I am always eager to learn