Getting a Windows Printer (Ricoh Aficio SP 204) natively running on Linux

Printing and scanning has always been the bane of Linux.  I thought I solved it three years ago by getting a nice network printer (HP OfficeJet Pro 8600) which spoke postscript and could scan to folder (provided you have samba installed).  Unfortunately, this is an inkjet printer and about three months ago the initial cartridges (which are deliberately lightly loaded) ran out of ink.  Purchasing new ones (it’s colour so I need four) turned out to be an arm and a leg (or 2x what the printer cost to buy in the first place).  Three months after replacement, the whole thing died with a call HP technicians error.  This turns out mostly to mean my ink cartridges are leaking.  Sure enough the entire inside is awash with a substance more costly than liquid gold … plus it’s now all over my shirt and trousers.  Trying to clean it out just gets ink all over the desk and some important papers.  Of course, since it’s a UK purchased printer and I’m now living in the US, HP support “cannot help”.  Vowing never to purchase another @!**#@ inkjet printer as long as I live, it’s time to find a cheap multi-function laser (did I mention the scanner function on the HP won’t work either now because when it gets this error it locks every function).

Investigating lasers, the cheapest multi-function seems to be a Ricoh Aficio SP204 N (the N means netowrk connected, which is nice) for US$60, which is a bargain, plus it’s a laser.  Google confirms it can scan to pdf (via file share or email), the only drawback is that the printer engine is “windows only” (one of those direct render on the system and send to printer ones).  Further googling around for the printer and linux drivers (and even DDST, the Ricoh name for their direct rendering protocol on linux) yields nothing.  Looks like I’ll be writing a driver when it arrives.  Fortunately, there is a way of running it (using KVM instead of VirtualBox) providing you have a windows virtual machine, so that’s the initial plan.  The only other annoyance is it doesn’t do duplex (either for scanning or printing).  Bummer, but you can’t have everything for US$60.

When the printer arrives, it turns out it has a web interface (yay) but you can’t program scan destinations with it (and without scan destinations, it won’t scan) … bummer.  Install the windows virtual machine with the Ricoh driver and use the tool to program scan to email; amazingly enough it all works correctly (it even scans in colour).  Followed the redirection directions with ghostview, ghostscript and redmon and successfully attach the printer to Linux.

Now to get the thing working under linux.  First step is to use tcpdump to track the communication between the windows machine and the printer:

tcpdump -n -w /tmp/trace.ricoh -i eth0 <printer ip>

And then print something.  Looking at the trace file in wireshark, the windows driver uses the HP Jetdirect port (9100).  In wireshark, select the first packet to this port and right click on “follow TCP stream”.  That gives the whole file the windows system sent.  Now save it to a file (tmp.winprint) and see if that’s enough the get the printer going.  You do this by sending the saved file to the printer with netcat:

nc <printer ip> 9100 < tmp.winprint

Wonder of wonders, it prints the same page again, so now we have the correct format to send.  A quick view with emacs reveals a HP PJL (Print Job Language) encoded header and footer with binary data in between.  This is the header:

^[%-12345X@PJL 
@PJL SET TIMESTAMP=2014/07/22 18:31:06 
@PJL SET FILENAME=gsprint 
@PJL SET COMPRESS=JBIG 
@PJL SET USERNAME=SYSTEM 
@PJL SET COVER=OFF 
@PJL SET HOLD=OFF 
@PJL SET PAGESTATUS=START 
@PJL SET COPIES=1 
@PJL SET MEDIASOURCE=TRAY1 
@PJL SET MEDIATYPE=PLAINRECYCLE 
@PJL SET PAPER=A4 
@PJL SET PAPERWIDTH=4961 
@PJL SET PAPERLENGTH=7016 
@PJL SET RESOLUTION=600 
@PJL SET IMAGELEN=61304

And this is the footer:

@PJL SET DOTCOUNT=995745 
@PJL SET PAGESTATUS=END 
@PJL EOJ 
^[%-12345X

So it all seems relatively straightforwards: each page is rendered as a pixel map in the jbig compressed image format (it’s lossless, like gif) and the header describes exactly the size and dimensions of the image.  So getting it working seems to be very straightforward: just generate the jbig images and slap on the header and footer.  Ghostscript doesn’t render natively to jbig, but it will render to ppm and the jbigkit renders what I need.  The image dimensions can be obtained from the ppm with the ImageMagick identify command.  The only fly in the ointment is the DOTCOUNT.  This shows per page how many black pixels are printed and must be something to do with the way the printer tracks the cartridge use; however, it can be faked for the moment.

The jbig format is also used in faxes, so I asked google if anyone else had a piece of code that does the split.  Since it would have the “@PJL SET COMPRESS=JBIG” line, I did a code search for that;  what do you know, it turns up a linux driver for the Ricoh Aficio SP 100:

https://github.com/madlynx/ricoh-sp100

To add insult to injury, the READMEs mention terms I’ve been searching for for ages (like Ricoh and DDST) and the driver filter even has them in the file name … honestly, for being allegedly the primary search engine of the internet, you’d sometimes wonder if google could find its own arse with both hands.

So, download this and install it and, yay, it works.  Looks like the only real difference between the SP 100 and the SP 204 is that the latter has a higher resolution mode (1200×600) and also can be adjusted to use a bypass tray (which is set in the header too).

I’ve done an initial package here and will be updating for the SP 204 additional features.

17 thoughts on “Getting a Windows Printer (Ricoh Aficio SP 204) natively running on Linux

  1. Netsplitz

    Thanks for this. Bought the same printer without the necessary research, and was just about to embark on the same journey you went through. Saved me hours of work!

    Reply
  2. Dmitrijs

    Very many thanks for Your work. I got same printer to work on Debian and Kali Linux without any problems.

    Reply
  3. Steve

    I just searched for “pjl dotcount” while attempting to reverse engineer this printer myself. I landed here, after searching for many other things related to this printer. Then I read your post and how you’d followed exactly the same steps I had. Then I installed the driver and worked fine.

    Well that’s a weekend gone, for a problem that could have been solved in an hour with more luck.

    Reply
    1. jejb Post author

      Actually, be careful, I just ran into a problem with the dotcount in that the printer will shut down the cartridge and not allow you to use it after it thinks you’ve printed enough dots. My cartridge isn’t empty (I can hear the toner when I shake it), so I implemented a fix to reduce the dotcount by a factor of ten to lengthen the life of the cartridges. The patch is here.

      Reply
      1. arved

        Hi jejb.

        Thank you very much for you efforts and the documentation. I installed the Ricoh SP 204SFN on a Raspberry 2 with the drivers provided by madlynx. Printing is working fine. The RaspberryPi is sharing the printer in my local network and I can even print using my Mac.

        You provided various patches. I’m sort of an advanced Linux user, meaning I taught myself a lot using tutorials. But I don’t know what to do with your patches. How do I execute them? I’m guessing the patch files are changing some code lines in the pstoricohddst-gdi file?

        Greetings

        Reply
  4. Gareth Dunley

    The printer prints fine in Ubuntu thanks to all the above. However, any ideas on getting it to scan as well – and help gratefully received!

    Reply
    1. jejb Post author

      I use it as a scan to pdf in email tool talking to my main email server. Unfortunately, the configuration utility is windows only for this to set up the email address (you can’t do it from the printer console), but since it’s network connected, any old windows device or VM will do.

      Reply
  5. Deedend

    I can’t make the printer working… I am on Ubuntu (but I can try it under Arch and Debian too) and I have “alienized” the Suse Package and installed it, all works fine except the printer when I send a job to it turn on but hang; if after this I try to print under windows the printer is still hanging and I have to manually cancel the ubuntu’s job (that make the printer stop working for somehow reason) and then I can print.

    Any suggestion? BTW thanks a lot for your precious driver, this is a very good printer except the fact that is not linux compatible (at least officially)

    Reply
  6. Mike Poppyfields

    Well done for working this out. I made a mistake of buyin the SP C240DN, as Ricoh suggest it is linux compatible. How wrong I was. I have searched everywhere and cannot find a solution. I tried your drivers but they do not print anything. As an expert, do you have any suggestions?

    Reply
  7. John Radley

    Quite incredible, it has worked for Ubuntu 16.04 as a guest in VirtualBox 5.1.0, with Windows 10 as Host, using an Samba share of the Ricoh SP 204 SFN connected by USB.
    Thank you very much.
    Must admit I nearly gave up – having to download the RPM and open as as an Archive, and then find the Ubuntu equivalents – namely, jbigkit-bin and inotify-tools.
    But after some reboots of Ubuntu and some odd clicks from the printer, the Test pages have imerged!

    ref:
    http://manpages.ubuntu.com/manpages/xenial/man1/pbmtojbg.1.html

    Here in UK, the RICOH was £29 on special offer last year (2015)! Couldn’t resist it. But an odd printer it is! Installing the WIndows drivers was a pain!

    Thanks again,
    John

    Reply
  8. Chris

    Hi – I’ve just tried this for my Ricoh SP201N on Debian 9 with CUPS installed.
    When I perform a test print from the CUPS web interface the job goes through but nothing is printed. I’ve tried both the 200 and 204 PPD’s without luck.

    No errors are reported in the CUPS error log..

    Any ideas?

    Many thanks

    Reply
    1. jejb Post author

      I’ve got to confess I wrote this package solely to get the printer working for me under CUPS on openSUSE, so I haven’t tested any other distributions.

      That said, I’ve noticed that even under openSUSE, if I cat a ps file to the printer it comes out blank, it only understands pdf files. I think this is because I’ve got the input format recognition wrong somewhere. This would mean that any distro that makes ps its native format would churn out blank pages, which may be your problem.

      I’ll look into this because my wife recently noticed she can’t print directly from libreoffice: she has to render to pdf then print the pdf.

      Reply
  9. Chris

    Many thanks for the reply. I don’t even get a blank page in my case. I’ve managed to do direct printing by using the ddst driver in this website http://foo2ddst.rkkda.com.

    If I do nc ‘ipofprinter’ 9100 I’m able to print their test .prn page. However, using the same driver in CUPS just results in the data being sent but never printing. Weird, as I’m specifying socket://ipofprinter:9100 as my CUPS queue.

    I’ve posted on their forums under the Ricoh subforum. Hopefully I can figure out why CUPS won’t play ball.

    Reply
  10. Inky

    Greetings, everyone.

    First of all, hats off! The Ricoh SP204 in my life is the bane of my existence, and just reading cogent, civilized conversation regarding its function cut my heart attack risk in half. I’m running OS X Mojave on a 2012 mini. Seeing “I can even print using my Mac” was very encouraging, although yes, I understand there’s a print server betwixt them.

    But, while not a proper techie I can tech quite a bit, and I tried to network print to Bane. Not working… but I am hoping someone will be kind enough to point out I am simply sticking the wrong end of the fork into the outlet. Here’s what I did:

    1) Went on GitHub, downloaded the .ppd, which turned into a .ppd.txt but I just renamed it back.
    2) Copied this file to /Library/Printers/PPDs/Contents/Resources/ (afaik where PPDs belong on a Mac)
    3) Tried to add the printer via both HP Jetdirect/Socket and LPD Line Printer Demon, specifying the above driver as Use > Select Software > picking it from the driver list (populates here with no problem).
    4) Got a nice error message “The software for the printer was installed incorrectly. Please reinstall the software from the manufacturer”. Which I have no clue what to make of.

    I am plenty aware of the linux factor, but the internet works by letting people agglutinate their thinking, so I’m just gonna put this here. And also on the Apple discussion boards. Any suggestions?

    Also, if it’s any worth to anyone, Bane doesn’t like to scan in Win10 with the native Scan app and I don’t recall finding a TWAIN driver from the manufacturer – but NAPS2 fixes all that.

    Best,

    Inky

    Reply

Leave a Reply to Joe Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.