LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-11-2007, 09:06 PM   #1
fukawi2
Member
 
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Rep: Reputation: 34
CUPS Routing Colour Print Jobs


Is it possible to setup a Class in CUPS with 2 printers, one colour, one black & white, then route jobs to each printer based off the document data - Jobs with colour to the colour printer, and anything without colour to the B&W printer.

Or any way to achieve the same thing, doesn't have to be through a class. I'm happy to have just the 2 printers setup, but if someone prints a B&W document to the colour printer, then have it forcefully re-routed to the B&W printer.

We currently have an Oki C7350 Colour Laser which is costing a fortune in consumables and repairs, and I want to replace with a B&W HP (something like a HP 4250), and a small colour laser, then get CUPS to do some smart stuff

Everything already runs through a CUPS server with Samba, so there's no problem there, just need to figure out the smart part!

Any input would be great
 
Old 09-12-2007, 06:15 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
I believe that both printers are postscript so this might work for you. You can create a virtual printer share in samba that executes a scipt to search the spooled file for the lack of postscript color commands. A simple bash if statement can be used to send the job to the correct printer via the lpr command and then delete the spool file. The /usr/local/bin/printselect bash script does the actual searching and printing.

example:
[someprinter]
comment = Auto printer
printing = LPRNG
path = /var/spool/samba
printable = yes
# Parameters below: spool file name, job name, user name, user home dir
print command = /usr/local/bin/printselect %s %u %H "%J"

I have not thought about any cavaets yet....

Last edited by michaelk; 09-12-2007 at 06:20 PM.
 
Old 09-12-2007, 06:55 PM   #3
fukawi2
Member
 
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Original Poster
Rep: Reputation: 34
I love PostScript printers

I hadn't thought about doing it using Samba... Samba won't complain that lprng isn't installed?

Does anyone know what the Postscript colour commands are?

The script would be something like this...?
Code:
#!/bin/bash

COLOURJOB=`grep %1 'color=yes'`

if [ -z "$COLOURJOB" ] ; then
    lpr -Pbwprinter %1
else
    lpr -Pcolourprinter %1
fi
(Replace 'color=yes' with whatever the PS colour command is)
 
Old 09-12-2007, 07:10 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
http://www.physics.emory.edu/~weeks/...s/colorps.html

Does not matter that lprng is not installed since it isn't using any LPRng programs.

Report back if it works.
 
Old 09-12-2007, 07:40 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by fukawi2 View Post
Does anyone know what the Postscript colour commands are?

The script would be something like this...?
Code:
#!/bin/bash

COLOURJOB=`grep %1 'color=yes'`

if [ -z "$COLOURJOB" ] ; then
    lpr -Pbwprinter %1
else
    lpr -Pcolourprinter %1
fi
(Replace 'color=yes' with whatever the PS colour command is)
Well, it’ll be a little more complicated than this. You see, the commands such as setrgbcolor or setcmykcolor can be used to set the color to a “color” or a shade of gray (which is technically a color). Moreover, because postscript is a programming language, you can’t just grep for the three tokens textually preceding a “setrgbcolor” (since the actual “parameter” could have been manipulated prior to being received by setrgbcolor). E.g.,
Code:
%!
0 0 0 setrgbcolor            % sets color to black
0 0 moveto 1 0 lineto stroke % this line is black
0 0 1 setrgbcolor            % sets color to blue
0 0 moveto 0 1 lineto stroke % this line is blue
0 0 -1 1 add setrgbcolor     % also sets color to black
0 1 moveto 1 1 lineto stroke % this line is black
So you’ll have to have some kind of interpreter do this for you. You might take a look at some of the “devices” of ghostscript. This is what a sample script might look like in my mind:
Code:
#!/bin/bash

#If $1 is the name of a postscript file, this
#script will determine whether the file is suitable
#for printing as color or grayscale

GRAYED="$1.grayed.ps"

gs -q -sDEVICE=psgray -sOutputFile=${GRAYED} ${1}

if [ -z "$(diff ${1} ${GRAYED})" ] ; then
    echo "$1 is grayscale"
else
    echo "$1 is color"
fi
Obviously, there should be a better way to determine the changes, but that’s the idea.
 
Old 09-13-2007, 10:32 PM   #6
fukawi2
Member
 
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Original Poster
Rep: Reputation: 34
This is one of those times to step out of my comfort zone and in to my learning zone and learn something new... Schweet!

Thanks osor, I'll have a fiddle with that and see if I can't figure something.

Will report back with how I go, have a good weekend all
 
  


Reply

Tags
cups, printer, routing


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
holding all print jobs in CUPS mohtasham1983 Linux - Server 1 08-22-2007 11:32 AM
cups - deleting print jobs mikejd Linux - Software 11 05-15-2007 08:48 AM
CUPS trunicating print jobs to 2 pages tisource Linux - Software 1 02-01-2006 11:28 AM
cups aborts print jobs sneak Linux - Software 0 11-09-2004 04:45 PM
Keep a record of print jobs with cups exodist Linux - Software 3 11-02-2004 04:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration