home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d7xx / d724 / donsgenies.lha / DonsGenies / DonsGenies.lha / Don'sGenies / Booklet.pprx next >
Text File  |  1992-07-16  |  5KB  |  165 lines

  1. /*
  2.  
  3. 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.
  4. Written by Don Cox
  5.  
  6. */
  7.  
  8.  
  9. cr = '0a'x
  10. call SafeEndEdit.rexx()
  11. call ppm_AutoUpdate(0)
  12. colormode = ppm_GetColorMode()
  13. call ppm_SetColorMode(0)
  14. oldpsout = ppm_GetPSOutput()
  15. call ppm_SetBatchMode(1)
  16.  
  17. prevdoc  = ppm_GetDocName()
  18.  
  19. if ppm_DocChanged() then
  20. do
  21.     if ppm_SavedDate() = "Not Saved" then prevdoc = ""
  22.  
  23.     if ppm_Inform(2, "You must save the current document first. Should I save and continue?", "Cancel", "Ok") then
  24.                 call ppm_SaveDocument(prevdoc)
  25.     else
  26.             exit_msg("Aborted by User")
  27.  
  28.     prevdoc = ppm_GetDocName()
  29. end
  30.  
  31.  
  32. totalpages = ppm_NumPages()
  33. if totalpages = 0 then exit_msg("No pages")
  34.  
  35. lpos = lastpos("/",prevdoc)  /* Find end of pathname */
  36. if lpos = 0 then lpos = lastpos(":",prevdoc)
  37. docname = substr(prevdoc,lpos+1)  /* Strip off pathname */
  38. pathname = substr(prevdoc,1,length(prevdoc)-length(docname))
  39. call ppm_SetDocName(docname||".bklt")
  40.  
  41. if length(docname)>30 then do
  42.     docname = delstr(docname,1,length(docname)-30)
  43.     call ppm_SetDocName(docname)  /* File name only */
  44.     end
  45. newname = ppm_GetDocName()   /* Full name including path */
  46.  
  47.  
  48. /* Set all pages to size of largest */
  49. if totalpages>1 then do
  50.     oldpageX = word(ppm_GetPageSize(1),1)
  51.     oldpageY = word(ppm_GetPageSize(1),2)
  52.     diff = 0   /* flag for different page sizes */
  53.  
  54.     do i = 2 to totalpages
  55.         pageX = word(ppm_GetPageSize(i),1)
  56.         pageY = word(ppm_GetPageSize(i),2)
  57.         if pageX ~= oldpageX | pageY ~= oldpageY then do
  58.             diff = diff+1
  59.             oldpageX = max(pageX,oldpageX)
  60.             oldpageY = max(pageY,oldpageY)
  61.             end
  62.         end
  63.  
  64. if diff ~=0 then do
  65.     do i =1 to totalpages
  66.         call ppm_SetPageSize(i,oldpageX,oldpageY)
  67.         end
  68.     exit_msg("Pages Resized. Check boxes & try again")
  69.     end
  70. end
  71.  
  72.  
  73. /* Save all pages as .eps files */
  74.  
  75. call ppm_SetPSEPSF(1)
  76. length2 = length(newname)
  77. epsname = substr(newname,1,length2-5) /* strip off ".bklt" */
  78. do i = 1 to totalpages
  79.      /* .eps is only as big as the boxes, not the page,so make a page-size box. */
  80.     newpage = ppm_GotoPage(i)
  81.     pagebox = ppm_CreateBox(0,0,oldpageX,oldpageY,0)
  82.     call ppm_SetPSOutputOrient(i,1)
  83.     call ppm_SetPSPageSize(oldpageX,oldpageY)
  84.     call ppm_SetPSOutput(epsname||i||".eps")
  85.     success = ppm_PrintPagePS(i,1,1)
  86.     if success = 0 then exit_msg("Failed saving .eps of page "i)
  87.     end
  88. /*call exit_msg("temporary stop") /* testing */*/
  89.  
  90. call ppm_DeletePage(1,totalpages)
  91. freshpage = ppm_CreatePage(1,1,0,0)
  92. call ppm_SetPageSize(1,oldpageX,oldpageY)
  93. /* The next 2 lines assume you are printing to a normal A4 or A3 printer */
  94. if oldpageX>oldpageY then call ppm_SetPSPageSize(oldpageY,oldpageX)
  95. if oldpageX>oldpageY then call ppm_SetPSOutputOrient(1,2)
  96. done = ppm_CopyPage(1,1,totalpages-1)
  97.  
  98.  
  99. offset = oldpageX/2
  100. offset = -offset
  101.  
  102. pages = 2*totalpages /* 2 pages on each side of the paper */
  103.  
  104. do i = 1 to totalpages
  105.     newpage = ppm_GotoPage(i)
  106.     Lbox = ppm_CreateBox(0,0,oldpageX/2,oldpageY,0)
  107.     Rbox = ppm_CreateBox(oldpageX/2,0,oldpageX/2,oldpageY,0)
  108.  
  109.  
  110.  
  111.     if i//2=1 then   /* check for odd number pages */
  112.         do
  113.         j = (i-1)/2
  114.         if j=0 then j=totalpages
  115.         k = (totalpages+1)-j  /* Formula for left page, odd sides */
  116.         m = (i+1)/2  /* Right page, odd sides */
  117.         done = ppm_ImportEPSF(Lbox,epsname||k||".eps")
  118.         if done = 0 then exit_msg("Trouble importing "epsname||j||".eps")
  119.         done = ppm_ImportEPSF(Rbox,epsname||m||".eps")
  120.         if done = 0 then exit_msg("Trouble importing "epsname||i||".eps")
  121.         end
  122.     else do
  123.         n = (i/2)+1  /* Left page, even sides */
  124.         p = (totalpages+1)-(i/2)  /* Right box, even sides */
  125.         done = ppm_ImportEPSF(Rbox,epsname||p||".eps")
  126.         if done = 0 then exit_msg("Trouble importing "epsname||i||".eps")
  127.         done = ppm_ImportEPSF(Lbox,epsname||n||".eps")
  128.         if done = 0 then exit_msg("Trouble importing "epsname||j||".eps")
  129.         end
  130.   
  131.     
  132.     /* Must set scale before offset as it scales the offset */
  133.     call ppm_SetBoxScale(Lbox,1,1)
  134.     call ppm_SetBoxScale(Rbox,1,1)
  135.     call ppm_SetBoxOffset(Rbox,offset,0)
  136.     end
  137.  
  138. /* Separate the odd and even sides for double-sided printing */
  139.  
  140. do i = totalpages-1 to totalpages/2 by -1
  141.         done = ppm_MovePage(i,1)
  142.     end
  143. newpage = ppm_GotoPage(1)
  144.  
  145. call exit_msg("Done")
  146. end
  147.  
  148.  
  149. exit_msg: procedure expose colormode oldpsout
  150. do
  151. parse arg message
  152.  
  153.     if message ~= '' then
  154.     call ppm_Inform(1, message,"Resume" )
  155.  
  156.     call ppm_SetColorMode(colormode)
  157.     call ppm_SetPSEPSF(0)
  158.     call ppm_SetPSOutput(oldpsout)
  159.     call ppm_AutoUpdate(1)
  160.     call ppm_ClearStatus()
  161.     call ppm_SetBatchMode(1)
  162.     exit
  163. end
  164.  
  165.