Suppose you’re going to print a report, make two-sided copies, and bind them. You want to shift the margins slightly on both pages to accommodate the binding. The right pages need to move to the right and the left pages need to move to the left. Other than that, the pages are identical.

You can use the onPage event handler to shift the margins of the PageTemplate after each page has printed, in preparation for the next page:

function Report_onPage( )

   #define TWIPS(x) ((x)*1440) 

   if this.reportPage % 2 == 0 // Finished left page, start right 

      this.pageTemplate1.marginLeft = TWIPS( 1.0 ) 

      this.pageTemplate1.marginRight = TWIPS( 0.5 ) 

   else // Finished right page, start left 

      this.pageTemplate1.marginLeft = TWIPS( 0.5 ) 

      this.pageTemplate1.marginRight = TWIPS( 1.0 ) 

   endif 

Pages on the left are even-numbered. An even number modulo 2 yields zero, so if a left page has just been printed, the margins are set to those for a right page, and vice versa.