home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / propage4.0 / arexx / booklet.pprx < prev    next >
Encoding:
Text File  |  1995-09-09  |  19.8 KB  |  604 lines

  1. /*
  2. This genie will rearrange a document designed as double-page spreads to fit on the sheets of a simple stapled booklet. In this document, the first page has the first page on the right and the last on the left; the rest have pairs in normal order (2 & 3, 4 & 5, etc). It only works for Postscript output (which may be to a non-Postscript printer via Post). 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.
  3. The script does not do the actual printing.
  4. Written by Don Cox ©1993 Revised March 93, July/Aug 95. Not public domain.
  5. */
  6. /* $VER: Booklet Sept 95 */
  7.  
  8. call open("STDERR","ram:traceBk","W")
  9. trace r
  10.  
  11. cr = '0a'x
  12. call SafeEndEdit.rexx()
  13. call ppm_AutoUpdate(0)
  14. oldunits = ppm_GetUnits()
  15. call ppm_SetUnits(2)
  16. call ppm_SetBatchMode(1)
  17.  
  18. mainchoice = ppm_Inform(3,"What do you want to do?","Basic Layout","Page Numbering","Convert for Printing") /* 0 for layout, 1 for numbering, 2 for conversion */
  19. do forever /* each section returns another option */
  20.     if mainchoice = 0 then mainchoice = basiclayout()
  21.     if mainchoice = 1 then mainchoice = pagenumbering()
  22.     if mainchoice = 2 then mainchoice = conversion()
  23.     end
  24.  
  25. /* +++++++++++++++++++++++++++++  ++++++++++++++++++++++++++++++++++ */
  26.  
  27. pagecheck:
  28. totalpages = ppm_NumPages()
  29. if totalpages = 0 then exit_msg("No pages") /* needs an Inform */
  30. if totalpages//2=1 then do /* odd number of pages */
  31. lastpageblank = 0
  32.     if ppm_Inform(2, "You must have an even number of pages. Add a blank page?", "Cancel", "Ok") then do
  33.         /* Create a new page at end of document */
  34.         thispage = ppm_DocLastPage()
  35.         call ppm_MakeTemplate(thispage,0)
  36.         newpage = ppm_CreatePage(thispage,1,2,0,0)
  37.         newpage = ppm_MovePage(newpage+1,newpage)
  38.         totalpages = totalpages+1
  39.         thispage = ppm_GoToPage(newpage+1)
  40.         box = ppm_PageFirstBox(thispage)
  41.         do until box = 0
  42.             call ppm_DeleteBox(box)
  43.             box = ppm_PageNextBox(box)
  44.             end
  45.         end
  46.     else exit_msg("Aborted by User")
  47.     end
  48.  
  49. /* Set all pages to size of largest */
  50. call ppm_ShowStatus("Checking page sizes")
  51. if totalpages>1 then do
  52.     oldpageX = word(ppm_GetPageSize(1),1)
  53.     oldpageY = word(ppm_GetPageSize(1),2)
  54.     diff = 0   /* flag for different page sizes */
  55.     do i = 2 to totalpages
  56.         pageX = word(ppm_GetPageSize(i),1)
  57.         pageY = word(ppm_GetPageSize(i),2)
  58.         if pageX ~= oldpageX | pageY ~= oldpageY then do
  59.             diff = diff+1
  60.             oldpageX = max(pageX,oldpageX)
  61.             oldpageY = max(pageY,oldpageY)
  62.             end
  63.         end
  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, then run Booklet genie again")
  69.     end
  70. end
  71.  
  72. return /* end of page checking */
  73.  
  74. /* +++++++++++++++++++++++++++++++++  ++++++++++++++++++++++++++++++ */
  75.  
  76. pagenumbering:
  77.  
  78. call pagecheck()
  79. choice = ppm_Inform(3,"Number the pages?","No numbers","Copy Existing Box","New boxes") /* 0 for no numbers, 1 for existing, 2 for new */
  80. currentpage = ppm_CurrentPage()
  81. dfirstpage = ppm_DocFirstPage()
  82. pageoffset = currentpage-dfirstpage
  83.  
  84. if choice = 1 then do
  85.     call ppm_UpdateScreen()
  86.     numberbox = ppm_ClickOnBox("Click on box for page numbers")
  87.     if numberbox = 0 then choice = 0
  88.     end
  89. if choice = 1 then do
  90.     /* GetBoxText doesn't work if first page is blank, so check */
  91.     boxcount = ppm_Numboxes(dfirstpage)
  92.     if boxcount = 0 then do
  93.         call ppm_GoToPage(dfirstpage)
  94.         littlebox = ppm_CreateBox(1,1,1,1,0)
  95.         call ppm_GoToPage(currentpage)
  96.         end
  97.     text1 = ppm_GetBoxText(numberbox,0) /* Uncoded */
  98.     text2 = ppm_GetBoxText(numberbox,1) /* With text codes */
  99.     code = left(text2,pos(word(text1,1),text2))/* This compares coded and codeless text to find where the initial chunk of code ends */
  100.     text3 = substr(text2,pos(word(text1,1),text2)) /* The rest of the coded text */
  101.     legend = text1
  102.     end
  103.  
  104. number. = ""
  105. typecode1. = ""
  106. typecode2. = ""
  107. firstnumber = ""
  108. thisword. = ""
  109.  
  110. if choice = 2 then do
  111.     form = "First Page:Page 1"
  112.     legend = ppm_GetForm("Legend for page number box",50,form)
  113.     if legend = "" then choice = 0
  114.     text3 = legend /* No codes */
  115.     code = "\dp\n\ff<(CG)Times>\fs<12.000>\lr<120>" || "\ps<100>\ls<0.000>\t<0>\c<Black>\FP<1>\pn\ds" /* default setup */
  116.     typecode1.1 = code
  117.     call ppm_UpdateScreen()
  118.     topcorner = ppm_GetClickPosition("Click on position for Page number")
  119.     boxwidth = 4 /*temp */
  120.     boxheight = 2
  121.     posX = word(topcorner,1)
  122.     posY = word(topcorner,2)
  123.     end
  124.  
  125. if choice~=0 then do i = 1 to words(legend) /* extract number from string */
  126.     thisword.i = word(legend,i) /* without typographic codes */
  127.     thisword2 = word(text3,i) /* with codes */
  128.     split = pos(thisword.i,thisword2)
  129.     thisword3 = thisword2
  130.     if split~=0 then do 
  131.         typecode1.i = left(thisword2,split-1)
  132.         thisword3 = substr(thisword2,split)
  133.         end
  134.     spos = pos("\",thisword3)
  135.     if spos~=0 then typecode2.i = substr(thisword3,spos) /* code after word */
  136.     if datatype(thisword.i,n) then do
  137.         number.i = thisword.i
  138.         thisword.i = ""
  139.         number.i.format = "arabic"
  140.         if firstnumber = "" then do
  141.             firstnumber = number.i-1 /* We are going to add 1 later */
  142.             pagenumberpos = i
  143.             end
  144.         end
  145.     else if verify(upper(thisword.i), "IVXLCMD")=0 then do
  146.         number.i = unroman(thisword.i)
  147.         thisword.i = ""
  148.         number.i.format = "roman"
  149.         if firstnumber = "" then do
  150.             firstnumber = number.i-1
  151.             pagenumberpos = i
  152.             end
  153.         end
  154.  
  155.     end
  156.  
  157.  
  158. if choice = 1 then do
  159.     box = numberbox
  160.     if box = 0 then break
  161.     boxsize = ppm_GetBoxSize(box)
  162.     boxwidth = word(boxsize,1)
  163.     boxheight = word(boxsize,2)
  164.     position = ppm_GetBoxPosition(box)
  165.     posX = word(position,1)
  166.     posY = word(position,2)
  167.     call ppm_DeleteBox(box)
  168.     end
  169.  
  170. if choice~=0 then do
  171.     LR = "right"
  172.     if posX < (OldPageX/2) then LR = "left"
  173.     if (LR = "left" & (posX+boxwidth)>(OldPageX/2)) then LR = "middle"
  174.     select
  175.         when (LR = "left"|LR = "middle") then do
  176.             boxLL = posX
  177.             boxRL = oldpageX-(posX+boxwidth)
  178.             boxoffset = (pageoffset*2)-1
  179.             if pageoffset = 0 then do
  180.                 LRchoice = ppm_Inform(2,"Which number is this?","Last page","First page")
  181.                 if LRchoice = 1 then boxoffset = 0
  182.                 if LRchoice = 0 then boxoffset = (totalpages*2)-1
  183.                 end
  184.             end
  185.         when LR = "right" then do
  186.             boxLL = oldpageX-(posX+boxwidth)
  187.             boxRL = posX
  188.             boxoffset = (pageoffset*2)
  189.             end
  190.         end
  191.  
  192.  
  193.     if firstnumber = "" then firstnumber = 0
  194.     firstnumber = firstnumber-boxoffset /* In case you pick a box not on first page */
  195.  
  196.     lastnumber = (totalpages*2)+firstnumber
  197.     do i = 1 to totalpages
  198.         thispage = ppm_GoToPage(i)
  199.         oldbox = ppm_BoxAtPosn(boxLL,posY,thispage)
  200.         if oldbox~=0 then call ppm_DeleteBox(oldbox)
  201.         Lbox = ppm_CreateBox(boxLL,posY,boxwidth,boxheight,0)
  202.         Lnumber = ((i-1)*2)+firstnumber
  203.         Lmessage = ""
  204.         do w = 1 to words(legend)
  205.             outnumber = number.w /* usually null */
  206.             if w = pagenumberpos then do
  207.                 outnumber = Lnumber
  208.                 if (i=1 & number.w~="") then outnumber = lastnumber
  209.                 end
  210.             if number.w.format = "roman" then outnumber = roman(outnumber)
  211.             Lmessage = Lmessage||typecode1.w|| outnumber|| thisword.w|| typecode2.w||" "
  212.             end
  213.         overflow = ppm_TextIntoBox(Lbox,Lmessage)
  214.         if overflow = 1 then call ppm_SetBoxSize(Lbox, boxwidth*2, boxheight*2)
  215.  
  216.         oldbox = ppm_BoxAtPosn(boxRL,posY,thispage)
  217.         if oldbox~=0 then call ppm_DeleteBox(oldbox)
  218.         Rbox = ppm_CreateBox(boxRL,posY,boxwidth,boxheight,0)
  219.         Rnumber = ((i*2)-1)+firstnumber
  220.         Rmessage = ""
  221.         do w = 1 to words(legend)
  222.             outnumber = number.w
  223.             if w = pagenumberpos then outnumber = Rnumber
  224.             if number.w.format = "roman" then outnumber = roman(outnumber)
  225.             Rmessage = Rmessage||typecode1.w|| outnumber|| thisword.w|| typecode2.w||" "
  226.             end
  227.         overflow = ppm_TextIntoBox(Rbox,Rmessage)
  228.         if overflow = 1 then call ppm_SetBoxSize(Rbox, boxwidth*2, boxheight*2)
  229.         end /* i=1 to toalpages */
  230.  
  231.     end
  232.  
  233. call ppm_GoToPage(dfirstpage)
  234. call ppm_DeleteBox(littlebox)
  235. mainchoice = ppm_Inform(3,"What do you want to do?","Basic Layout","Exit from Genie","Convert for Printing") /* 0 for layout, 1 for numbering, 2 for conversion */
  236. if mainchoice = 1 then call exit_msg("Done")
  237. else return mainchoice
  238.  
  239. /* ++++++++++++++++++++++++++++++  +++++++++++++++++++++++++++++++++ */
  240.  
  241. /* This converts the document into a set of .eps files for printing */
  242. conversion:
  243. call pagecheck()
  244. call docsaver()
  245. /* Save all pages as .eps files */
  246.  
  247. oldpsout = ppm_GetPSOutput()
  248. oldOrient = ppm_GetPSOutputOrient()
  249. oldPageSize = ppm_GetPSPageSize()
  250. oldDownLoad = ppm_GetPSFontDownload()
  251. call ppm_SetPSFontDownload(0)
  252. oldEPSF = ppm_GetPSEPSF()
  253. call ppm_SetPSEPSF(1)
  254.  
  255. length2 = length(newname)
  256. epsname = substr(newname,1,length2-5) /* strip off ".bklt" */
  257. do i = 1 to totalpages
  258.      /* .eps is only as big as the boxes, not the page, so make a page-size box. */
  259.     statusmessage = "  Saving page "i" as EPS file"
  260.     call ppm_ShowStatus(statusmessage)
  261.     newpage = ppm_GotoPage(i)
  262.     pagebox = ppm_CreateBox(0,0,oldpageX,oldpageY,0)
  263.     call ppm_SetPSOutputOrient(i,1)
  264.     call ppm_SetPSPageSize(oldpageX,oldpageY)
  265.     call ppm_SetPSOutput(epsname||i||".eps")
  266.     success = ppm_PrintPagePS(i,1,1)
  267.     if success = 0 then exit_msg("Failed saving .eps of page "i)
  268.     end
  269.  
  270. call ppm_DeletePage(1,totalpages)
  271. freshpage = ppm_CreatePage(1,1,0,0)
  272. call ppm_SetPageSize(1,oldpageX,oldpageY)
  273. /* The next 2 lines assume you are printing to a normal A4 or A3 printer */
  274. if oldpageX>oldpageY then call ppm_SetPSPageSize(oldpageY,oldpageX)
  275. if oldpageX>oldpageY then call ppm_SetPSOutputOrient(1,2)
  276. done = ppm_CopyPage(1,1,totalpages-1)
  277.  
  278.  
  279. offset = oldpageX/2
  280. offset = -offset
  281. pages = 2*totalpages /* 2 pages on each side of the paper */
  282. do i = 1 to totalpages
  283.     statusmessage = "  Creating new page "i
  284.     call ppm_ShowStatus(statusmessage)
  285.     newpage = ppm_GotoPage(i)
  286.     Lbox = ppm_CreateBox(0,0,oldpageX/2,oldpageY,0)
  287.     Rbox = ppm_CreateBox(oldpageX/2,0,oldpageX/2,oldpageY,0)
  288.  
  289.     if i//2=1 then   /* check for odd number pages */
  290.         do
  291.         j = (i-1)/2
  292.         if j=0 then j=totalpages
  293.         k = (totalpages+1)-j  /* Formula for left page, odd sides */
  294.         m = (i+1)/2  /* Right page, odd sides */
  295.         done = ppm_ImportEPSF(Lbox,epsname||k||".eps")
  296. /*        if done = 0 then exit_msg("Trouble importing "epsname||k||".eps")
  297. n.b. Had to remove error check because of bug in ProPage 4.1  */
  298.         done = ppm_ImportEPSF(Rbox,epsname||m||".eps")
  299.  /*       if done = 0 then exit_msg("Trouble importing "epsname||m||".eps")*/
  300.         end
  301.     else do
  302.         n = (i/2)+1  /* Left page, even sides */
  303.         p = (totalpages+1)-(i/2)  /* Right box, even sides */
  304.         done = ppm_ImportEPSF(Rbox,epsname||p||".eps")
  305. /*        if done = 0 then exit_msg("Trouble importing "epsname||p||".eps")*/
  306.         done = ppm_ImportEPSF(Lbox,epsname||n||".eps")
  307. /*        if done = 0 then exit_msg("Trouble importing "epsname||n||".eps")*/
  308.         end
  309.   
  310.     
  311.     /* Must set scale before offset as it scales the offset */
  312.     call ppm_SetBoxScale(Lbox,1,1)
  313.     call ppm_SetBoxScale(Rbox,1,1)
  314.     call ppm_SetBoxOffset(Rbox,offset,0)
  315.     end
  316.  
  317.  
  318. /* Separate the odd and even sides for double-sided printing */
  319. do i = totalpages-1 to totalpages/2 by -1
  320.         done = ppm_MovePage(i,1)
  321.     end
  322. newpage = ppm_GotoPage(1)
  323.  
  324.  
  325. call ppm_SetPSOutput(oldpsout)
  326. call ppm_SetPSoutputOrient(oldOrient)
  327. call ppm_SetPSPageSize(oldPageSize)
  328. call ppm_SetPSFontDownLoad(oldDownLoad)
  329. call ppm_SetPSEPSF(oldEPSF)
  330.  
  331. call exit_msg("Booklet now converted ready for Postscript printing")
  332. exit
  333.  
  334. /* +++++++++++++++++++++++++++++++++  ++++++++++++++++++++++++++++ */
  335.  
  336. /*exit_msg: procedure expose oldpsout*/
  337. do
  338. parse arg message
  339.     if message ~= '' then call ppm_Inform(1, message,"Resume" )
  340.     call ppm_AutoUpdate(1)
  341.     call ppm_ClearStatus()
  342.     call ppm_SetBatchMode(1)
  343.     exit
  344. end
  345.  
  346.  
  347. /* ++++++++++++++++++++++++++++++++=  +++++++++++++++++++++++++++++ */
  348.  
  349. /* Procedure to read in Roman Numerals  */
  350. unroman: procedure
  351. parse arg nums
  352.  
  353. answer = 0
  354. nums = upper(nums)
  355. nums = space(nums,0)
  356. if verify(nums,"IVXLCDM") ~= 0 then do
  357.     answer = "Bad characters"
  358.     return 0
  359.     end
  360.  
  361. /* padded so that each occupies 5 spaces */
  362. digits =   " I    II   III  IV   V    VI   VII  VIII IX  "
  363. tens =     " X    XX   XXX  XL   L    LX   LXX  LXXX XC  "
  364. hundreds = " C    CC   CCC  CD   D    DC   DCC  DCCC CM  "
  365. /*          111112222233333444445555566666777778888899999  (check padding)  */
  366.  
  367. pos1 = pos("I",nums)
  368. pos2 = pos("V",nums)
  369. select
  370.     when pos1=0 & pos2 = 0 then position = 0
  371.     when pos2 = 0 & pos1 ~=0 then position = pos1
  372.     when pos1 = 0 & pos2 ~=0 then position = pos2
  373.     otherwise position = min(pos1,pos2)
  374.     end
  375.  
  376. if position ~=0 then do
  377.     digs = substr(nums,position)
  378.     nums = left(nums,position-1)
  379.     if digs = "IIII" then decimal = 4
  380.     else decimal =  ((index(digits," "digs))+4)/5
  381.     answer = decimal
  382.     end
  383.  
  384.  
  385. pos1 = pos("X",nums)
  386. pos2 = pos("L",nums)
  387. select
  388.     when pos1=0 & pos2 = 0 then position = 0
  389.     when pos2 = 0 & pos1 ~=0 then position = pos1
  390.     when pos1 = 0 & pos2 ~=0 then position = pos2
  391.     otherwise position = min(pos1,pos2)
  392.     end
  393.  
  394. if position ~=0 then do
  395.     digs = substr(nums,position)
  396.     nums = left(nums,position-1)
  397.     if digs = "XXXX" then decimal = 4
  398.     else decimal =  ((index(tens," "digs))+4)*2
  399.     answer = answer+decimal
  400.     end
  401.  
  402.  
  403. pos1 = pos("C",nums)
  404. pos2 = pos("D",nums)
  405. select
  406.     when pos1=0 & pos2 = 0 then position = 0
  407.     when pos2 = 0 & pos1 ~=0 then position = pos1
  408.     when pos1 = 0 & pos2 ~=0 then position = pos2
  409.     otherwise position = min(pos1,pos2)
  410.     end
  411.  
  412. if position ~=0 then do
  413.     digs = substr(nums,position)
  414.     nums = left(nums,position-1)
  415.     if digs = "CCCC" then decimal = 4
  416.     else decimal =  ((index(hundreds," "digs))+4)*20
  417.     answer = answer+decimal
  418.     end
  419.  
  420. answer = answer+(length(nums))*1000  /* just count the Ms */
  421.  
  422. return answer
  423.  
  424. /* +++++++++++++++++++++++++++++++  ++++++++++++++++++++++++++++++++++++++ */
  425.  
  426. /* Procedure to convert arabic numbers to Roman numbers  */
  427.  
  428. roman: procedure
  429. parse arg nums
  430.  
  431. nums = space(nums,0)
  432. if verify(nums,"1234567890") ~= 0 then do
  433.     answer = "Bad characters"
  434.     return 0
  435.     end
  436.  
  437. answer = ""
  438.  
  439. digits = "i ii iii iv v vi vii viii ix"
  440. tens = "x xx xxx xl l lx lxx lxxx xc"
  441. hundreds = "c cc ccc cd d dc dcc dccc cm"
  442.  
  443. quotient = nums%10
  444. remainder = nums//10
  445. roman = word(digits,remainder)
  446. answer = roman||answer
  447. nums = quotient
  448.  
  449. quotient = nums%10
  450. remainder = nums//10
  451. roman = word(tens,remainder)
  452. answer = roman||answer
  453. nums = quotient
  454.  
  455. quotient = nums%10
  456. remainder = nums//10
  457. roman = word(hundreds,remainder)
  458. answer = roman||answer
  459. nums = quotient
  460.  
  461. do i = 1 to nums
  462.     answer = "m"||answer
  463.     end
  464.  
  465. return answer
  466.  
  467.  
  468.  
  469.  
  470. /* +++++++++++++++++++++++++++++  ++++++++++++++++++++++++++++++++ */
  471.  
  472.  
  473. docsaver:
  474. prevdoc  = ppm_GetDocName()
  475. if ppm_DocChanged() then do
  476.     if ppm_SavedDate() = "Not Saved" then prevdoc = ""
  477.     samessage = "You must save the current document first. Save and continue?"
  478.     if ppm_Inform(2,samessage , "Cancel", "Ok") then call ppm_SaveDocument(prevdoc)
  479.     else exit_msg("Aborted by User")
  480.     prevdoc = ppm_GetDocName()
  481.     end
  482.  
  483. lpos = lastpos("/",prevdoc)  /* Find end of pathname */
  484. if lpos = 0 then lpos = lastpos(":",prevdoc)
  485. docname = substr(prevdoc,lpos+1)  /* Strip off pathname */
  486. pathname = substr(prevdoc,1,length(prevdoc)-length(docname))
  487. call ppm_SetDocName(docname||".bklt")
  488. if length(docname)>30 then do
  489.     docname = delstr(docname,1,length(docname)-30)
  490.     call ppm_SetDocName(docname)  /* File name only */
  491.     end
  492. newname = ppm_GetDocName()   /* Full name including path */
  493.  
  494.  
  495. return
  496.  
  497.  
  498. /* +++++++++++++++++++++++++++++  ++++++++++++++++++++++++++++++++++ */
  499.  
  500. basiclayout:
  501. /* You can change these defaults */
  502. ppnumber = getclip("bookletppnumber")
  503. if ppnumber = "" then ppnumber = 16
  504. pwidth = getclip("bookletpwidth")
  505. if pwidth = "" then pwidth = 148.5
  506. pheight = getclip("bookletpheight")
  507. if pheight = "" then pheight = 210
  508. pcolumns = getclip("bookletpcolumns")
  509. if pcolumns = "" then pcolumns = 1
  510. pgutter = getclip("bookletpgutter")
  511. if pgutter = "" then pgutter = 4
  512. ptmargin = getclip("bookletptmargin")
  513. if ptmargin = "" then ptmargin = 17
  514. pbmargin = getclip("bookletpbmargin")
  515. if pbmargin = "" then pbmargin = 23
  516. pimargin = getclip("bookletpimargin")
  517. if pimargin = "" then pimargin = 20
  518. pomargin = getclip("bookletpomargin")
  519. if pomargin = "" then pomargin = 17
  520. pcreep = getclip("bookletpcreep")
  521. if pcreep = "" then pcreep = 0
  522.  
  523. layoutform = "How many pages?:"ppnumber||cr||"Page width (mm):"pwidth || cr||"Page height (mm):"pheight || cr || "Columns:"pcolumns ||cr|| "Gutter (mm):"pgutter ||cr ||"Top margin (mm):"ptmargin || cr||"Bottom margin (mm):"pbmargin||cr||"Inner margin (mm):"pimargin ||cr||"Outer margin (mm):"pomargin ||cr||"Creep (mm):"pcreep
  524.  
  525. layoutspecs = ppm_GetForm("Enter layout details",8, layoutform)
  526. if layoutspecs = '' then exit_msg("Aborted by User")
  527.  
  528. parse var layoutspecs ppnumber'0a'x pwidth '0a'x pheight '0a'x pcolumns '0a'x ppgutter '0a'x ptmargin '0a'x pbmargin '0a'x pimargin '0a'x pomargin '0a'x pcreep
  529.  
  530. if ~datatype(ppnumber,n) then exit_msg("Invalid entry "ppnumber)
  531. if ~datatype(pwidth,n) then exit_msg("Invalid entry "pwidth) 
  532. if ~datatype(pheight,n) then exit_msg("Invalid entry "pheight)
  533. if ~datatype(pcolumns,n) then exit_msg("Invalid entry "pcolumns)
  534. if ~datatype(pgutter,n) then exit_msg("Invalid entry "pgutter)
  535. if ~datatype(ptmargin,n) then exit_msg("Invalid entry "ptmargin)
  536. if ~datatype(pbmargin,n) then exit_msg("Invalid entry "pbmargin)
  537. if ~datatype(pimargin,n) then exit_msg("Invalid entry "pimargin)
  538. if ~datatype(pomargin,n) then exit_msg("Invalid entry "pomargin)
  539. if ~datatype(pcreep,n) then exit_msg("Invalid entry "pcreep)
  540. call setclip("bookletppnumber",ppnumber)
  541. call setclip("bookletpwidth",pwidth)
  542. call setclip("bookletpheight",pheight)
  543. call setclip("bookletpcolumns",pcolumns)
  544. call setclip("bookletpgutter",pgutter)
  545. call setclip("bookletptmargin",ptmargin)
  546. call setclip("bookletpbmargin",pbmargin)
  547. call setclip("bookletpimargin",pimargin)
  548. call setclip("bookletpomargin",pomargin)
  549. call setclip("bookletpcreep",pcreep)
  550.  
  551. /* convert to cm */
  552. pwidth = pwidth/10
  553. pheight = pheight/10
  554. pgutter = pgutter/10
  555. ptmargin = ptmargin/10
  556. pbmargin = pbmargin/10
  557. pimargin = pimargin/10
  558. pomargin = pomargin/10
  559. pcreep = pcreep/10
  560.  
  561. docpages = ppnumber/2
  562. call docsaver()
  563. call ppm_New()
  564. page = ppm_CreatePage(1,1,1,0,0)
  565. call ppm_SetPageSize(page,pwidth*2,pheight)
  566. call ppm_CopyPage(1,1,docpages-1)
  567.  
  568.  
  569. pboxwidth = pwidth-(pimargin+pomargin)
  570. pboxheight = pheight-(ptmargin+pbmargin)
  571. prmargin = pwidth+pimargin
  572. pcwidth = (pboxwidth-((pcolumns-1)*pgutter))/pcolumns /* width of 1 column */
  573.  
  574. oldbox = 0
  575. do i=1 to docpages
  576.     page = ppm_GoToPage(i)
  577.     if i~=1 then do c=1 to pcolumns
  578.         plcleft = pomargin+((pcwidth+pgutter)*(c-1))
  579.         box = ppm_CreateBox(plcleft,ptmargin,pcwidth,pboxheight,0)
  580.         call ppm_LinkBox(oldbox,box)
  581.         oldbox = box
  582.         end
  583.     do c= 1 to pcolumns /* right page */
  584.         prcleft = prmargin+((pcwidth+pgutter)*(c-1))
  585.         box = ppm_CreateBox(prcleft,ptmargin,pcwidth,pboxheight,0)
  586.         call ppm_LinkBox(oldbox,box)
  587.         oldbox = box
  588.         end
  589.     end
  590. i=1 /* do last page of booklet */
  591. page = ppm_GoToPage(i)
  592. do c=1 to pcolumns
  593.     plcleft = pomargin+((pcwidth+pgutter)*(c-1))
  594.     box = ppm_CreateBox(plcleft,ptmargin,pcwidth,pboxheight,0)
  595.     call ppm_LinkBox(oldbox,box)
  596.     oldbox = box
  597.     end
  598.  
  599.  
  600. mainchoice = ppm_Inform(3,"What do you want to do now?","Exit","Page Numbering","Convert for Printing") /* 0 for exit, 1 for numbering, 2 for conversion */
  601. if mainchoice = 0 then call exit_msg("Done")
  602. else return mainchoice
  603.  
  604.