/* This genie will rearrange a document designed as double-page spreads to fit on the sheets of a simple stapled booklet. It only works for Postscript output. The pages are arranged so you can print the first half of the document on one side of the paper and then turn the paper over for the other half. Written by Don Cox */ cr = '0a'x call SafeEndEdit.rexx() call ppm_AutoUpdate(0) colormode = ppm_GetColorMode() call ppm_SetColorMode(0) oldpsout = ppm_GetPSOutput() call ppm_SetBatchMode(1) prevdoc = ppm_GetDocName() if ppm_DocChanged() then do if ppm_SavedDate() = "Not Saved" then prevdoc = "" if ppm_Inform(2, "You must save the current document first. Should I save and continue?", "Cancel", "Ok") then call ppm_SaveDocument(prevdoc) else exit_msg("Aborted by User") prevdoc = ppm_GetDocName() end totalpages = ppm_NumPages() if totalpages = 0 then exit_msg("No pages") lpos = lastpos("/",prevdoc) /* Find end of pathname */ if lpos = 0 then lpos = lastpos(":",prevdoc) docname = substr(prevdoc,lpos+1) /* Strip off pathname */ pathname = substr(prevdoc,1,length(prevdoc)-length(docname)) call ppm_SetDocName(docname||".bklt") if length(docname)>30 then do docname = delstr(docname,1,length(docname)-30) call ppm_SetDocName(docname) /* File name only */ end newname = ppm_GetDocName() /* Full name including path */ /* Set all pages to size of largest */ if totalpages>1 then do oldpageX = word(ppm_GetPageSize(1),1) oldpageY = word(ppm_GetPageSize(1),2) diff = 0 /* flag for different page sizes */ do i = 2 to totalpages pageX = word(ppm_GetPageSize(i),1) pageY = word(ppm_GetPageSize(i),2) if pageX ~= oldpageX | pageY ~= oldpageY then do diff = diff+1 oldpageX = max(pageX,oldpageX) oldpageY = max(pageY,oldpageY) end end if diff ~=0 then do do i =1 to totalpages call ppm_SetPageSize(i,oldpageX,oldpageY) end exit_msg("Pages Resized. Check boxes & try again") end end /* Save all pages as .eps files */ call ppm_SetPSEPSF(1) length2 = length(newname) epsname = substr(newname,1,length2-5) /* strip off ".bklt" */ do i = 1 to totalpages /* .eps is only as big as the boxes, not the page,so make a page-size box. */ newpage = ppm_GotoPage(i) pagebox = ppm_CreateBox(0,0,oldpageX,oldpageY,0) call ppm_SetPSOutputOrient(i,1) call ppm_SetPSPageSize(oldpageX,oldpageY) call ppm_SetPSOutput(epsname||i||".eps") success = ppm_PrintPagePS(i,1,1) if success = 0 then exit_msg("Failed saving .eps of page "i) end /*call exit_msg("temporary stop") /* testing */*/ call ppm_DeletePage(1,totalpages) freshpage = ppm_CreatePage(1,1,0,0) call ppm_SetPageSize(1,oldpageX,oldpageY) /* The next 2 lines assume you are printing to a normal A4 or A3 printer */ if oldpageX>oldpageY then call ppm_SetPSPageSize(oldpageY,oldpageX) if oldpageX>oldpageY then call ppm_SetPSOutputOrient(1,2) done = ppm_CopyPage(1,1,totalpages-1) offset = oldpageX/2 offset = -offset pages = 2*totalpages /* 2 pages on each side of the paper */ do i = 1 to totalpages newpage = ppm_GotoPage(i) Lbox = ppm_CreateBox(0,0,oldpageX/2,oldpageY,0) Rbox = ppm_CreateBox(oldpageX/2,0,oldpageX/2,oldpageY,0) if i//2=1 then /* check for odd number pages */ do j = (i-1)/2 if j=0 then j=totalpages k = (totalpages+1)-j /* Formula for left page, odd sides */ m = (i+1)/2 /* Right page, odd sides */ done = ppm_ImportEPSF(Lbox,epsname||k||".eps") if done = 0 then exit_msg("Trouble importing "epsname||j||".eps") done = ppm_ImportEPSF(Rbox,epsname||m||".eps") if done = 0 then exit_msg("Trouble importing "epsname||i||".eps") end else do n = (i/2)+1 /* Left page, even sides */ p = (totalpages+1)-(i/2) /* Right box, even sides */ done = ppm_ImportEPSF(Rbox,epsname||p||".eps") if done = 0 then exit_msg("Trouble importing "epsname||i||".eps") done = ppm_ImportEPSF(Lbox,epsname||n||".eps") if done = 0 then exit_msg("Trouble importing "epsname||j||".eps") end /* Must set scale before offset as it scales the offset */ call ppm_SetBoxScale(Lbox,1,1) call ppm_SetBoxScale(Rbox,1,1) call ppm_SetBoxOffset(Rbox,offset,0) end /* Separate the odd and even sides for double-sided printing */ do i = totalpages-1 to totalpages/2 by -1 done = ppm_MovePage(i,1) end newpage = ppm_GotoPage(1) call exit_msg("Done") end exit_msg: procedure expose colormode oldpsout do parse arg message if message ~= '' then call ppm_Inform(1, message,"Resume" ) call ppm_SetColorMode(colormode) call ppm_SetPSEPSF(0) call ppm_SetPSOutput(oldpsout) call ppm_AutoUpdate(1) call ppm_ClearStatus() call ppm_SetBatchMode(1) exit end