Hacker News

4 years ago by jcrawfordor

While the article is correct, it omits most of the actual function of CUPS. Many printers are capable of accepting various types of documents directly over the network, with postscript, HP PCL, and PDF being commonly supported---and ASCII pretty much universally supported.

The problem is that few printers support _all_ of these standards. Postscript, for example, is surprisingly complex to implement in practice, which leads to a lot of inexpensive network printers actually lacking postscript support. Further, printers are very slow at rasterizing, and so while support for PDF rasterization is very common you probably don't want to use it. You can easily see a minute per page for printing modest PDFs. In-printer PDF rasterization is also of very uneven quality, and I have seen issues like completely broken kerning in documents due to the printer's poor handling of embedded fonts.

One of the key functions of something like CUPS is to address this problem: CUPS standardizes the format of all printed documents to something that is well-supported by the printer, and performs much of the rasterization ahead of time on the much faster print server. This saves time and improves reliability since you don't need to figure out if a given document is supported by the printer. For most printers these days some variant of PCL is the preferred language for jobs, as it's simpler and easier to implement than Postscript. It also presents fewer security concerns.

Of course the other major problem CUPS solves is the management of the queue, including across multiple users. That's an important feature but not one that matters in a lot of home situations. That said, if you don't use a printing system you can and will run into annoying situations where you cannot print a document because you are waiting for the previous one to complete sending, which often gets blocked on the printer's memory space or rasterization.

4 years ago by captainmuon

> Further, printers are very slow at rasterizing, and so while support for PDF rasterization is very common you probably don't want to use it.

That's interesting. Back in the day (of HP LaserJet 4L and similar), I learned that rasterizing on the PC and sending to the printer was very slow because printers had slow connections and little memory. The resolution was also limited and it looked blocky. The rule was to never print "as bitmap" if you could avoid it. OTOH printing "flat" postscript was very fast and yielded much better quality. I think the printers allowed loadable fonts and often had some of the standards (Times, Arial) pre-loaded.

4 years ago by jcrawfordor

The big issue is that, back when, printed documents were much simpler. Printers offer a set of embedded fonts that makes it very quick and easy to print simple text documents, if you are okay with one of the printer's embedded fonts. You just need to send a couple commands to set up the font parameters and then the text. PCL and moreso Postscript also give you some vector drawing capability that makes printing line art in vector format very efficient.

But the nature of printing has changed! People now want to print things in all kinds of arbitrary fonts, which requires either rasterizing to print resolution (which is a lot, 300-600dpi) or sending the printer all the outlines as vector instructions. Postscript and PCL take different approaches to this and sometimes different print stacks do as well. And then add graphics, and 99% of documents you encounter these days provide all graphics in raster format in the first place. The result is that something, either the host or the printer, needs to take a raster graphic (which can even just be little icons) and interpolate them to whatever dot pitch the printer is using. That tends to be the real killer... that interpolation can take a printer a very long time. Usually there's some way in the PCL (exposed via the printer driver) that you can tell the printer to interpolate to a lower DPI which will speed things up, but make your images look worse.

Unfortunately sending 600dpi graphics over the network can still be kind of slow and does contribute to the "Receiving Data..." and time to first page even with modern printers and drivers. Most laser printers have a pretty poor TTFP anyway, though, so it's not too big of a deal.

4 years ago by tonyedgecombe

I suppose if you have a printer that doesn't support PostScript or PDF then you could pipe the output through GhostScript. This is what CUPS is relying on anyway.

4 years ago by simonh

Right, there's no magic pixie dust in CUPS that you can't manually reproduce using a concoction of software packages, command line incantations and maybe some scripts. But then you're just re-implementing CUPS, manually.

4 years ago by qwerty456127

Is there any guide on how to make a Linux-based print server which would be autodetectable by all the major OSes? I feel like we need a dedicated print server for our office (where there are many computers running Ubuntu, Windows and MacOS) because the printer doesn't work reliably enough. I have never actually seen such a scenario in the wild - people seem to always connect to network printers directly (they also used LPT and USB printers shared via the standard means of Windows in the past).

