Getting the sheet number instead of page number when printing duplex - xmpie-users/uStore-js GitHub Wiki

In some cases, when printing duplex, you will want to get the "sheet" number instead of the "page" number.

For this, simply divide the pageIndex by 2 and use the ceiling function to raise any decimal to the next highest integer:

return "Sheet " + Math.ceil(state.pageIndex/2) + " of " + Math.ceil(state.pageCount/2) + " sheets.";

Of course, you will get "Sheet 1 of n" for both the first and second page (front and back of the sheet) so you may also need to use the modulo trick to hide on one side:

if (state.pageIndex % 2 == 0) {
  return "Sheet " + Math.ceil(state.pageIndex/2) + " of " + Math.ceil(state.pageCount/2) + " sheets.";
} else {
  return "";
}