Printing two pages on one physical page

Extracted from debian-user
Tip provided by Wayne T. Topa
>      Is it possible to make postscipt files print out with two
> postscript pages fitting onto one physical page (or is there an option in
> ghostview for this?), please? 350 pages of hurd manual could do with being
> shrunk before I use _all_ my paper up....
>
 Look at the man pages for a2ps, enscript, psresize, and psselect.
 
 With combinations of the above I have scripts that Allow any file (ps,
 gz,etc) to print as 1 page, 2 pages 1 side, 2 pages both sides, 4
 pages one side and 4 pages - both sides ( Man pages look great this
 way).
 The script is following.


#!/bin/sh 
#

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# Printer Menu Program Written by Wayne Topa.

## These are the only things you really need to change....
###########################################################

A2PS=/usr/local/bin/a2ps      # used to convert to PS & page formating
ENSCRPT=/usr/local/bin/enscript
LSRPRT=/usr/local/bin/laserprt     # Used for booklet printing
PAGE_FILE=/usr/local/bin/psselect    # used to print Odd & Even pages

#  The following files are also required
# psnup, psresize, psselect
# these are part of the psutils package available from
# metalab.unc.edu
# 
# laserprt by Bob van der Poel
# http://www.kootenay.com/~bvdpoel/ 
###########################################################
## These are variables common to all the routines
TMP=/tmp           # Where Temp. variables are stored.
###########################################################

########################################
#
# get_confirm
# 
# function to check that we are doing what the user wants

get_confirm() {
 echo -e "Is this correct? (Y/N) \c"
 while true
 do
  read x
  case "$x" in
   y | yes | Y | Yes | YES)
   return 0;;
   n | no | N | No | NO)
   echo
   echo "Cancelled"
   return 1;;
   *) echo "Please enter yes or no" ;;
 esac
done
}

######################################
#
# clr_temps
# 
# Clear out the temps files we used
# 
clr_temps()
{
 rm -f $TMP/new_file $TMP/resized $TMP/format_file
 return
}

