• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Variable «Page Count» considered useless

Community Expert ,
Aug 23, 2021 Aug 23, 2021

Copy link to clipboard


Variable Page Count has it's quirks:

  • When the book files use "Continue Numbering From Previous Chapter in Book" then the variable increases from file to file, because it just takes the value from the last page.
  • It can not be used to sum up in the other cases, because it is formatted (how to sum up V + VII + IX...?)

The core to get the desired information for summing up the total is quite simple:


KLD_Z.GetPageNums = function (oDoc) { 
/*            Get information about page numbers
Arguments     oDoc            document to be handled
Returns       object with the following properties:
              .nFirst          Page number of first body page (integer)
              .nPages          Number of body pages
              .iFormat         Format of pagen number (an integer!)
var oPage, obj= {};
  obj.nFirst = oDoc.FirstPageNum;
  oPage = oDoc.LastBodyPageInDoc;
  obj.nPages = oPage.PageNum + 1;
  obj.iFormat = oDoc.PageNumStyle; // is an integer
  return obj;
} //--- end GetPageNums --------------------------------------------------------------------


... but the whole task GetBookPageCount to define/insert/update a user variable  BookPageCount in all (*.fm) book files requires some ancillary functions: CollectDocsInBook, DefineUserVariable, GetSimpleOpenProps, GetText, GetVariableValue, Message, OpenDocOrBook

I have put this together into a ZIP. Place both the contained file and the subdirectory in the StartUp folder. To use the function, have a book active, open the Script Library, check "Autorun" to list the scripts of the StartUp folder; select GetBookPageCount.jsc and use the Run button.

The relevant files are opened and get the variable, which then can be used... In the next run with the same book the variable is updated.

Well, the resulting script may be viewed as elaborate - You are free to cut it down to a 'one-liner'...

The attached file can not be ZIP, hence you need to rename from txt to zip after download! Heck, the txt was not accepted - I try with jpg. Aaaargh! Even this is not accepted as an attachement! → https://www.daube.ch/docu/files/GetBookPageCount.zip


Formatting and numbering , Scripting






Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation