Tag Archive : cups

/ cups

Using CUPS

December 9, 2015 | Article | No Comments

On previous article, we have discussed about how to install CUPS on FreeBSD. In this article we will discuss and use the server for printing example documents.


Test the server by pointing a web browser to http://host.example.com:631 (substituting your server’s hostname or IP address for host.example.com). You will then see a Common Unix Printing System Welcome! page if the server started successfully; if you don’t, check your /usr/local/etc/cups/cupsd.conf file for typographical errors.

If you are using a PostScript printer, have its PPD (PostScript Printer Description) file handy . If you don’t have your printer’s PPD file, check http://openprinting.org.

Gutenprint Driver

The Gutenprint driver contains extensive support for Epson printers (among others). Visit http://gutenprint.sourceforge.net for a complete list of supported printers. The following commands will install the Gutenprint driver from the ports collection (this may take 30 minutes or more to complete):

cd /usr/ports/print/gutenprint
make install clean

A menu will appear containing options for Gutenprint; choose Gutenprint Cups Drivers. You may install the HPLIP driver as well, if you wish.

HPLIP Driver

The HP Linux Imaging and Printing driver was developed at Hewlett-Packard, and it contains support for virtually all HP printers. Visit http://hplip.sourceforge.net for a complete list of supported printers. The following commands will install the HPLIP printer driver from the ports collection (this may take 60 minutes or more to complete):

cd /usr/ports/print/hplip
make config; make install clean

A menu will appear containing options for HPLIP. Here we use defaults installation, thus we don’t need to change anything.

Finishing Printer Setup

Ensure that your printer is powered on and connected to the CUPS server via a USB or parallel cable. Reboot the system. Log in as root to the web administration interface https://host.example.com:631/admin (or substitute it with your servers hostname or IP address).

Select Add Printer. Choose a name for the connected printer. This name will act as identifier among printers we have. Also enter a description of the printer (e.g., HP LaserJet 1100) and then click Continue. There should be a pull-down menu on the next page. Select either USB or LPT (parallel) as appropriate and then click Continue. Select the correct brand (vendors) of your printer on the next page, then click Continue. Choose the correct model from the list presented on the next page, then click Continue. Your printer should be ready to accept print jobs. You can print a test page from the Printers page of the CUPS web interface. Proceed to the appropriate section to set up client printing.

Various Testing

Printing from Windows XP

To print to a CUPS printer from Windows XP:

  1. click the Start menu and select Control Panel.
  2. Double-click the Printers and Faxes icon.
  3. Click Add a Printer at the left side of the window. The Welcome to the Add Printer Wizard dialog will appear; click Next.
  4. Click the Network Printer radio button, then click Next.
  5. Click the Connect to a Printer on the Internet or on a Home or Office Network radio button. In the URL field, use the following syntax to specify the server address: http://host.example.com:631/printers/printername (substitute the hostname or IP address of your CUPS server for host.example.com and replace printername with the name you assigned the printer during the CUPS printer setup).
  6. After clicking Next, you will be required to select the printer series and model from a list. If you have a Windows driver from the manufacturer, use it; otherwise select it from the given list and click OK.

You should be able to print via the CUPS print server from Windows applications.

Printing from Mac OS X

Open an application capable of printing (e.g., Safari). In the File menu, select Print. Select the Printer pull-down menu to display a list of available printers. You should see Shared Printers in the lower half of the menu. Hover the mouse over Shared Printers to display the submenu. Select the appropriate CUPS printer from the list. The CUPS printer will be added to your permanent list of printers. You can print the current document by clicking Print on the lower-right side of the dialog box.

Printing from the FreeBSD Command Line

Printing from command line is one of fun thing to do. The contents of file can be printed by CUPS. To print it, use following command:

lp -d printername filename

Send Command from Command Line

Print a Document

As a user, we can use printer on network using CUPS. To print using the default print, use:

lpr filename

Print to specific printer:

lpr -P printer filename

Print multiple copies, for example 4 copies:

lpr -P filename -#4 filename

CUPS status information

Query CUPS status by:

lpr <options>

The options can be:

  • -t: show all CUPS info
  • -d: show default printer
  • -p: show all printer
  • -a: show all printers that accept jobs
  • -o: show active print jobs

Cancel a Print Job

Cancelling a job can be done by the same user who submit the job.

lprm <job-id>

Setting Options for a Specific Print Job

Sometimes, user needs specific print options. A general way to define specific options for a print job is:

lpr -P printer -o option1=value -o option2=value filename

Modify the Default Print Options

A user can define his own options for all his print jobs for a specific printer. They are saved in the ~/.lpoptions file and override the default options that have been defined by the system administrator for this specific CUPS printer.

Create Sets of Options

A user can set his own default options for a specific CUPS printer by issuing following command:

lpoptions -P printer -o option1=value -o option2=value filename

Remove Print Options

Previously defined print options can be removed from ~/.lpoptions by:

lpoptions -P printer -r option1 -r option2

List a Printer’s Options

To list print queue’s current options:

lpoptions -P printer

To list print queue’s current options:

lpoptions -P printer -1

Create Sets of Options

A very useful CUPS feature is that sets of options can be defined. These can be system-wide if they are set by root, or user specific if they are set by a user. Printer instances are extra options for a specific printer that are saved as an extra printer in the form printer/set. This virtual printer’s settings override the default options. To create a printer instance, as a user issue the command:

lpoptions -p printer/set1 -o option1=value -o option2=value

To delete a printer instance issue the command:

lpoptions -x printer/set1

The printer instance is listed as a printer in lpstat. The user can send a document to the printer instance:

lpr -P printer/set1 filename

Options Available

The common print options can be seen here. If an option accepts a value, then it is listed in the form option=value:

  • landscape – for landscape printing
  • media=A4 – check your ppd file for possible media values
  • Collate=true | false – useful when printing multiple copies
  • sides=two-sided-short-edge – used for landscape prints [the default is sides=one-sided]
  • sides=two-sided-long-edge – used for portrait prints [the default is sides=one-sided]
  • page-ranges=1-4,7,9-12 – print specific pages or page ranges
  • page-set=odd | even – print only odd or even pages
  • outputorder=normal | reverse – the pages are printed from first to last or the other way around
  • cpi=10 – characters per inch
  • lpi=6 – lines per inch
  • columns=2 – format the text in two or more columns
  • page-left=value – specify the left margin in points [1pt = 1/72inch]
  • page-right=value – specify the right margin in points [1pt = 1/72inch]
  • page-top=value – specify the top margin in points [1pt = 1/72inch]
  • page-bottom=value – specify the bottom margin in points [1pt = 1/72inch]
  • job-sheets=none – front and back cover pages
  • job-sheets=standard
  • job-sheets=classified,classified

In this article we will discuss about how to install CUPS on FreeBSD. In this article I use:

  1. FreeBSD 8.3
  2. Updated ports collection.
  3. Supported parallel or USB Printer

What is CUPS?

The Common Unix Printing System (CUPS) is an open source printing system that provides a common interface to support printers in Unix-based systems. It also provides a standardized and modular platform that allows the use of external filters like Foomatic and Ghostscript for expanded printer compatibility. CUPS is licensed under the GNU GPL and has become the standard printing system for a large number of Linux distributions as well as Mac OS X.

CUPS is composed of a print spooler, filters, and backends. It uses the Internet Printing Protocol (IPP) to accept print jobs from clients on the network. The print data is then stored in a print spool or queue until the printer is ready to accept a print job. When the printer is ready, CUPS sends the print job through filters that convert the print job data into a language the printer understands. The converted data then travels through a backend to the intended printer. Common backends include Universal Serial Bus (USB) and parallel interfaces.

Most printers communicate using either PostScript or Printer Control Language (PCL). PostScript was developed at Adobe Systems in the mid-1980s to create a standard language for both document exchange and printer communication. CUPS can print to virtually all printers that support PostScript. However, PostScript printers are notoriously expensive due to the cost of licensing the technology from Adobe. PCL was created by Hewlett-Packard in 1984 and didn’t carry the licensing restrictions of PostScript. This has created a large market of low cost PCL printers. To support this large market, projects like Gimp-Print were started to develop Unix drivers for PCL printers. HP has responded to the need for Unix-based drivers with the Hewlett-Packard Inkjet Driver Project. Gimp-Print and the HP Inkjet Driver Project greatly expand CUPS support for non-PostScript printers.


Installing CUPS is as easy as installing other ports. You can enter following commands to complete installation (use root privileges):

setenv XORG_UPGRADE yes
cd /usr/ports/print/cups
make config ; make install clean

Here we use basic / defaults options so we don’t need to change anything.


Once the installation process is complete, it’s time to configure CUPS for use on our system.

FreeBSD includes a print spooling system that utilizes the same command names as CUPS. If the search path has not been modified from its default, the FreeBSD spooler will run instead of CUPS.  Therefore we need to tell FreeBSD to use CUPS instead of its print spooler. We also need to tell make command to skip compilation of the print spooler if we choose to recompile the base operating system and consider CUPS as drop-in replacement for the FreeBSD print spooler.

Edit /etc/make.conf and add following:

cp /etc/make.conf /etc/make.conf
echo 'NO_LPR="YES"' >> /etc/make.conf

In order to allow print clients to send raw print data to the connected printer we must uncomment a line in the /usr/local/etc/cups/mime.convs file. Scroll down to the application/octet-stream declaration and remove the hash mark (#) to uncomment the line. It should now appear as follows:

application/octet-stream   application/vnd.cups-raw     0     -

Save and exit.

We are now ready to modify the main configuration file, /usr/local/etc/cups/cupsd.conf. Now change the Listen localhost:631 declaration to Listen *:631. This allows external clients access to the CUPS web administration page. Otherwise, CUPS only serve localhost (serves self only).

By default, access to CUPS services is restricted and needs to be relaxed to enable printing support to computers on the local network. Change the Allow localhost declaration within the Location / container to Allow @LOCAL. The line should appear as follows after the modification:

# Restrict access to the server...
<Location />
   Oder allow,deny
   Allow @LOCAL

By default, access to the administrative web interface is closed to the local network and can only be accessed from the server itself. To allow access from the local network, change the Allow localhost declaration within the Location /admin container to Allow @LOCAL. You should also add Require user @SYSTEM to require authentication for access to the web administration page. The lines should appear as follows after the modification:

# Restrict access to the admin pages..
<Location /admin>
   Encryption Required
   Require user @SYSTEM
   Order allow,deny
   Allow @LOCAL

Note: The root account and users that are members of the wheel group will be able to log in to the web administration page at https://host.example.com:631/admin (substitute host.example.com with your server’s hostname or IP address) to manage printers and print jobs. CUPS will encrypt authentication credentials using a self-signed certificate. We can also specify our own SSL Certificate.

Autostart at Boot

To automatically start CUPS on booting, make sure cupsd is enabled in /etc/rc.conf. You invoke following command to do so:

echo 'cupsd_enable="YES"' >> /etc/rc.conf

Save and exit. Enjoy

Social Share Buttons and Icons powered by Ultimatelysocial