######################################
#
#ck_zip
# see if file is gzipped & gunzip it
# 
ck_zip()
{
 extension=${print_file##*.}
 if [ $extension = gz ]; then
  ext=1                                   
  PFILE=${print_file%.*}          
  gunzip $print_file
 else
  PFILE=$print_file
 fi
 return
}

######################################
#
# ck_orig
# 
# If original file was gzipped, re-gzip
#   it back to original name
ck_orig()
{
 if [ ext != 0 ]; then
  gzip $PFILE
 fi
 return
}

######################################
#
# prt_both
# 
# routine to print odd and even pages
prt_both()
{
 echo " Hit Return to print Odd Pages"
 read
 $PAGE_FILE -o $TMP/resized |lpr
 if [ "$type_choice" = "h" ]; then
  echo "Re-insert paper into drawer. Page #'s at Rear of tray"
 else if [ "$type_choice" = "i" ]; then
  echo "Re-insert paper into drawer. Page #'s on Right side of tray"
  else
  echo "Re-insert paper into drawer. Page #'s at Front of tray"
  fi 
 fi
 echo
 echo " Hit Return to print Even Pages"
 read
 $PAGE_FILE -e $TMP/resized |lpr
 return
}

######################################
#
# ps_resize()
#
# resize A4 to Letter or vice versa
#
# File to resize = $TMP/format_file
# Temp file      = $TMP/new_file
# Re-Sized File  = $TMP/resized
#
ps_resize()
{
 if [ $paper_choice = 'Letter' ]; then
  # convert from A4 to Letter, just in case
  #    psresize -PA4 -pletter $TMP/format_file $TMP/new_file
  # resize the paper to better fit letter size paper
  psresize -Pletter -w8.4in -h10.9in $TMP/format_file $TMP/resized
 else
  psresize -Pletter -pA4 $TMP/format_file $TMP/new_file
  psresize -pA4 $TMP/new_file $TMP/resized
 fi
 return
}

######################################
#
# Prt_1side
# Print file on 1 side of paper
# Convert it to PS so it looks better
# cat file  | psnup -2 -Pletter | lpr works also
# a2ps -1 -f(Font&size) file 

prt_1side() 
{
 ck_zip
 $A2PS -1RE -f 11.5 -M $paper_choice $PFILE
 ck_orig
 return
}

######################################
#
# prt_2-1
# Print file on one side as 2 pages/side
# There are options for this type of printing
# laserprt file -t 4 file
# a2ps -2 file  
# enscript -2 file
#
prt_2-1()
{
 ck_zip
 $A2PS -f8 -2 -jrE -T4 -L57 $PFILE
 ck_orig
 return
}

######################################
#
# prt_4-1   4 pages printed on 1 side of paper
#options
#a2ps -M$paper_choice -4 $print_file
#  enscript -f Times-Roman12 -G2E -U2 -i 2l -L 57 $print_file
#  a2ps -Mpaper_choice -4 -f 8 $print_file
#
prt_4-1()
{
 ck_zip
 $A2PS -M$paper_choice -E -T4 -4 -f8 $PFILE --output=$TMP/format_file
 #  $ENSCRPT -f Helvetica12 -T 4 -Gj2rE -U2 -L 57 -p $TMP/format_file $PFILE
 ps_resize  
 lpr $TMP/resized  
 clr_temps
 ck_orig
 return
}

######################################
#
# prt_1-2  Print 1 page on each side of paper
#
prt_1-2()
{
 ck_zip
 $ENSCRPT -M $paper_choice -f Times-Roman12 -Gj1E -L 57 -p $TMP/format_file $PFILE
 ps_resize
 prt_both
 clr_temps
 ck_orig
 return
}

######################################
#
# prt_2-2  2 Pages on both sides of paper
#
# laserprt -dm 3 -t 4 file
#
prt_2-2()
{
 ck_zip
 $LSRPRT -dm 3 -t 4 $PFILE
 ck_orig
 return
}

######################################
prt_4-2()
{
 ck_zip
 $A2PS -4 -f8 $PFILE --output=$TMP/format_file
 ps_resize
 prt_both
 clr_temps
 ck_orig
 return
}

######################################
prt_book()
{
 ck_zip
 $LSRPRT -bm 3 -t 4 $PFILE
 ck_orig
 return
}


######################################
#
# prt_man_page(s) 4 up both sides of paper
#
# Don't have an A4 printer so can't check this.
#
# Temp file      = $TMP/new_file
# Formated file  = $TMP/format_file
#
prt_man_page_4()
{
 man $print_file > $TMP/new_file
 $ENSCRPT -b "Man Page - "$print_file -f Helvetica12.5 -G2rE -U2 -L 57 -p $TMP/format_file $TMP/new_file
 ps_resize
 prt_both
 clr_temps
 return
}

######################################
#
# prt_man_page_2 2 up man pages, both sides
#
# man -t $1 | psnup -pletter -n 2 |lpr
#
prt_man_page_2()
{
 man $print_file > $TMP/new_file
 #$ENSCRPT -b "Man Page - "$print_file -f Times-Roman10 -Gj2rE -L 60 -p $TMP/format_file $TMP/new_file
 # ps_resize
 # prt_both
 clr_temps
 return
}

#############################################
#
# prt_PS_2-1
#
# print a ps file 2 pages on 1 side of paper
#
prt_PS_2-1()
{
 ck_zip
 cat $print_file>$TMP/format_file
 ps_resize
 $A2PS -2 -f9 $TMP/resized
 ck_zip
 clr_temps
 return
}

###########################################
#
# prt_PS_2-2
#
# print PS file 2 pages to both sides of paper
#
#
prt_PS_2-2()
{
 ck_zip
 cat $print_file>$TMP/format_file
 ps_resize
 cat $TMP/resized > $TMP/new_file
 cat $TMP/new_file |psnup -2 > $TMP/resized
 ck_zip
 clr_temps
 return
}

######################################
#
# setup paper choice
#
setup_paper()
{
 if [ "$paper_choice" = "a" ]; then
  paper_choice="Letter"
 else
  paper_choice="A4
 fi
 return
}

##############################################
#
# set up print option type
#
setup_option_type()
{
 case "$type_choice" in
  a) option_choice="Single sided page";;
  b) option_choice="2 pages on 1 side";;
  c) option_choice="4 pages on 1 side";;
  d) option_choice="1 page  on 2 sides";;
  e) option_choice="2 pages on 2 sides";;
  f) option_choice="4 pages on 2 sides";;
  g) option_choice="a booklet (2 pages/2 sides)";;
  h) option_choice="man page 4 pages on 2 sides";;
  i) option_choice="man page 2 pages on 2 sides";;
  j) option_choice="PS file 2 pages 1 side";;
  k) option_choice="PS file 2 pages 2 sides";;
 esac
 return
}

# The main program menu
#
# print single sided page [ .txt, .gz, .html, manual pages, .ps, .dvi ]
# print 2 pages on 1 side
# print 4 pages on 1 side
# print 2 pages on both sides
# print 4 pages on both sides
# print a booklet
#
#
#
set_type_choice() {
 #clear
 printf "\n\t\t%s\n\n" " Print Menu "
 echo "Options :"
 echo
 echo "   a) Print a single sided page"
 echo "   b) Print 2 pages on 1 side"
 echo "   c) Print 4 pages on 1 side"
 echo "   d) Print 1 page  on 2 sides"
 echo "   e) Print 2 pages on 2 sides"
 echo "   f) Print 4 pages on 2 sides"
 echo "   g) Print booklet (2 pages/2 sides)"
 echo "   h) Print man page 4 pages on 2 sides"
 echo "   i) Print man page 2 pages on 2 sides"
 echo "   j) Print PS file 2 pages 1 side"
 echo "   k) Print PS file 2 pages 2 sides"
 echo ""
 echo "   q) Quit"
 echo
 echo -e "Please enter choice and press return \c"
 read type_choice
 if [ "$type_choice" = 'q' ]; then
  exit 0
 fi
 setup_option_type
 echo
 if [ "$type_choice" = "h" ] || [ "$type_choice" = "i" ]; then
  echo "Enter Man page to print"
 else
  echo -e "Enter path/filename.type \c"
 fi
 read print_file
 ORGFILE=$print_file
 echo
 echo " Paper size"
 echo
 echo " a) Letter   b) A4"
 echo
 echo -e "Enter paper type and press return \c"
 read paper_choice
 setup_paper
 echo TYpe Choice = $type_choice
 if [ "$type_choice" = h ] || [ "$type_choice" = i ]; then
  echo " You have selected Man  - "$print_file
 else
  echo " You have selected file - "$print_file
 fi
 echo "       to be printed as - "$option_choice
 echo "                     on - "$paper_choice" size paper."
 echo
 get_confirm
 return
}

###########################################################
# The main program itself
#
#
# 
# Get type of page to print
# Get file to print
# Get type of paper to print
#
#  clear
while [ "$quit" != "y" ];
do
 set_type_choice
 case "$type_choice" in
  a) prt_1side;;
  b) prt_2-1;;
  c) prt_4-1;;
  d) prt_1-2;;
  e) prt_2-2;;  
  f) prt_4-2;;
  g) prt_book;;
  h) prt_man_page_4;;
  i) prt_man_page_2;;
  j) prt_PS_2-1;;
  k) prt_PS_2-2;;
  q | Q ) quit=y;;
 esac
done
echo "Finished"
exit 0

Follow-up :
| Previous | Next | Index of category | Main Index | Submit |


Appears in section(s) : printer
Tip recorded : 21-03-1999 19:08:15
HTML page last changed : 27-07-1999 20:08:52