Recipe / HOWTO for printing from linux/unix/BSD to Windows

filed under: ,

29 December 2006


This recipe tells how to configure a linux/unix/BSD machine and a Windows machine such that the unix machine can print to a printer attached to the Windows machine, even if it isn’t a postscript printer. This could also be adapted to work for OSX client machines.

How it works

Starting from the unix machine, a print job travels thusly:

  1. User prints something to a CUPS-configured print queue
  2. CUPS generate a postscript version of the printout, using Ghostscript and/or foomatic and/or gimp-print
  3. CUPS passes the postscript file to Samba which passes it over the network to a network-shared (virtual) postscript printer on the Windows box
  4. The virtual printer takes the poscript file and gives it RedMon which gives it to Ghostscript (on the Windows box), which prints it out to the actual printer

There’s a bit of work on the Windows side to set up Ghostscript and the virtual printer, and another bit of work on the unix side to set up Samba so you can print over the network, and then another bit of work to set up CUPS so it can accept printjobs and route them to Samba.


A Windows machine (I used Windows XP, but this may work for others), with:

  • a printer (I used a Canon i470D, but that’s irrelevant)
  • Ghostscript (I used the ‘AFPL’ version, but the ‘GNU’ version will probably also work)
  • GSView
  • RedMon

A linux/unix/BSD machine (I used NetBSD, but this should work for others), with:

  • a network connection to the Windows machine
  • Samba
  • CUPS
  • Ghostscript (I used the ‘AFPL’ version, but the ‘GNU’ version will probably also work) – possibly optional
  • gimp-print (now called gutenprint) – possibly optional
  • the foomatic PPDs and scripts – possibly optional
  • beh – completely optional

Most of the unix packages are available via pkgsrc, if you have it available. I used:

  • net/samba
  • print/cups
  • print/ghostscript-esp
  • print/gimp-print-cups
  • print/foomatic-filters-cups
  • print/foomatic-ppds-cups



  1. Look at the diagram and then follow steps 1-12 of these instructions exactly, but with the following modifications:
    1. In Steps 2-4, use the latest versions of the respective software packages. There’s no need to use older versions.
    2. In Step 8, I configured the virtual printer as an HP Color Laserjet 4550, based on a recommendation from another site.
    3. Ignore the last two steps (about setting up print client machines).

Unix – Samba

  1. Install and configure Samba to your liking.
  2. Make sure you’re running nmbd and smbd
  3. Make sure you have load printers = yes set in smb.conf
  4. Make sure you can see Windows shares from your unix machine. (Try smbclient -L WINDOWS_MACHINE_NAME -N.) Make sure the virtual postscript printer shows up in the list of shares.
  5. Make sure everything still works after a machine reboot
  6. Test that you can print from the unix box, through samba, to the virtual postscript printer, to the real printer
    1. Try a command like this: smbspool smb://HOST_NAME/PRINTER_NAME 1 root test 1 "" < /path/to/some/postscript/file
      1. You may get an error like “ ticket cache found…”. That’s probably ok.
    2. Something should print

Unix – CUPS

  1. You might want to backup your existing printcap file (probably in /etc), because CUPS will overwrite it
  2. Install and configure CUPS
  3. Run it, and make sure you can get to http://localhost:631/admin. Login as ‘root’ with your root password. Don’t worry about setting up printers yet.
  4. Make sure it still works after a machine reboot
  5. If you’re on BSD, you probably have local versions of lp, lpr, lpq, and lprm commands that will conflict with the versions just installed by CUPS. You probably want the CUPS versions. I just renamed the BSD versions, and that lets the CUPS versions be found on the PATH.
  6. Install Ghostscript, gimp-print, and foomatic. You won’t necessarily need all three of those, but I did, and it doesn’t hurt to have them, and they make your printing setup more flexible to changes, other printers, etc.
  7. Tell CUPS about Samba by creating a symlink as described here. On NetBSD with pkgsrc the backend directory was in /usr/pkg/libexec/cups/backend. Don’t use those instructions for setting up the printer.
  8. Restart CUPS
  9. Configure a printer in the CUPS webadmin. This will take you through a little wizard, as follows:
    1. The first page asks you to name the printer. The only required field is ‘Name’ and it’s the name that users on the unix box will see. It can be anything.
    2. The second page asks you to choose the protocol for reaching the printer. Choose “Windows Printer via SAMBA” from the dropdown. If it’s not there, you probably didn’t create the symlink correctly, or you forgot to restart CUPS.
    3. The third page asks you for the path to your printer. Type the network path to your virtual Windows printer. Example: smb://HOST_NAME/PRINTER_NAME
    4. The fourth page asks you to choose a printer manufacturer. If you installed gimp-print and foomatic you should have a ton of items in the list. Choose the one that matches the virtual Windows printer you set up earlier. (HP, in my case.) Alternatively, you can also use ‘Generic’ to get a generic Postscript driver.
    5. The fifth page asks you to choose the actual driver. Choose the one that matches your printer. If you’re going the ‘Generic’ route, scroll all the way to the bottom and choose “Generic Postscript Printer Foomatic/Postscript (recommended) (en)”.
    6. That’s it! The printer will show up on the printers page.
  10. Try printing a test page (through the webadmin) and see if it works. If it doesn’t, set LogLevel debug in cupsd.conf and try again. See what the log says.
    1. I ran into a problem where CUPS wasn’t generating the correct set of command-line arguments for the smbspool program (which we symlinked to smb earlier). If you suspect that you’re having that problem, try replacing the smb symlink with a shell script containing the following two lines:
      1. #!/bin/sh
      2. cat <&0 | /usr/pkg/bin/smbspool "$1" "$2" "$3" "$4" "$5"
    2. Remember to make the script executable
    3. You can add debugging statements to that script to see what’s being passed to it (if anything at all!) or to save the output somewhere

Other info

  1. You might want to install beh. I didn’t, but I’m the only user of my NetBSD system.
  2. You might want to check out these other resources for more info:
    1. Another set of instructions (with a different approach) for creating the virtual postscript printer
    2. A set of instructions, similar to these, for printing from OSX to Windows
    3. A HOWTO for CUPS on BSD
    4. A quick-start guide for CUPS
  1. Adrian Waters says:

    Which year was this published? The date is shown as POSTED DEC 29, 03:22 PM

  2. Nathan Arthur says:

    Ah, good point! The format shown is the textpattern default, which seems silly. I have switched it to show the year (which was 2006). I am still using this setup at home, though, if that helps.

  3. Nathan Arthur says:

    Hm, I just realized that my primary out-link is broken. I haven’t actually had to re-install this configuration for a year or two, so I haven’t tested these instructions recently. It’s possible that has a copy of the linked site, maybe that would do the trick.

Add a comment

(will not be displayed)

(not required)