4 years ago by phaemon

You just want to make sure you have IPP and Bonjour enabled and it should Just Work. A quick google finds https://www.dailycupoftech.com/how-to-set-up-a-print-server-... which looks about right

4 years ago by the_arun

What about Page Layout / Color/Mono selection etc.,?

4 years ago by gpvos

Postscript has commands for that, you can preprocess the file appropriately.

4 years ago by xorcist

It's very much non standardized. The standard is PPD, so you'd want a parser for that at the very least, perhaps a user interface too, and before long you want something similar to CUPS.

4 years ago by jim-jim-jim

Hah. I had a similar moment of enlightenment with FreeBSD when somebody explained that you can just cat a wav file into /dev/audio (or /dev/dsp? forget the exact name). And that you can produce white noise by catting /dev/random to the same destination. With no barrier to the sound card like that, I was free to experiment with programming dfferent noise algorithms and figuring out how digital audio works. I eventually did things the proper way with OSS and finally sndio on OpenBSD, but direct, universal interfaces like files invite that initial exploration and help you get things done quick and easy.

netcat is also a secret weapon around the house. My girlfriend runs macOS, but it's way more reliable to just nc files to each other over wifi than deal with all the cloud and airdropping bullshit.

4 years ago by krrrh

When I was first learning Linux many years ago a friend and I got intoxicated and catted /dev/hda into /dev/dsp. It was all basically static with sometimes very structured patterns that we would try to guess as to what filetype was producing them. He had download and forgotten about a long uncompressed audio recording of a piano performance on his drive that suddenly started breaking through the static in chunks of varying length. We came to the conclusion that this was probably just what the kernel source sounded like.

4 years ago by FeepingCreature

mplayer -demuxer rawaudio -rawaudio rate=48000 -format s16le -af volume=-20 /dev/sda

Warning, headphone users: may hurt your ears. Trust me on the volume lowering.

With 16 bit samples and (default) two channels, you can recognizeably hear small integer values in your left ear. :)

4 years ago by lgeorget

I remember when I discovered that while in engineering school. I would try to pipe all kinds of files to see which ones had interesting acoustic signatures. I remember .iso files to be particularly interesting.

4 years ago by qiqitori

for i in $(seq 1 10); do seq -120 1 120; seq 120 1 -120; done | aplay

It's for you.

4 years ago by gerdesj

Good skills.

It has never occurred to me to do that but it is actually quite an obvious thing to do when you "know" that everything is a file.

Any idea what the visual equivalent would be?

4 years ago by toast0

If you've got a framebuffer console, I think you can cat to /dev/fb ... Although pixels are less friendly than audio, it's kind of helpful for identifying patterns if you preprocess so everything is shades of one color, or a byte -> color map anyway.

4 years ago by anthk

Plan9's /dev/draw.

4 years ago by reshie

ffmpeg can point directly to the webcam under /dev/.

4 years ago by axiolite

> Any idea what the visual equivalent would be?

Perhaps:

head -c800 /dev/urandom > /dev/tty

Or:

mplayer -demuxer rawvideo -rawvideo w=80:h=60 /dev/urandom

4 years ago by cogman10

The secret of *nix that people don't like accepting is the file approach is often the right approach.

Consider lowly embedded linux. You COULD dig down deep into the documentation of which register, which interrupt, which special memory address needs to be written to interact with the right ports on a embedded linux board. All while adding a bunch of safeguards and checks to make sure "Only you are doing this".

Or, as if often the case, you can simply find the right /dev/xxxx device and read from it or write to it.

9 times out of 10, you'd not suffer any negative consequences from using the /dev/xxx system as intended and you get the bonus ability of being able to interact with the outside world using programming languages other than C.

4 years ago by PaulDavisThe1st

The file approach ignores anything that exists (at least in part) in the time domain.

Audio files are (for me) the canonical example. A text file has no inherent bit-rate. An audio file being handled without knowledge of (even just) its sample rate has its semantics distorted or destroyed.

There's an awful lot of things you can do with the file approach, and I love it. Cross into the time domain and try to retain the same approach, and I say you're making a serious mistake.

What's worse is when the actual programming APIs (as opposed to just redirecting stdout to /dev/dsp) also fail to model the time aspect, and encourage programmers to think that you can just shovel data at a device without any consequences for your software's properties (like latency).

4 years ago by dredmorbius

Many character devices do in fact have a bitrate.

4 years ago by Denvercoder9

I don't think this has anything to do with the file approach per se, just with using an interface at a higher abstraction level.

4 years ago by phamilton

My favorite version of this is reading from /dev/dsp will capture audio from the mic. I would cat this audio to /dev/dsp on another host over ssh in the school lab.

4 years ago by kelnos

You used to be able to do that on Linux when its sound system was OSS ("Open Sound System", not "Open Source Software"), the same as FreeBSD uses today (I believe Linux still has an OSS compat layer). A long time ago the project lead was employed by a company to write support for some newer sound hardware, and decided to make those changes proprietary. The Linux folks decided to do something completely different, and we got ALSA, while some BSD folks decided to fork the last fully open source version of OSS and continue developing it.

The irony, of course, is that the proprietary version of OSS failed, and it ended up going open source again.

4 years ago by account42

The difference is that on Linux, only one process can open /dev/dsp, which is why you need shims like aoss or padsp to run older games or other audio-programs without stopping all other sound sources / your sound server.

IMO, /dev/dsp was the right approach and should have been extended instead of being replaced with entirely different interfaces.

4 years ago by anthk

ALSA has compat modules for OSS.

4 years ago by corbet

FWIW, the Internet Printing Protocol (and IPP Everywhere in particular) make printer setup in CUPS far, far easier, but distributors seem reluctant to encourage it. I wrote about my experiences with IPP back in June (https://lwn.net/Articles/857502/). I expect to never have to hassle with printer drivers again...

4 years ago by gerdesj

I own a HP MFP and for several years HPLIP generally worked for several to many months at a time, until it didn't. Me and the wiff both run Arch on our laptops (she doesn't know or care).

After a particularly rubbish time trying to get HPLIP working again after a pacman -Syu I did a literature search: Mr CUPS had deprecated everything apart from IPP Everywhere. So, I tried it out.

Me and the missus send docs to print and they get printed. I cannot remember the last failure (apart from running out of paper.) I also have toner levels monitored via Home Assistant.

I also have an office with several MFPs and inkjets, accessed via Windows (Server 2019) print queues. They are not so reliable. I often have to restart the Print Spooler service on our print server. To be fair, it is generally one queue that is at fault.

4 years ago by tonyedgecombe

>To be fair, it is generally one queue that is at fault.

Printer drivers run in process as well as the port monitor (for older printers). You might find the situation improves if you use an inbox driver (one that comes with Windows) and/or the standard port monitor.

4 years ago by abhgh

I read your article and finally got my Brother printer working on elementary OS! Thank you!

4 years ago by askvictor

I thought that the whole point of CUPS was to provide an IPP service.

4 years ago by AceJohnny2

CUPS provides an IPP service over those printers that aren't natively IPP.

Now printers integrate the IPP functionality.

4 years ago by merb

keep in mind not every printer has a good http stack, especially if the device never gets restarted this can be a problem.

4 years ago by gerdesj

Probably true but why not turn it off and on again daily. While you are at it, you can restart your print queues regularly via a cronjob or Taskman.

There is no need to suffer if that will do the job.

Pragmatism is not the enemy of perfection.

4 years ago by MonaroVXR

Didn't know about that, you got some examples?

4 years ago by nonameiguess

The point of CUPS and of server middleware in general like PulseAudio and what not is when multiple clients all want to send output streams to the same sink. Just sending the stream directly to a device with no middleman works fine provided 1) the stream is encoded in a way the device understands, and 2) no one else is trying to use it at the same time. For a shared network resource like a printer, unless you live alone and are the only user on your LAN, betting no one else is sending a job to the printer at the same time might be a rough bet.

