Hack27.Centralize Macintosh Printing with CUPS


Hack 27. Centralize Macintosh Printing with CUPS

Mac OS X makes CUPS printers readily available from Macintosh systems.

Now that the Mac OS is actually a Unix system with graphical gravy, it's much easier to get to the underpinnings of the operating system when necessary. Also, because much of the software that actually powers Mac OS X is now familiar open source software, it's easier than ever to reapply your existing Linux/Unix knowledge to working with Mac OS X. Integrating Mac OS X printing with a CUPS server running on a remote Linux system is one of the best examples of this, because Mac OS X actually uses CUPS as the core of its printing subsystem. This hack explains how to use the familiar CUPS web interface to quickly and easily set up your Mac OS X systems to print to centralized CUPS print servers running on Linux systems. If you're still running a version of the Mac OS earlier than Mac OS X, this hack isn't for you unless you upgrade.

3.9.1. Configuring Access to a Remote CUPS Server

As well as supporting CUPS, Mac OS X also includes its own printer configuration tool, the Printer Setup Utility. The versions of the Printer Setup Utility provided with Mac OS X 10.4 and above can locate remote CUPS printers automatically, because CUPS supports the standard Internet Printing Protocol (IPP). However, just in case you can't find your printer using IPP, this hack explains the details of configuring a printer using our old friend, the web-based CUPS administrative interface. The procedure discussed in this section works fine with Versions 10.2 and later of Mac OS X.

Thanks to the fact that Mac OS X uses CUPS, the basic procedure of defining a remote printer on Mac OS X is almost identical to that of configuring remote printing on Linux systems. It is therefore also almost identical to that for creating a CUPS print server [Hack #24]. As in "Configure Linux Connections to Remote CUPS Printers" [Hack #25], I'll focus on the two screens that are different and that really matter: the Device screen, where you specify how to connect to the printer; and a new Device URL screen, where you specify the Universal Resource Locator (URL) that uniquely identifies the remote printer.

After authenticating (using the login and password of any user with administrative privileges) and beginning the process of adding a printer, you'll need to specify the protocol with which your OS X system will communicate with the remote printer. This is done on the Device screen, shown in Figure 3-14. Instead of selecting a physical connection, you'll usually select the "Internet Printing Protocol (http)" entry to specify that you want to use IPP with the HTTP protocol as its transport mechanism.

Figure 3-14. Specifying the protocol for remote printing


Once you've selected IPP over HTTP, click Continue to proceed to another Device screen, shown in Figure 3-15. This screen enables you to specify the URL of the remote printer so that the local system knows where to find the correct printer.

Figure 3-15. Specifying the URL of the remote printer


As shown in Figure 3-15, the URL of the remote CUPS printer is in the form http://address-or-name/printers/printer-name, where address-or-name is the IP address or name of the host to which the printer is physically attached, and printer-name is the name of that printer on the remote host. The URL shown in this figure reflects a different print server than was used previously; it's named silentwriter and is running on the host 192.168.6.64.

If Windows printers are available in your environment or you are running Samba on one of your systems and you prefer to print using Windows SMB protocols, you can select "Windows Printer via SAMBA" as the printing protocol that you want to use and enter a URL of the form smb://username: passwd@hostname/printers/printer-name. If you're using a version of Mac OS X earlier than 10.4, you'll also have to verify that /usr/libexec/cups/backend/smb is a symbolic link to /usr/bin/smbspool and, if not, create that link.


Once you've specified the URL for the remote printer, proceed through the rest of the printer configuration screens [Hack #24]. You'll probably also want to print a test page to ensure that you can connect to the remote printer and verify that you selected the correct print driver to format output for the remote printer. You can do that after making sure you've tweaked your server's configuration to handle HTTP print jobs correctly, as described in the next section.

3.9.2. Server-Side Configuration for HTTP Printing

Once you've finished configuring the printer on the Mac OS X system, you'll need to make a few modifications to the CUPS printer configuration files on your print server. Because the files that you print are being preformatted on your OS X system and you are using the HTTP protocol, you will need to configure the CUPS server on the Linux system to which the printer is connected. You will need to modify two configuration files to tell the CUPS server how to handle raw data files received via HTTP, configuring it to simply send those files directly to the specified print queue with no local formatting.

First, edit the file /etc/cups/mime.types, which defines valid Multipurpose Internet Mail Extensions (MIME) formats that are supported by the CUPS server. MIME defines a variety of formats that one might encounter on the Internet (such as in a web browser or in HTTP communications) and defines how MIME-aware applications should handle them. To enable printing via HTTP, remove the hash mark (#) at the beginning of the following line:

 #application/octet-stream 

Without the leading comment character (the hash mark), this entry tells the CUPS print server that raw data streams are an acceptable input format. Next, edit the file /etc/cups/mime.convs, which defines the types of conversions that the CUPS server should perform on various MIME input formats. To enable printing via HTTP, remove the hash mark at the beginning of the following line:

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

As with the change to the /etc/cups/mime.types file, removing the comment character from the beginning of this line tells the CUPS server to handle input files in application/octet-stream format by passing them to a CUPS application that simply inserts them into a print queue without doing any local formatting.

You will need to restart the CUPS print server to make sure that it picks up these changes. The startup script for your CUPS server is called cups and is typically located in /etc/init.d. To restart the CUPS print server, execute the following command (or one appropriate for your distribution):

 # /etc/init.d/cups restart 

3.9.3. Testing Printing from Mac OS X to Your CUPS Server

At this point, you're ready to try a test print job. In your web browser, select the Printers button in the CUPS page header. Click the Print Test Page button and verify that a test page prints correctly on the remote printer. If so, congratulations! If not, check the Jobs status page in your web browser by clicking Jobs in the CUPS page header. If you've made a syntax error in your URL, you'll see a message saying "Unable to connect to IPP host: Invalid Argument." Correct the URL, abort the current test page, and retry printing a test page. If you don't see any error messages but the print job claims to have completed, see the next section for some debugging tips.

Once you've successfully printed a page from your OS X system, you'll notice that the printer that you defined using the CUPS web interface is also now visible in the Printer Setup Utility. Magic!

3.9.4. Troubleshooting Mac OS X Printing to CUPS Servers

The most common cause of being unable to print to a CUPS print server is that the printer is not configured to accept print jobs from your host's IP address [Hack #24].

If you're sure that this is not the problem, check the CUPS logfiles. CUPS print servers maintain three logfiles that can provide a variety of information about attempts to access or use them: access_log, error_log, and page_log.Of these, the access_log and error_log files are the most useful for diagnostic purposes. Examining the end of these files after attempting to print but not receiving any output usually shows meaningful error messages. For example, if you forgot to update the MIME files and are trying to print to a CUPS printer from Mac OS X, you may see messages like the following:

 E [05/Sep/2005:17:55:49 -0400] get_job_attrs: job #0 doesn't exist! E [05/Sep/2005:17:55:49 -0400] print_job: Unsupported format 'application/   octet-stream'! I [05/Sep/2005:17:55:49 -0400] Hint: Do you have the raw file printing rules   enabled? 

Talk about useful error messages! Double-check the changes you made to the CUPS MIME configuration files, restart the CUPS daemon, and try printing again.

3.9.5. See Also

  • http://www.cups.org/documentation.php

  • "Create a CUPS Print Server" [Hack #24]

  • "Configure Linux Connections to Remote CUPS Printers" [Hack #25]



Linux Server Hacks (Vol. 2)
BSD Sockets Programming from a Multi-Language Perspective (Programming Series)
ISBN: N/A
EAN: 2147483647
Year: 2003
Pages: 162
Authors: M. Tim Jones

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net