Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: fp - a Linux FinePrint-like utility to duplex print .ps files into A5 booklets.

  1. #1
    Join Date
    Aug 2006
    Location
    Europe
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    HOWTO: FinePrint-like utility to save paper and print a booklet in Linux.

    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
    Last edited by docplastic; January 10th, 2010 at 07:45 PM. Reason: New code added

  2. #2
    Join Date
    Jul 2006
    Location
    Southern California
    Beans
    496
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: fp - a Linux FinePrint-like utility to duplex print .ps files into A5 booklets.

    I LOVE fineprint! But I can't get this to execute... Typing 'fp' into a terminal just results in a "bash: fp: command not found" error message.

    I know it must be something ridiculously simple I'm missing...but I can't for the life of me figure out what it is...!

  3. #3
    Join Date
    Oct 2005
    Beans
    Hidden!
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: fp - a Linux FinePrint-like utility to duplex print .ps files into A5 booklets.

    I guess you've missed STEP 2.
    2. Put it into a directory in your PATH.

  4. #4
    Join Date
    Aug 2006
    Location
    Europe
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: fp - a Linux FinePrint-like utility to duplex print .ps files into A5 booklets.

    The code was "redone" to make the page setup even more customizable.

    I would like to see this to grow into some kind of printer filter useable from any program without the extra assle of first producing a .ps file, then enter that file's dir and finally "fp" (fineprint) it.

    But, as is, it is already a rather good "paper saver".

    P.
    Last edited by docplastic; August 28th, 2006 at 12:10 AM.

  5. #5
    Join Date
    Aug 2006
    Location
    Europe
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: fp - a Linux FinePrint-like utility to duplex print .ps files into A5 booklets.

    Quote Originally Posted by wilberfan View Post
    I LOVE fineprint! But I can't get this to execute... Typing 'fp' into a terminal just results in a "bash: fp: command not found" error message.
    Either you put it in a directory somewhere in your path. To see what your current PATH is, open a terminal window and execute the command:
    Code:
    echo $PATH
    Or, you may just put your .ps files in the same directory where you have put the fp script and "dot-slash execute" it:
    Code:
    ./fp some_test_file.ps
    P.
    Last edited by docplastic; August 28th, 2006 at 10:04 PM.

  6. #6
    Join Date
    Jul 2006
    Location
    Southern California
    Beans
    496
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: fp - a Linux FinePrint-like utility to duplex print .ps files into A5 booklets.

    Quote Originally Posted by docplastic View Post
    Either you put it in a directory somewhere in your path. To see what your current PATH is, open a terminal window and execute the command:
    Code:
    env | grep PATH
    Or, you may just put your .ps files in the same directory where you have put the fp script and "dot-slash execute" it:
    Code:
    ./fp some_test_file.ps
    P.
    Hey, thanks for this. It helps. Well, a little.

    OK, that 'PATH' thing confused me--never having encountered it before (aren't n00bs annoying?!). I (assumed) it was my "home" folder, or something...

    This is what comes up when I execute that grep PATH command:

    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games

    I don't really know what it's saying, but it sure explains why 'fp' wouldn't run on my system!
    Last edited by wilberfan; August 28th, 2006 at 08:44 PM. Reason: ahhh....'PATH' (I have some reading to do)

  7. #7
    Join Date
    Jul 2006
    Location
    Southern California
    Beans
    496
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: fp - a Linux FinePrint-like utility to duplex print .ps files into A5 booklets.

    Ooooo-kay. I've got PATH figured out. (Who knew??!) But I had to install 'psutils'. And now I get this:

    /
    usr/bin/pstops release 1 patchlevel 17
    Copyright (C) Angus J. C. Duggan, 1991-1995. See file LICENSE for details.
    Usage: /usr/bin/pstops [-q] [-b] [-wwidth] [-hheight] [-dlwidth] [-ppaper] <pagespecs> [infile [outfile]]
    /usr/local/bin/fp: line 35: 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): command not found

    Printing to the default printer: odd pages first...
    /usr/bin/lpr: Error - no default destination available.
    I guess I now have to figure out how to set my 'default printer'!

  8. #8
    Join Date
    Oct 2005
    Beans
    Hidden!
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: fp - a Linux FinePrint-like utility to duplex print .ps files into A5 booklets.

    In GNOME, take a look in System-Administration-Printing. It might help. Right now I'm on a laptop with no printer at hand, but it worth to try

  9. #9
    Join Date
    Aug 2006
    Location
    Europe
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: fp - a Linux FinePrint-like utility to duplex print .ps files into A5 booklets.

    Quote Originally Posted by wilberfan View Post
    Ooooo-kay. I've got PATH figured out. (Who knew??!) But I had to install 'psutils'. And now I get this:
    ...I guess I now have to figure out how to set my 'default printer'!
    1. Please note that line 35 is a single line that starts with "/usr/bin/psbook..." and ends with "tmp-$1"
    and between "...-p a4" and "4:1L@0.7..." there should only be a single space and nothing else.

    2. In the Gnome menu (menu at the top os the screen) select "System" -> "Administration" -> "Printing" and (re)install your printer. After checking that it is installed, right click on it, open "Properties" and select "Print a Test Page" and check if it spoils some paper. Then click "Close".

    3. At the "Printing" screen left click on your printer and after that right click on it and select "Make Default" (if this option is unavailable it most probably means that it already is your default printer).

    4. Get out of screen that and try using "fp" again.

    P.

  10. #10
    Join Date
    Jul 2006
    Location
    Southern California
    Beans
    496
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: fp - a Linux FinePrint-like utility to duplex print .ps files into A5 booklets.

    Quote Originally Posted by docplastic View Post
    1. Please note that line 35 is a single line that starts with "/usr/bin/psbook..." and ends with "tmp-$1"
    and between "...-p a4" and "4:1L@0.7..." there should only be a single space and nothing else.
    Wow. Thanks. I NEVER would have caught THAT one. (I had "text wrap" on in gedit.... Again, who knew?)


    2. In the Gnome menu (menu at the top os the screen) select "System" -> "Administration" -> "Printing" and (re)install your printer. After checking that it is installed, right click on it, open "Properties" and select "Print a Test Page" and check if it spoils some paper. Then click "Close".
    "The CUPS server could not be contacted". Crap. I wonder what's wrong NOW?...

    OK....more debugging... But thanks loads for the help so far!

    Scott

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •