Printing from Windows in Virtualbox via CUPS on a Linux host

For the one other person in the world that needs this
Notes virtualbox windows

What?

I recently got into the position where I needed to get something printed from a Windows XP application which ran in Virtualbox.

My host OS was Ubuntu Linux, and while you could attempt to use USB passthrough for the printer, often there are not any drivers for Windows XP.

In my scenario I had no printer available at the time either, which is why I wanted a PDF instead.

How?

CUPS is the answer. The following are some notes on how I got my PDF even though the Windows application thought it was printing on a regular printer

CUPS

First step is to configure CUPS to allow remote connections

$ cupsctl --remote-any

CUPS-PDF

Then to create the PDFs I used CUPS-PDF. This is not required if you want to use CUPS to print on a actual printer. To install CUPS-PDF:

sudo apt install cups-pdf
sudo systemctl restart cups

This will give you a printer named “PDF” on your system. By default, everything you print will end up as .pdf’s under /var/spool/cups-pdf/ANONYMOUS. To enable printer sharing, open up a web-browser on your system and navigate to http://localhost:631. If prompted for credentials, enter the username and password you use for logging into the computer.

Virtualbox networking

Then to allow connections between the Virtualbox VM and the host OS I configured Virtualbox host-only networking.

In my setup I had to temporarily deactivate the systemd firewall to get the connection to work. I could of course only open up the relevant ports, but as I were on a trusted and safe network I opted to simply temporarily disable it until I was done printing instead.

sudo systemctl stop firewalld

To ensure that the networking is working as it should, you can use Python’s simpleHTTPserver to test.

$ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

When browsering to http://192.168.56.1:8000 you should see a directory listing from the folder where you ran the command above. If so, then you have configured the networking correctly!

If you do not see the listing, ensure the settings in VirtualBox, and that there are no firewall rules which blocks the connection.

Windows XP

PostScript driver

On the Windows XP side of things we first need to install a printer driver which matches our setup. For this any PostScript compatible driver should work. The first Google search for me resulted in Epsons Universal driver for WP-4590, which worked perfectly fine with CUPS for me.

Download the following driver, and install it in your Windows XP VM.

Configure printer

Then to configure Windows to use CUPS I went through the normal “Add Printer Wizard”.

Testing 🖨️

Then to test your setup, simply find your PDF printer in Windows XP’s “Printers and faxes”, right click for Properties and press “Print Test Page”. You should then end up with a file under /var/spool/cups-pdf/ANONYMOUS! (Note, you might need to change the permissions of the file to access it.)

Done!

And thats it! Hopefully this page found it’s way and was of help to the one other person that needed this. If you’re out there, and you are still stuck even after reading this, then feel free to contact me at andreas@whynot.guide 🖨️. Buy Me a Coffee at ko-fi.com