Thursday, November 17, 2011

Working with the Current Page

You can easily locate a document's current page using the CurrentPage document property. The current page is the one that is currently displayed on the screen and not the one with the insertion point.

Once you have the current page, you can access page number information:
  • PageNum is an integer indicating the position of the page within the document. The count starts at zero.
  • PageNumString is the number that appears in the page footer. It is defined by the variable building block <$curpagenum>.
The script below defines two functions:
  • GetPageNumber() returns the relative page number within the document.
  • GetPageString() returns the portion of the printed page number determined by the <$curpagenum> building block. (In my experiments, redefining the Current Page # variable did not impact the value returned by this function.)
Each function is called on the active document. The string printed in the FrameMaker console reflects the values associated with the page currently on the screen.

var doc, pageNum, pageString;
doc = app.ActiveDoc;

function GetPageNumber(doc) {
    var page = doc.CurrentPage.PageNum;
    return page;

function GetPageString(doc) {
    var pageStr = doc.CurrentPage.PageNumString;
    return pageStr;

pageNum = GetPageNumber(doc);
pageString = GetPageString(doc);

Console("Offset in pages from start of document is " + pageNum);
Console("Page number that appears on printed page is  " + pageString);

The following output illustrates the fact that each of these functions likely returns a different value for the same document page even accounting for the difference in value type.

No comments:

Post a Comment