Highlighted

Finding the body page that contains a marker

Enthusiast ,
Sep 17, 2019

Copy link to clipboard

Copied

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

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

TOPICS
Scripting

Views

781

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Finding the body page that contains a marker

Enthusiast ,
Sep 17, 2019

Copy link to clipboard

Copied

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

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

TOPICS
Scripting

Views

782

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 17, 2019 0
Adobe Community Professional ,
Sep 17, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2019 0
Enthusiast ,
Sep 17, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2019 0
Mentor ,
Sep 17, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2019 0
Enthusiast ,
Sep 17, 2019

Copy link to clipboard

Copied

Thanks Russ, this is exactly what I needed. Sometimes it's not knowing what you don't know that causes the problems!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 17, 2019 0