Script – Custom layout

This script arranges page in one special way by putting one or two pages per sheet. Basically we should arrange source pages from this (see below) in the way similar to the right image.

Source Pages Left to Right Arrow Page Layout

Number of pages is not fixed – we can put one or two pages per sheet. Hence we should create our layout from scratch. This script contain  InsertOnePage function. It can be used in any other script, it works in the same way as standard one page layout in priPrinter.

 

// same as one page mode
function InsertOnePage(paper,page)
{
  paper.InsertPage(page);
  local paperArea=paper.GetArea();
  local pageSize = page.GetAreaSize();
  local ky=paperArea.Height()/pageSize.y;
  local kx=paperArea.Width()/pageSize.x;
  if(ky<kx)kx=ky;
  paper.SetPageScale(page,kx);
  pageSize *=kx;
  local offset=(paperArea.Size()-pageSize)/2.0;
  paper.SetPagePos(page,offset);
}

// similar to 2 pages layoyt
function InsertTwoPages(paper,page,pos)
{
  local paperArea=paper.GetArea();
  page.angle=3;
  paper.InsertPage(page);
  local paperArea2=paperArea.Size();
  paperArea2.y/=2;

  local pageSize = page.GetAreaSize();
  local ky=paperArea2.y/pageSize.y;
  local kx=paperArea2.x/pageSize.x;
  if(ky<kx)kx=ky;
  paper.SetPageScale(page,kx);
  pageSize *=kx;
  local offset=(paperArea2-pageSize)/2.0;
  offset.y+=pos*paperArea2.y;
  paper.SetPagePos(page,offset);
}

// main code
local doc=window.GetDocument();
layout.Clear();// remove all papers

local numPages=doc.numpages;// number of source pages
local iPage=0; // current page
while(iPage<numPages)
{
  local paper=layout.NewSheet();// new paper sheet
  local page=doc.GetPage(iPage);// page

  if((iPage>=2)&&(iPage<=5)) // it is possible to change this condition
  {
    InsertTwoPages(paper,page,1);
    iPage++;
    if(iPage<numPages)
    {
    page=doc.GetPage(iPage);
    InsertTwoPages(paper,page,0);
    }
  }else
    InsertOnePage(paper,page);
  
  iPage++;
}

// main code

 

All samples