LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-17-2009, 05:50 PM   #1
bourne
Member
 
Registered: Feb 2006
Location: Toronto, Ontario
Distribution: Fedora 10, centos
Posts: 181

Rep: Reputation: 30
Cups and Samba to print one print job to 2 printers - tutorial added


Hey everyone,

I have a samba/cups server setup (on centos 5.3) on which I have been able to successfully setup and share a virtual PDF printer using cups-pdf. I now need the ability to be able to send a print job to 2 printers at once. For instance - A user prints a document that is sent to a printer that prints it out on paper. At the very same time that that happens that very same print job is also sent to the virtual PDF printer and a PDF is created and dumped into a shared directory.

I know how to dump the PDF files in the directory I want however I am totally and completely lost on how to have one print job go to both printers. I have been reading that I can create a simple bash script to do this. However I am not sure I understand exactly how this script works. I assume that I would need to place it under "/usr/lib/cups/backend/" but then I am not sure how to call on it.

I was also thinking that if I could capture the PS file that is created when the user sends the job I could us that in a script to then print to PDF or vice-versa. My problem with this is I haven't been able to figure out a way to actually capture the PS file that is created. Assuming I have this right - when a user sends a job to a printer the system uses the printer drivers to create a PS file which is then sent to the printer?

If anyone could please offer me up some advice or point me in the right direction I would greatly appreciate it. So far google hasn't turned up anything solid and I am close to tearing my hair out trying to figure this out!

Thank you in advance


Cheers

Todd

Last edited by bourne; 09-18-2009 at 02:12 AM.
 
Old 09-17-2009, 06:12 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,710

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
It should be fairly easy. Create a bash script print command that uses ps2pdf and a lpr command to actually print the file. Any windows PS printer driver should work.

http://www.lesbell.com.au/Home.nsf/b...1?OpenDocument
 
Old 09-17-2009, 06:19 PM   #3
bourne
Member
 
Registered: Feb 2006
Location: Toronto, Ontario
Distribution: Fedora 10, centos
Posts: 181

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by michaelk View Post
It should be fairly easy. Create a bash script print command that uses ps2pdf and a lpr command to actually print the file. Any windows PS printer driver should work.

http://www.lesbell.com.au/Home.nsf/b...1?OpenDocument
Omg,

Seeing that all written out that like makes total sense now. I can't believe I couldn't figure that out on my own. Thank you so much for the post, I definitely think I can work with this..

Will report back..

Thank you, thank you


Cheers

Todd
 
Old 09-17-2009, 08:28 PM   #4
bourne
Member
 
Registered: Feb 2006
Location: Toronto, Ontario
Distribution: Fedora 10, centos
Posts: 181

Original Poster
Rep: Reputation: 30
Hey everyone,

So the suggestion that michaelk gave me worked like a charm - Thank you michaelk.

I have tested the setup by using it to create pdf's and I now want to tackle printing to a physical printer.

I have a question related to the print drivers though. It says that ps2pdf will work with virtually any postscript drivers. If that is the case, when I specify the drivers for this printer I should use the drivers for the physical printer I am printing to right? Because technically 2 sets of print drivers would have to be loaded when you add the one virtual representation of the printer because it is printing to both a virtual pdf creator AND a physical printer. But since ps2pdf can use just about any postscript drivers I should use the postscript drivers for the physical printer right?

Sorry I know this is probably so confusing (at least it is for me!). I am just trying to think out loud though because trying to keep it straight in my head is hard.


Thanks again guys...


Cheers

Todd
 
Old 09-18-2009, 02:07 AM   #5
bourne
Member
 
Registered: Feb 2006
Location: Toronto, Ontario
Distribution: Fedora 10, centos
Posts: 181

Original Poster
Rep: Reputation: 30
Hey everyone,

So after a bunch of testing I managed to get it to work.
The link that michaelk gave me was all I needed.

I had to slightly modify it though to suit my purpose.
This is what I did.

**NOTE**: The majority of the stuff I did here I took from this link. I am in no way claiming that this was my idea, I only took what was on this page and modified it to work with what I needed.

I first created the script:

Code:
vim /usr/local/bin/printpdf

-------------------------------

#!/bin/sh
# Shell script to print to PDF file
# Parameters $1 = spool file (smbprn . . .)
# $2 = user name
# $3 = user home directory
# $4 = print job name

OUTDIR=$3
filename="$4.pdf"
echo Converting $1 to "$4" for user $2 in $3 $5 >> pdfprint.log
ps2pdf $1 "$OUTDIR/$4.pdf"
echo Converting complete, moving onto paper - printing $filename >> pdfprint.log
/usr/local/bin/print-cupspdf "$filename"
rm $1
Then I set permissions on it:

Code:
 chmod +x /usr/local/bin/printpdf
I then added an entry in my samba config for my pdf printer:

Code:
[newPDF]
       comment = Print to create PDF
       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/printpdf %s %u /var/spool/cups-pdf/pdf "%J" %p
NOTE: As per the instructions on the site that michaelk gave me the "printing = LPRNG" is very important. I encourage you to play around to figure out exactly how it works!

I then restarted samba:

Code:
 /etc/init.d/smb restart
I then went over to my Windows host to upload the PDF print drivers to this printer. Since I don't have any security enabled on my samba server at this time I found it necessary to creat a "root" account on my windows machine that shared the same password as my "root" account on my linux box. I had to do this in order to gain access to the shared printers properties.

To upload the drivers from windows download the generic PS cups drivers found here.

Code:
**NOTE**: You must create the same directory structure that windows has for its drivers:"/var/spool/samba/drivers/W32X86/3"
create folders like these for each of the architectures of windows.

