Purpose: To emulate SOME of the booklet printing functions of the Windows FinePrint utility (http://www.fineprint.com/), i.e. trying to save a few sheets of paper.
It will not concatenate .ps files.
It will not properly print to a .pdf file, nor to any other thing besides a physical printer.
It has been tested to reliably print to many printers (both InkJet and Laser).
It will manually print front and rear (duplex), even in plain, non duplex, printers.
A. Command Line Version (there is also a "point-and-click" version to print from the Nautilus File Browser, see B. paragraph bellow)
1. Copy and paste the following code it into a text file named fp
2. Make it executable with the command: chmod 755 fp
3. Copy that file to a directory in your PATH. You may want to copy it into your own private /bin dir created with the command: mkdir -p /home/`whoami`/bin. If you name it /bin It will be automatically added to your environment the next time your system boots.
4. Print the file with the command: fp filename.ps
5. Remember that any printed file in Linux starts its life as a .ps file, so all what you have to do is, from any program, select "Print", choose any printer, click the "print to file" check mark and print it into a .ps file.
Code:
#!/bin/bash
#
# fp is a fineprint-like utility to duplex print postscript - .ps -
# files into A5 booklets.
#
# Tested with HP, Epson and Canon InkJets.
# It prints front and rear, even in plain (non duplex) printers.
#
# It will accept a .ps file and modify it (compressing
# and rotating each two A4 pages into a single A4 sheet).
#
# It will print front (odd) pages and then wait for you to
# reinsert the printed paper. Once paper reinserted it will
# print rear (even) pages.
#
# In the end you may fold the printed sheets to form an A5 booklet;
#
# Copyright © 2005-2008 by J. Antas.
# Licensed under a GPL 2.0 License (full text available
# at http://www.gnu.org/copyleft/gpl.html)
#
if !((test -f /usr/bin/psbook) && (test -f /usr/bin/pstops)) ; then
echo -e "\nYou need to (re)install the 'psutils' package, " ;
echo -e "Try installing it with 'sudo apt-get install psutils'\n" ;
exit 62;
fi;
if [ -z "$1" ] ; then
echo -e "\nUsage: `basename $0` filename.ps\n";
exit 64;
fi;
if [ -f "$1" ] ; then
echo -e "Script `basename $0` started...\n" ;
#
/usr/bin/psbook $1 | /usr/bin/pstops -q -p a4
"4:1L@0.7(21.0cm,14.95cm)+0L@0.7(21.0cm,0.6cm),3L@0.7(21.0cm,14.95cm)+2L@0.7(21.0cm,0.6cm)"
> "tmp-$1";
echo -e "\nPrinting to the default printer: odd pages first...";
# printer def: -P PrinterName as seen using: lpstat -a
# If no printer it will use the default printer
# You may also set the PRINTER env variable with: export PRINTER=tp0
/usr/bin/lpr -o page-set=odd -o outputorder=reverse "tmp-$1";
echo -n "...after printing this batch, load the paper back in and hit
<enter>";
read dummy;
echo -e "\nNow printing even pages...\n";
/usr/bin/lpr -o page-set=even "tmp-$1";
echo -e "Done.\n";
/bin/rm "tmp-$1";
else
echo -e "\nFile '$1' was not found. Program aborted\n";
exit 66;
fi;
exit 0;
#end of code
UPADATE: 2010.01.10 - Attached bellow is code to "point-and-click" print from Ubuntu's Nautilus File Browser
B. "Point-and-Click" Version:
This version will let you print directly from the Nautilus File Browser by right clicking at the selected .ps file.
NOTE: In Linux a printed file starts its life as a .ps (postscript) file. In order to have a .ps file, all what you have to do is, from any program, select "Print", choose any printer, click the "print to file" check mark and print it into a .ps file.
1. Copy and paste the following code it into a text file named fprint
2. Make it executable: chmod 755 fprint
3. Copy that file to $HOME/.gnome2/nautilus-scripts
4. Start printing by right clicking at the desired .ps file and selecting fprint from the right click drop-down menu.
Code:
#!/bin/bash
#
# fprint: fineprint-like utility to duplex print a .ps files into A5 booklets.
# prints front and rear, even in plain (non duplex) printers;
# accepts a .ps file and modifies it, compressing
# and rotating each two A4 pages into a single A4 sheet;
# prints front (odd) pages first and then waits for you to
# reinsert the printed paper. Once paper reinserted it will
# print rear (even) pages.
# you may fold the printed sheets to form an A5 booklet;
#
# Copyright © 2005-2010 by J. Antas.
# Released under a GPL 2.0 License (full text available
# at http://www.gnu.org/copyleft/gpl.html)
#
# make this script executable and copy it to ~/.gnome2/nautilus-scripts/
#
IFS=$'\n' ; # Set word splitting to happen at a new line, instead of spaces
NEEDBIN="/usr/bin/psbook"
NEEDPACK="psutils"
test -x $NEEDBIN || { zenity --question --title="ERROR: uninstalled dependencies" --text="${0##*/} needs the $NEEDPACK package which is not installed.\n\nTo install $NEEDPACK run the following from a shell terminal:\n\n sudo aptitude -R install $NEEDPACK" && exit; }
printer=$(lpstat -d | sed 's/\(.*\) \(.*\)/\2/') # get DEFAULT PRINTER
# if you configure a printer instance as BW and put bw somewhere in its device name, you will be able to print in BW only:
#printer=$(lpstat -a | sed -n '/bw/s/\([^ ]\+\) .*/\1/p') # choose black&white printer
# if you configure a printer instance as COLOR and put color somwhere in its device name, you will be able to print in color only:
#printer=$(lpstat -a | sed -n '/color/s/\([^ ]\+\) .*/\1/p') # choose black&white printer
tmpfile=$(mktemp)
for FILE in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ; do
file="$(echo "$FILE" | sed 's/ /\\ /g')"
$NEEDBIN "$file" | /usr/bin/pstops -q -p a4 "4:1L@0.7(21.0cm,14.95cm)+0L@0.7(21.0cm,0.6cm),3L@0.7(21.0cm,14.95cm)+2L@0.7(21.0cm,0.6cm)" > $tmpfile
echo "$file" | grep " " > /dev/null 2>&1 && { zenity --info --title="ERROR: pathname has spaces" --text="Offending file: $file"; break; } # if pathname has spaces, abort.
/usr/bin/lpr -P $printer -o page-set=odd -o outputorder=reverse $tmpfile
if zenity --question --title="Fine Printing to $printer..." --text="Printing $file\nPrinting odd pages first,\nWhen finished load the paper back in and click OK"; then
/usr/bin/lpr -P $printer -o page-set=even -o outputorder=reverse $tmpfile
fi
killall zenity
done
[ -f $tmpfile ] && /bin/rm $tmpfile
exit 0
Enjoy,
J. Antas
Bookmarks