Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Finding the body page that contains a marker

Enthusiast ,
Sep 17, 2019 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

TOPICS
Scripting

Views

828

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
community guidelines

correct answers 1 Correct answer

Mentor , Sep 17, 2019 Sep 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 re...

Likes

Translate

Translate
Adobe Community Professional ,
Sep 17, 2019 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
community guidelines
Enthusiast ,
Sep 17, 2019 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
community guidelines
Mentor ,
Sep 17, 2019 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
community guidelines
Enthusiast ,
Sep 17, 2019 Sep 17, 2019

Copy link to clipboard

Copied

LATEST
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
community guidelines