Access your samba server by opening Windows Explorer and typing: 
\\<Samba-server>\
or
\\centos-1\

If you have everything shared properly you should see some printers and any other shares you have setup.

Then find the folder marked: "Printers and Faxes"

The find your newly created pdf printer
Right click on it and go to "Properties"

When if asked you about the drivers click no so you can proceed to the "Properties" of the printer.

Click the "Advanced" tab
Look for "Driver" followed by a drop down menu followed by "New Driver"

Click "New driver" and follow the on screen instructions. When you are prompted for the driver select "Have disk" and point to the "cups6.inf" that you downloaded.

If everything has gone well you should be able to see those drivers being uploaded to your Samba server to the Windows directories you created.
Now it is back to windows to setup your physical printer

Code:
First open the cups web manager in your browser by typing:

http://localhost:631

Then click "Administration"

Under "Printers" select "Add Printer"
Follow the instructions for setting up your printer

**NOTE**: On the device page I selected IPP and used "IPP://centos-1/HP9040" as my device URI

**NOTE**: to make life a little easier download the PPD for your printer
and finish the instructions.

Next you need to share this printer through samba:
**NOTE**: lines that are commented out are lines I was testing with.

[HP9040]
       comment = Prints to physical as well creates PDF
       #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/printphysical %s %u /var/spool/cups-pdf/pdf "%J"


Then restart samba (and cups if you want: /etc/init.d/smb restart
                                         /etc/init.d/cups restart

Then it is back to windows to load the printer drivers. Follow the exact same procedure for your physical printer replacing the cups PDF generic print drivers for the PS drivers for your particular printer
Once that is done you can now create the second script:

Code:
#!/bin/sh

#lpr -h -p Cups-PDF1 $1
#echo This is from cups-pdf1 $1 and $4 >> pdfprint.log
path="/var/spool/cups-pdf/pdf/"
echo We made it to the physical printer - printing "$path$1" >> pdfprint.log
lpr -h -P HP9040 "$path$1"
The purpose of the first script is to print the PDF file and dumb it into a directory of my choosing. When I was testing this I wasn't able to then run the "lpr" command to print that PDF from within the same script that is why I ended up using 2 different scripts. However now that I know what I was doing wrong I think you can consolidate it down to one script.

As you can see the once the FIRST script creates the PDF we use the SECOND script to actually print the PDF to paper using the created PDF. This happens automatically.

I CANNOT stress enough the importance of the lines redirecting their output to >> "pdfprint.log" - - this saved my life when things weren't working in the beginning. It works as a log file to check where things are going wrong.

But with all this setup you shoud now be able to print 1 print job to both a PDF and paper at the sametime. The nice thing about this method as well is that you can specify it to go to any physical printer you want by simply changing the scripts.

I know there is probably a more efficient way of doing this but this is what I got to work for me and I wanted to share it.

If I am missing anything please let me know - I am writing this half asleep but wanted to get it up before I forgot.

Thanks again guys


Cheers
 
Old 09-18-2009, 02:14 AM   #6
bourne
Member
 
Registered: Feb 2006
Location: Toronto, Ontario
Distribution: Fedora 10, centos
Posts: 181

Original Poster
Rep: Reputation: 30
Hey guys,

Sorry I forgot one thing.
The reason that we load the Windows drivers from Windows to the linux server is because in my experience it is the easiest way of doing it. The reason we do this is so that when a new computer comes online and goes to add a printer from your samba server your Windows box will get the necessary drivers for the printer you wish to use directly from the samba server instead of you having to download them manually.

One you have uploaded the drivers remember to actually add the printer to your windows box using the "Add Printer" procedure in windows


Cheers

Todd
 
Old 09-18-2009, 07:09 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,710

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Just a few comments:
The spool files i.e. /var/spool/samba are not automatically deleted.
The samba printers section automatically adds shares so it isn't necessary to add a specific share for the HP 9040.
Any windows Postscript printer driver should work since it will be converted to PDF and the actual print job accomplished by the cups with the real print driver. Same setup as cups-pdf. The actual print driver is required on the linux computer.
 
Old 09-18-2009, 10:10 AM   #8
bourne
Member
 
Registered: Feb 2006
Location: Toronto, Ontario
Distribution: Fedora 10, centos
Posts: 181

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by michaelk View Post
Just a few comments:
The spool files i.e. /var/spool/samba are not automatically deleted.
The samba printers section automatically adds shares so it isn't necessary to add a specific share for the HP 9040.
Any windows Postscript printer driver should work since it will be converted to PDF and the actual print job accomplished by the cups with the real print driver. Same setup as cups-pdf. The actual print driver is required on the linux computer.
Hey,

You are right - sorry.

There is probably a lot of of unnecessary stuff in my config files and scripts. I originally added the HP9040 share because I wanted to specify specific properties for that printer, but in a case where you do not need to specify special properties the [printer] share is enough.

I see what you are saying for the /var/spool/samba now - I have to add the -r option for the [HP9040] script I wrote or else the spool files will start to pile up. Thank you for pointing that out



Cheers
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cups/samba print w/o passwd in printers.conf? jshaffer Linux - Networking 1 03-29-2010 06:26 AM
CUPS does not print to my network LPD printers ROXR Slackware 3 07-31-2009 02:06 AM
CUPS shows job sent from gLabels, but doesn't print it CJ Chitwood Linux - General 2 09-30-2007 08:27 AM
Clearing CUPS print job? Jonah86 Linux - Newbie 2 05-24-2004 02:11 PM
samba/cups print job size carpman Linux - Networking 1 01-25-2002 05:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:53 PM.

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