Skip to main content
Ian Proudfoot
Legend
September 17, 2019
Answered

Finding the body page that contains a marker

  • September 17, 2019
  • 2 replies
  • 1241 views

I am building an application that reports the page number of a given type of marker. This is normally quite simple as I just need to test for the TextLoc and resolve that to give the correct body page number.

It's not so easy if the marker is located in a paragraph that spans multiple pages. In that case the reported location is the start location of the containing paragraph and that could be several pages away from the actual marker location.

I understand that the offset of the marker location gives its true location, but how do we relate that to an actual page?

My initial attempt has been to compare the marker's TextLoc offset with the occurence of TextItems with dataType of Constants.FTI_PageBegin. Am I on the right track, or am I missing somthing really obvious?

 

I haven't posted any code yet because I wanted to discuss this at the conceptual level first.

Thanks

Ian

This topic has been closed for replies.
Correct answer Russ Ward

Hi Ian, it is possible and it is not as complicated as you might think. Basically, to reliably find the page location of anything like this, you need to find the page frame that contains it. That is, the highest-level frame on the page. You can reliably find the immediate parent frame of an object with its text location, then you can iterate up to the page frame, and then the page number is elementary.

 

Here is a basic function to do it, where doc and marker are the respective objects.

function reportMarkerPageNum(doc, marker)
{
  var prop = doc.GetTextPropVal(marker.TextLoc, Constants.FP_InTextFrame);
  var frame = prop.propVal.obj;
  var pageFrame = null;
   
  while(frame.ObjectValid())
  {
     pageFrame = frame;
     frame = frame.FrameParent;
  }
  if(pageFrame)
  {
     var page = pageFrame.PageFramePage;
     alert(page.PageNumString);
  }
}

I hope this helps. I think this method is more logical than the approach you were taking. It will work whether the marker is in a basic text frame, table cell, anchored frame, or whatever. I think.

 

Russ

2 replies

Russ WardCorrect answer
Legend
September 17, 2019

Hi Ian, it is possible and it is not as complicated as you might think. Basically, to reliably find the page location of anything like this, you need to find the page frame that contains it. That is, the highest-level frame on the page. You can reliably find the immediate parent frame of an object with its text location, then you can iterate up to the page frame, and then the page number is elementary.

 

Here is a basic function to do it, where doc and marker are the respective objects.

function reportMarkerPageNum(doc, marker)
{
  var prop = doc.GetTextPropVal(marker.TextLoc, Constants.FP_InTextFrame);
  var frame = prop.propVal.obj;
  var pageFrame = null;
   
  while(frame.ObjectValid())
  {
     pageFrame = frame;
     frame = frame.FrameParent;
  }
  if(pageFrame)
  {
     var page = pageFrame.PageFramePage;
     alert(page.PageNumString);
  }
}

I hope this helps. I think this method is more logical than the approach you were taking. It will work whether the marker is in a basic text frame, table cell, anchored frame, or whatever. I think.

 

Russ

Ian Proudfoot
Legend
September 17, 2019
Thanks Russ, this is exactly what I needed. Sometimes it's not knowing what you don't know that causes the problems!
Bob_Niland
Community Expert
Community Expert
September 17, 2019

I have no insights from a scripting perspective, but if generating a normal LoM for the document correctly presents the page number for the marker, then it should at least be possible.

Ian Proudfoot
Legend
September 17, 2019
Thanks for the response Bob. I agree that it's possible and my way does seem to work most of the time, but it just seems rather clumsy and unsatisfactory.