Even when it works, there might be downsides, as some other comments are alluding to. The long print time one mentioned is likely because while you're lucky that your printer understands how to transcode pdf to ps in order to print a pdf, the onboard processor on the printer is much weaker than whatever you have on your computer. Also beware that if you're doing this on a radio network, I don't think netcat can encrypt the traffic. So don't be printing your credit card statements this way.

4 years ago by ChuckMcM

Hence the existence of lp(1), which at its simplest is just a queue that sends things to the network as they arrive.

4 years ago by AceJohnny2

Huh. So can one leverage/hack lp to serve as a generic service spooler? Has anyone done so (in a mildly documented way)?

4 years ago by mprovost

Yes, at OpenBSD hackathons they used lpd as a queue for mp3s so all the devs could submit music to be played for the room.

https://patrick.wagstrom.net/weblog/2003/05/23/lpdforfunandm...

4 years ago by tonyedgecombe

>2) no one else is trying to use it at the same time.

Printers are fine with accepting jobs from multiple clients and have been for a long time. After all this is pretty much standard practice for any small office without a server.

4 years ago by usr1106

> Also beware that if you're doing this on a radio network, I don't think netcat can encrypt the traffic. So don't be printing your credit card statements this way.

Of course netcat does not encrypt anything. But if your printer accepts encrypted traffic you can send that over netcat. The question is what encryptions do the printers support? What protocol (stack) CUPS uses in the end? I have never heard that a printer certificate has expired, so my first guess would be it's all in cleartext.

4 years ago by undefined

[deleted]

4 years ago by axiolite

Terrible idea on several levels.

Avoid jetdirect (9100) port like the plague. Partial files? Errors parsing the postscript? Outputting to the jetdirect port will result in printing every bit of that trash out, no questions asked. Walked up to a printer and found Nearly blank pages with one PCL or Postscript line telling you there's an error? That's jetdirect printing for you, and there's no good reason for it. LPD and IPP have actual protocols signaling start and end of jobs, so nothing comes out if something in the process fails, saving paper, toner and frustration. Yeah, you can't just use netcat, but you can easily use lp: lp -h 192.168.0.30 file.ps

Printing raw to a printer without drivers is also a terrible idea, it happens to work some of the time, but leaves you at the mercy of printer defaults. Printing a US Letter page on a printer which defaults to A4 (or vise versa)? Say goodbye to part of your print job. Now, yeah, you could program the correct command sequences into your postscript document, but why would you want to? Plenty of other things used in documents will cause errors if sent to a printer without being sanitized by CUPS (or filters to lpng, or whatnot).

CUPS isn't great. It makes printing so much harder than it needs to be. I absolutely hate having to remember the exact syntax to select B&W on my color printer: lp -o ColorMode=Monochrome It's very difficult to track down how it's mangling your print jobs, when there's a problem and you need to do so. Having to do an old apache style allow,deny reverse polish notation logic to configure who you want to access the printer and admin interface is user-hostile to be sure. And more. But it certainly has made it much easier to go from nothing to up and printing quickly, it's certainly got every feature you could need, and it's certainly reliable. I've done it in the old days, and I certainly don't want to go back to configuring printcaps manually with inscrutable invocation of ghostscript and many other print filters.

4 years ago by TacticalCoder

I used to do this at home all the time (from Linux though): networked printer with its own IP address and then good old netcat. I'd do it with PostScript files and send them to HP LaserJet 4M+: not only do these beauties speak PostScript natively, they can also be made to display the infamous "PC LOAD LETTER" message.

I'd try to find these printers used then I'd upgrade them: more RAM, more fonts, adding a network card inside the printer etc.

I still have several of these printers in a garage, some of them have printed more than 300 000 pages. They probably still work: some things were that good back then.

And, yup, there's something feeling magical when netcat'ing a .ps file (or another format) directly to the printer.

4 years ago by jtvjan

I recently tried that with my Epson Ecotank, but instead of rendering the document, it just printed out the literal source code. It then held the paper halfway through the machine until I sent enough newlines.

