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