home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / postscri / 6134 < prev    next >
Encoding:
Internet Message Format  |  1993-01-01  |  3.7 KB

  1. Path: sparky!uunet!bcstec!bcsaic!sundry!sdc!cek
  2. From: cek@sdc.boeing.com (Conrad Kimball)
  3. Newsgroups: comp.lang.postscript
  4. Subject: Re: printing a range of pages from a postscript file
  5. Message-ID: <7700@fury.BOEING.COM>
  6. Date: 31 Dec 92 08:27:46 GMT
  7. References: <1h7flvINNjc1@tamsun.tamu.edu> <id.ES1W.3M2@ferranti.com>
  8. Organization: Boeing Computer Services (ESP), Seattle, WA
  9. Lines: 124
  10.  
  11. In article <1h7flvINNjc1@tamsun.tamu.edu> vamsee@abgen.tamu.edu (Vamsee Lakamsani) writes:
  12. > I have an 80 page postscript document and I need only pages 50-60,75,
  13. > 78 and 80 (this is just a silly example). Is there someway that I can tell
  14. > the printer to print only these pages?
  15. >
  16. > The printer is an Apple LaserWriter 2.
  17. > We use "/usr/bin/lp". Is there some software for extracting only these 
  18. > pages from the document ?
  19.  
  20. I use the following script that I got off the net some time ago.
  21. --------------
  22. #!/bin/sh
  23.  
  24. # Extracts a range of pages from a PostScript file, writing
  25. # output to standard out.
  26. #
  27. # Synopsis:
  28. #
  29. # pssplit file first_page [ last_page ]
  30. #
  31. # If last_page is omitted, extracts from first_page to the end.
  32. # To extract one page, make last_page the same as first_page.
  33.  
  34. if test $# -gt 2; then
  35.     LAST=`expr $3 + 1`
  36. else
  37.     LAST=0
  38. fi
  39.  
  40. sed -n -e "#
  41.        # first loop to copy all lines of the prolog
  42.        #
  43.        :prolog
  44.        1,/^%%EndProlog/{p
  45.                             n
  46.                             b prolog
  47.                            }
  48.  
  49.        # end of the prolog - now skip lines until we find the first
  50.        # page of the target range or a trailer.  if we encounter any
  51.        # included images we skip them entirely, without checking
  52.        # their contents
  53.  
  54.            :first
  55.            /^%BeginIncludedImage/b includ1
  56.            /^%%Page: [^ ][^ ]* $2\$/b pages
  57.            /^%%Trailer/b trailr1
  58.            n
  59.            b first
  60.  
  61.        # found an included image - skip until end of included image,
  62.        # then rejoin ordinary skip loop (above)
  63.  
  64.        :includ1
  65.            /^%EndIncludedImage/b first
  66.        n
  67.        b includ1
  68.  
  69.        # found a trailer - loop to save lines in hold space until:
  70.        #
  71.        # 1. a new page (go back to "first" to skip more lines),
  72.        # 2. a "%!" line (go back to "first" to skip more lines),
  73.        # 3. end of file (print saved trailer).
  74.  
  75.            :trailr1
  76.            /^%%Page: /b first
  77.            /^%\!/b first
  78.            H
  79.            /^%%Trailer/h
  80.            \${g
  81.               p
  82.              }
  83.            n
  84.            b trailr1
  85.  
  86.        # found start of the target page range - copy lines until we
  87.        # find the end of the target page range
  88.  
  89.            :pages
  90.            /^%%Page: [^ ][^ ]* $LAST\$/b skip
  91.            p
  92.            n
  93.            b pages
  94.  
  95.        # found end of the target page range - skip lines until we
  96.        # find the start of the trailer.  if we encounter any
  97.        # included images we skip them entirely, without checking
  98.        # their contents
  99.  
  100.            :skip
  101.            /^%BeginIncludedImage/b includ1
  102.            /^%%Trailer/b trailr2
  103.            n
  104.            b skip
  105.  
  106.        # found an included image - skip until end of included image,
  107.        # then rejoin ordinary skip loop (above)
  108.  
  109.        :includ2
  110.            /^%EndIncludedImage/b skip
  111.        n
  112.        b includ2
  113.  
  114.        # found a trailer - loop to save lines in hold space until:
  115.        #
  116.        # 1. a new page (go back to "skip" to skip more lines),
  117.        # 2. a "%!" line (go back to "skip" to skip more lines),
  118.        # 3. end of file (print saved trailer).
  119.  
  120.            :trailr2
  121.            /^%%Page: /b skip
  122.            /^%\!/b skip
  123.            H
  124.            /^%%Trailer/h
  125.            \${g
  126.               p
  127.              }
  128.            n
  129.            b trailr2" $1
  130. -- 
  131. --
  132. Conrad Kimball       | Client Server Tech Services, Boeing Computer Services
  133. cek@sdc.boeing.com   | P.O. Box 24346, MS 7A-35
  134. (206) 865-6410       | Seattle, WA  98124-0346
  135.