I was only half disappointed.

4 years ago by tonyedgecombe

>It then held the paper halfway through the machine until I sent enough newlines.

That is what a form feed character is for (ASCII 0x0C).

4 years ago by na85

How did you add network cards? Do some printers have PCI expansion slots?

4 years ago by kindall

Proprietary, not PCI, but expansion slots, yes. On HPs it was called the MIO slot and later the EIO slot. If your printer came with a MIO card that only did serial and parallel, you could swap it for one that added networking.

4 years ago by jeffreygoesto

And if it stops working, try re-soldering it in an oven before throwing away. Some infamous batches had bad soldering problems that can be fixed. See i.e. [0]

[0] https://community.spiceworks.com/how_to/2077-how-to-bake-an-...

4 years ago by dredmorbius

If you have a single host, and a single printer, or your printer itself is both network-enabled and can manage its own print spool, direct TCP/IP printing may indeed work for you.

The value of CUPS is that it enables the CUPS-serving computer to run as a print server. This means not only print drivers (document format support --- typically plain text, Postscript, and one or more PDL (printer definition languages) & PCL (Printer Control Language), but status on the printer, queue management, job control, and access control. Note that if your printer is generally available on your local WiFi network, you might want to give more thought to that last element.

If those are overkill for you and your printer Just Works with generated output, then yes, you can get by without the complexity.

Note that you can also often telnet directly to the printer port.

Be aware of what you're trading off, though, and whether or not you actually need what CUPS, or direct network access, offers.

4 years ago by cbhl

The CUPS web front-end also has rough edges; Apple maintains CUPS these days and OS X now ships with the web interface on :631 disabled.

If you still need a print server, it can be well worth the extra $100 or so to buy a business-class printer with an IPP server in it, so that CUPS runs on a chip inside the printer instead of on a separate computer. (Generally anything that supports "Airprint" will do this, and also at the mid range you avoid the "printers whose ink cartridges are more expensive than the printer" zone.)

4 years ago by BearOso

> Apple maintains CUPS these days

Apple never really maintained CUPS. They hired the author, Michael Sweet, and he pretty much served as the printing team. He left Apple a couple years ago, and basically stalled their printing department.

He’s recently become head of the Printer Working Group, and they’re all pushing IPP Everywhere towards greater adoption. It’s a laudable effort.

4 years ago by jwatt

After he left, all his cups commits to Apple's public CUPS repo stopped[1] and his work continued in the OpenPrinting fork of CUPS[2]. Interestingly though, it seems he resumed committing to the Apple repo in March. I'm glad CUPS on macOS isn't going to be left behind, but I'm curious what happened there.

1. https://github.com/apple/cups/graphs/contributors 2. https://github.com/OpenPrinting/cups/graphs/contributors

4 years ago by GeekyBear

Apple moved to IPP (branded as AirPrint) a decade ago.

Google shut down Google Cloud Print in 2020 and moved to IPP.

Microsoft announced that they were moving to IPP (branded as Universal Print) in 2020 as well.

CUPS still exists because legacy printers don't have built in IPP support.

4 years ago by mackman

My first introduction to the internet was downloading Magic the Gathering card lists as postscript files via FTP and then FTPing them to a postscript printer. Would have been 1994 and they were some sort of Sun machine at LMU. Internet has been all downhill since then.

4 years ago by mbreese

A few years later (2002-ish), I setup a Zebra barcode/label printer that had a similar mechanism. I’d write the code for the label in the printers language (ZPL?) and then FTP a file to the printer.

I was in grad school in a wetlab, so I had to label a ton of microcentrifuge tubes. Having a quick web interface e to generate the ZPL files that would be FTP’d to the printer let me avoid writing all of that out by hand.

It was such a simple system. And the FTP server was basically a queue, so you could print a bunch of labels at a time.

4 years ago by voidmain0001

...all downhill since then. Well said greybeard, well said. https://dilbert.com/strip/1995-06-24

Daily digest email

Get a daily email with the the top stories from Hacker News. No spam, unsubscribe at any time.