This chapter provides background information and procedures for customizing the LP print service.
This is a list of the step-by-step instructions in this chapter.
For overview information about printers, see Chapter 2, Managing Printing Services (Overview).
The printer port characteristics set by the LP print service must be compatible with the printer communication settings. If the default printer port settings provided by the LP print service do not work with a printer, refer to the printer manual from the manufacturer to find out what settings the printer requires from the LP print service. Use the stty command to set and display printer communication settings.
The following table shows the default stty settings used by the LP print service.
Table 7–1 stty Default Settings Used by the LP Print Service
Option |
Meaning |
---|---|
-9600 |
Set baud to 9600 |
-cs8 |
Set 8-bit bytes |
-cstopb |
Send one stop bit per byte |
-parity |
Do not generate parity |
-ixon |
Enable XON/XOFF (also known as START/STOP or DC1/DC3) |
-opost |
Do “output post-processing” using all the settings that follow in this table |
-olcuc |
Do not map lowercase to uppercase |
-onlcr |
Change line feed to carriage return/line feed |
-ocrnl |
Do not change carriage returns into line feeds |
-onocr |
Output carriage returns even at column 0 |
-n10 |
No delay after line feeds |
-cr0 |
No delay after carriage returns |
-tab0 |
No delay after tabs |
-bs0 |
No delay after backspaces |
-vt0 |
No delay after vertical tabs |
-ff0 |
No delay after form feeds |
Log in as superuser, lp, or assume an equivalent role on the print server.
Adjust the printer port characteristics.
# lpadmin -p printer-name -o "stty=options" |
-p printer-name |
Name of the printer for which you are adjusting the port characteristics. |
-o "stty=options” |
Sets the port characteristic (stty option) specified by options.You can change more than one stty option setting with this command. Enclose each option in single quotation marks and use a space to separate the options. For a complete list of options, see stty(1). Table 7–1 shows the default stty settings used by the LP print service. |
Verify that the printer port characteristics have been changed.
# lpstat -p printer-name -l |
The following example shows how to set the port characteristics for the printer luna. The parenb option enables parity checking/generation, parodd sets odd parity generation, and cs7 sets the character size to 7 bits.
# lpadmin -p luna -o "stty='parenb parodd cs7'" |
The following example shows how to set the terminal baud rate to 19200 for the printer venus.
# lpadmin -p venus -o "stty=19200" |
The LP print service uses an interface program and the terminfo database to initialize each printer and establish a selected page size, character pitch, line pitch, and character set.
Each printer is identified in the terminfo database with a short name. The name required by the terminfo database is identical to the name used to set the TERM shell variable. This name is also the printer type you specify when setting up a printer. For example, the entries for different types of PostScript printers are in the /usr/share/lib/terminfo/P directory. The default entries provided with the SunOS release are PS (for PostScript) and PSR (for PostScript Reverse).
If you cannot find a terminfo entry for your printer, you still might be able to use the printer with the LP print service without the automatic selection of page size, pitch, and character sets. However, you might have trouble keeping the printer set in the correct modes for each print request.
If there is no terminfo entry for your type of printer and you want to keep the printer set in the correct modes, you can either customize the interface program used with the printer or add an entry to the terminfo database. A terminal or printer entry in the terminfo database contains and defines hundreds of items. The LP print service, however, uses fewer than 50 of these items. The following table lists the required terminfo items for a printer.
Table 7–2 Required terminfo Items for a Printer
Item |
|
Meaning |
---|---|---|
Booleans: |
|
|
|
cpix |
Changing character pitch changes resolution |
|
daisy |
Printer requires an operator to change character set |
|
lpix |
Changing line pitch changes resolution |
Numbers: |
|
|
|
bufsx |
Number of bytes buffered before printing |
|
cols |
Number of columns in a line |
|
cps |
Average print rate in characters per second |
|
it |
Tabs initially every n spaces |
|
lines |
Number of lines on a page |
|
orc |
Horizontal resolution, in units per character |
|
orhi |
Horizontal resolution, in units per inch |
|
orl |
Vertical resolution, in units per line |
|
orvi |
Vertical resolution, in units per inch |
Strings: |
|
|
|
chr |
Change horizontal resolution |
|
cpi |
Change number of characters per inch |
|
cr |
Carriage return |
|
csnm |
List of character set names |
|
cudl |
Down one line |
|
cud |
Move carriage down n lines |
|
cuf |
Move carriage right n columns |
|
cvr |
Change vertical resolution |
|
ff |
Page eject |
|
hpa |
Horizontal position absolute |
|
ht |
Tab to next 8-space tab stop |
|
if |
Name of initialization file |
|
iprog |
Path name of initialization program |
|
is1 |
Printer initialization string |
|
is2 |
Printer initialization string |
|
is3 |
Printer initialization string |
Strings: |
|
|
|
lpi |
Change number of lines per inch |
|
mgc |
Clear all margins (top, bottom, and sides) |
|
rep |
Repeat a character n times |
|
rwidm |
Disable double-wide printing |
|
scs |
Select character set |
|
scsd |
Start definition of a character set |
|
slines |
Set page length to n lines per page |
|
smgl |
Set left margin at current column |
|
smglp |
Set left margin |
|
smgr |
Set right margin at current column |
|
smgrp |
Set right margin |
|
smglr |
Set both left and right margins |
|
msgt |
Set top margin at current line |
|
smgtp |
Set top margin |
|
smgb |
Set bottom margin at current line |
|
smgbp |
Set bottom margin |
|
smgtb |
Set both top and bottom margins |
|
swidm |
Enable double-wide printing |
|
vpa |
Vertical position absolute |
Before you create a terminfo entry for a printer, you should first make sure none of the existing terminfo entries will support the printer. To do so, try to set up the printer with an entry for a similar printer, if there is one.
Log in as superuser, lp, or assume an equivalent role on the print server.
Determine a terminfo entry name for the printer.
The directories in the /usr/share/lib/terminfo directory contain all the valid terminfo entries. Use them as a guide for choosing a name for the printer.
Create a terminfo entry file for the printer.
Table 7–2 shows the items you must define in the terminfo entry to add a new printer to the LP print service. For more details about the structure of the terminfo database, see terminfo(4).
To help you start writing a new terminfo entry, use the infocmp command to save an existing terminfo entry to a file. This is helpful if there is a terminfo entry that is similar to one you want to create. For example, the following command saves the ps entry to the ps_cust file, which will become the new terminfo entry.
infocmp ps > ps_cust
Compile the terminfo entry file into the terminfo database.
# tic terminfo_entry |
terminfo_entry |
The terminfo entry file you created. |
Check for the new terminfo entry file in the /usr/share/lib/terminfo directory.
If you have a printer that is not supported by the standard printer interface program, you can furnish your own printer interface program. You can copy the standard program and then tell the LP print service to use it for a specified printer. But first you need to understand what is in the standard program. The following section describes the standard program.
A printer interface program should:
Initialize the printer port, if necessary. The standard printer interface program uses the stty command to initialize the printer port.
Initialize the printer hardware. The standard printer interface program gets the control sequences from the terminfo database and the TERM shell variable.
Print a banner page, if necessary.
Print the number of copies specified by the print request.
If you have a printer interface program from a release of UNIX System V prior to Release 3.2, it will probably work with the SunOS 5.9 or compatible LP print service. However, several -o options have been standardized in the SunOS 5.9 or compatible LP print service and will be passed to every printer interface program. These options might interfere with similarly named options used by the old interface.
The LP print service, not a printer interface program, is responsible for opening the printer port. The printer port is given to the printer interface program as standard output, and the printer is identified as the “controlling terminal” for the printer interface program so that a “hang-up” of the port will cause a SIGHUP signal to be sent to the printer interface program.
The standard (model) printer interface program, /usr/lib/lp/model/standard, is used by the LP print service to set the printing defaults shown in Table 7–3.
Table 7–3 Default Printer Port Characteristics
Characteristic |
Default Setting |
---|---|
Default filter |
None |
Character pitch |
None |
Line pitch |
None |
Page width |
None |
Page length |
None |
Character set |
None |
stty options |
9600 cs8 -cstopb -parenb -parodd ixon -ixany opost -olcuc onlcr -ocrnl -onocr -onlret -ofill nl0 cr0 tab0 bs0 vt0 ff0 |
0 |
If you need to change the terminal characteristics, like baud rate or output options, look for the section of the standard printer interface program that begins with the following comment:
## Initialize the printer port
When printing is complete, your interface program should exit with a code that shows the status of the print job. The exit code is the last entry in the printer interface program.
The following table shows the exit codes and how they are interpreted by the LP print service.
Table 7–4 Printer Interface Program Exit Codes
Code |
Meaning to the LP Print Service |
---|---|
0 |
The print request has been successfully completed. If a printer fault occurred, it has been cleared. |
1 to 127 |
A problem was encountered when printing a request (for example, too many nonprintable characters or the request exceeds the printer capabilities). The LP print service notifies the person who submitted the request that there was an error when printing it. This error will not affect future print requests. If a printer fault has occurred, it has been cleared. |
128 |
This code is reserved for internal use by the LP print service. Interface programs must not exit with this code. |
129 |
A printer fault was encountered when printing the request. This fault will affect future print requests. If the fault recovery for the printer directs the LP print service to wait for the administrator to correct the problem, the LP print service disables the printer. If the fault recovery is to continue printing, the LP print service will not disable the printer, but it will try printing again in a few minutes. |
>129 |
These codes are reserved for internal use by the LP print service. Interface programs must not exit with codes in this range. |
If the program exits with a code of 129, root is alerted of a printer fault. The LP print service must also reprint the request from the beginning, after the fault has been cleared. If you do not want the entire request to be reprinted, you can have the interface program send a fault message to the LP print service, but wait for the fault to be cleared. When the fault is cleared, the interface program can resume printing the file. When printing is finished, the printer interface program can give a zero exit code, just as if the fault had never occurred. An added advantage of this approach is that the interface program can detect when the fault is cleared automatically, so that the administrator does not need to re-enable the printer.
You can use the lp.tell program to send fault messages to the LP print service. This program is referenced by the LPTELL shell variable in the standard printer interface code. The program takes standard input and sends it to the LP print service, where it is put into the message that alerts the administrator to the printer fault. If its standard input is empty, lp.tell does not initiate an alert. For an example of how the lp.tell program is used, examine the standard printer interface code immediately after the following comment:
# Set up the $LPTELL program to capture fault messages here
If you use the special exit code 129 or the lp.tell program, the printer interface program does not need to disable the printer itself. The interface program can disable the printer directly, but doing so will override the fault-alerting mechanism. Alerts are sent only if the LP print service detects that the printer has a fault, and the special exit code and the lp.tell program are its main detection tools.
If the LP print service has to interrupt printing of a file at any time, it kills the interface program with a signal TERM (trap number 15). (For more information, see kill(1) and signal(3C).) If the printer interface program dies from receipt of any other signal, the LP print service assumes that future print requests will not be affected, and continues to use the printer. The LP print service notifies the user who submitted the request that the request has not been finished successfully.
When the interface is first invoked, the signals HUP, INT, QUIT, and PIPE (trap numbers 1, 2, 3, and 13) are ignored. The standard interface changes this so the signals are trapped at appropriate times. The standard interface interprets receipt of these signals as warnings that the printer has a problem; when it receives a signal, it issues a fault alert.
You can create a customized printer interface program and use it in place of the standard printer interface program on the print server. To do so, you use the lpadmin command to register the program with the LP print service for a specific printer.
Log in as superuser, lp, or assume an equivalent role on the print server.
Determine your next step based on whether you have a custom printer interface program.
Custom Printer Interface Status |
Action |
---|---|
Need to create a custom printer interface program |
Go to Step 3. |
Already have a custom printer interface program |
Go to Step 5. |
Copy the standard printer interface program.
# cp /var/spool/lp/model/standard custom-interface |
Change the copy of the standard printer interface program to meet your needs.
Refer to the description of the program in The Standard Printer Interface Program to determine what you need to change.
Set up the custom printer interface program for a specific printer.
# lpadmin -p printer-name -i custom-interface |
-p printer-name |
The printer that will use the custom printer interface program. |
-i custom-interface |
Name of the custom printer interface program. |
The custom printer interface program is registered with the LP print service, and will be used by that printer when users submit print requests.
Verify that the custom printer interface program has been added in the /etc/lp/printers/printer-name/configuration file.
The following example shows how to set up a custom printer interface program named custom for the printer luna.
# lpadmin -p luna -i custom |
The following example shows how to copy a custom printer interface program from the printer venus to the printer asteroid.
# lpadmin -p asteroid -e venus |
A filter is used by the LP print service each time it has to print a type of file that the printer cannot interpret. Creating a new print filter is not easy; it usually requires extensive experimentation. The process of defining a new print filter consists of two steps:
Writing a print filter program
Creating a print filter definition
A print filter can be as simple or as complex as needed. Filters contain input types, output types, and complex options that provide a language to process command-line arguments within the filter.
If you have non-PostScript printers, you have to create and add print filters as required. First, you need to understand what print filters are and the requirements that must be met by a filter program.
The LP print service provides filter programs in the /usr/lib/lp/postscript directory. These filters cover most PostScript printing situations—where the destination printer requires the data to be in PostScript format. A print filter program must be a binary executable.
There are two types of print filters: fast filters and slow filters.
Fast filters do not require much processing time to prepare a file for printing. They must have access to the printer when they run. To be capable of detecting printer faults, a print filter must be a fast filter. Any filter that uses the PRINTER keyword as a filter option must be installed as a fast filter.
Slow filters require a great deal of processing time to prepare a file for printing. They do not require access to the printer when they run. Slow filters are run in the background so they do not tie up the printer, allowing other files that do not need slow filtering to be printed.
The LP print service uses print filters to convert files from one content type to another. You can specify the accepted file content types for each printer. The user specifies the file content type when submitting a print request, and the LP print service finds a printer that can print files of that content type. Because many applications can generate files for various printers, this is often sufficient. However, some applications can generate files that cannot be printed on any available printers.
Each time the LP print service receives a request to print a type of file that is in a format that cannot be accepted directly by a printer, the LP print service tries to match the content type of the print request with the content type of the available (or specified) printer. If there is a match, the file can be sent directly to the printer without filtering. If no match is found, or if the content type specifies that a filter be used, the LP print service tries to match the content type of the file with the input content type of available filters, and match the output type of the filter with the content type of the printer. When an appropriate filter is found, the print request is passed through the filter.
A print filter handles special modes and requests to print specific pages. A special printing mode is needed to print any characteristics of print requests that require a customized filter. Filters handle the following characteristics:
Printer type
Character pitch
Line pitch
Page length
Page width
Pages to print
Character set
Form name
Number of copies
The LP print service provides default settings for these characteristics; however, a print filter can handle some characteristics more efficiently. For example, some printers can handle multiple copies more efficiently than the LP print service, and, in this case, you can provide a filter for multiple-copy page control.
Each printer has its own way of detecting printer faults and transmitting fault signals to the LP print service. The LP print service only checks for hang-ups (loss of carrier) and excessive delays in printing.
Some printers provide good fault coverage and can send a message describing the reason for a fault. Other printers indicate a fault by using signals other than the signals indicating loss of carrier signal or shut off of data flow. A filter is required to interpret this additional printer fault information.
A filter can also put a print request on hold, wait for a printer fault to clear, and then resume printing. With this capability, the print request that was interrupted does not need to be reprinted in its entirety. Only a filter that knows the control sequences used by a printer can determine where to break a file into pages. Consequently, only such a filter can find the place in the file where printing should start after a fault is cleared.
When a print filter generates messages, those messages are handled by the LP print service, and alerts are sent to the system administrator if alerts are enabled. For further information, see Setting Up Printer Fault Alerts.
A print filter can be simple or complex, but it has to meet the following requirements:
The filter should get the contents of a file from its standard input and send the converted file to the standard output.
A program cannot be used as a filter if it references external files. You might be tempted to use a program like troff, nroff, or a similar word processing program as a filter. The LP print service does not recognize references to other files, known as include files, from a filter program. Because troff and nroff allow include files, they can fail when used as filters. If the program needs other files to complete its processing, it should not be used as a filter.
The filter should not depend on files that normally would not be accessible to a user. If a filter fails when run directly by a user, it will fail when run by the LP print service.
A slow filter can send messages about errors in the file to standard error; a fast filter should not. Error messages from a slow filter are collected and sent to the user who submitted the print request.
If a slow filter dies because it received a signal, the print request is stopped and the user who submitted the request is notified. Likewise, if a slow filter exits with a non-zero exit code, the print request is stopped and the user is notified. The exit codes from fast filters are treated differently.
If you want the filter to detect printer faults, it should also meet the following requirements:
If possible, the filter should wait for a fault to be cleared before exiting. It should also continue to print at the top of the page where printing stopped after the fault is cleared. If you do not want use the continuation feature, the LP print service will stop the filter before alerting the administrator.
The filter should send printer fault messages to its standard error as soon as the fault is recognized. It does not have to exit; it can wait for the fault to be cleared.
The filter should not send messages about errors in the file to standard error. These messages should be included in the standard output, where they can be read by the user.
The filter should exit with a zero exit code if the file is finished printing (even if errors in the file have prevented it from being printed correctly).
The filter should exit with a non-zero exit code only if a printer fault has prevented it from finishing a print request.
When added to the filter table, the filter must be added as a fast filter.
A print filter definition tells the LP print service about the filter, what print filter program to run, what kind of conversion it does, and so on. A set of filter descriptor files are provided in the /etc/lp/fd directory. These files describe the characteristics of the filters (for example, fast or slow filter), and point to the filter programs (for example, /usr/lib/lp/postscript/postdaisy).
When defining a new print filter, in addition to writing a filter program, you must create a print filter definition. A print filter definition contains the following information used by the LP print service:
Name of the filter program to run
Input types it accepts
Output types it produces
Printer types to which it can send jobs
Names of specific printers to which it can send jobs
Filter types (either fast or slow)
Options
You can type the characteristics as direct input to the lpfilter command. You also can create a file that specifies the filter's characteristics, and use the file name as input to the lpfilter command. Such a file is called a filter descriptor file and should be located in the /etc/lp/fd directory. These files are not the filters themselves, but rather point to the filters.
Whether you store the information in a file, or enter it directly on the command line, use the following format:
Command: command-pathname [options] Input types: input-type-list Output types: output-type-list Printer types: printer-type-list Printers: printer-list Filter type: fast or slow Options: template-list |
If you provide more than one definition (that is, more than one line) for any filter characteristic other than Options, only the second definition will be used by the print service.
The information can be arranged in any order, and not all the information is required. When you do not specify values, those shown in the following table are assigned by default. They are not very useful, which is why you should specify explicit values.
Table 7–5 Default Values for lpfilter Arguments
Item |
Default |
---|---|
Input types |
any |
Output type |
any |
Printer types |
any |
Printers |
any |
Filter type |
slow |
Use the full path of the filter program. If there are any fixed options that the program always needs, include them here.
Input types is a list of file content types that the print filter can process. The LP print service does limit the number of input types, but most filters can accept only one type. Several file types can be similar enough that the filter can deal with them. You can use whatever names you like, with a maximum of 14 alphanumeric characters and dashes. Do not use underscores as part of the input type name.
The LP print service uses these names to match a filter to a file type, so follow a consistent naming convention. For example, if more than one filter can accept the same input type, use the same name for that input type when you specify it for each filter. Inform your users of these names so they know how to identify the file type when submitting a file for printing.
Output types is list of file types that the filter can produce as output. For each input type, the filter produces a single output type. The output type can vary, however, from job to job. The name of the output type is restricted to 14 alphanumeric characters and dashes.
The output type names should either match the types of available (local or remote) printers, or match the input types handled by other filters. The LP print service groups filters in a shell pipeline if it finds that several passes by different filters are needed to convert a file. It is unlikely that you will need this level of sophistication, but the LP print service allows it. Try to find a set of filters that takes as input types all the different files the users might want printed, and that converts those files directly into file types the printer can handle.
Printer types is a list of the types of printers into which the print filter can convert files. For most printers and filters, you can leave this part of the filter definition blank, because it is identical to the list of output types. But it can be different. For example, you could have a printer with a single printer type for purposes of initialization, but which can recognize several different file content types. Essentially, this printer has an internal filter that converts the various file types into one that it can handle. Thus, a filter might produce one of several output types that match the file types that the printer can handle. The print filter should be marked as working with that printer type.
As another example, you might have two different models of printers that are listed as accepting the same file types. Due to slight differences in manufacture, however, one printer deviates in the results it produces. You label the printers as being of different printer types, say A and B, where B is the one that deviates. You create a filter that adjusts files to account for the deviation produced by printers of type B. Because this filter is needed only for those printer types, you would list it as working only on type B printers.
A print filter is normally able to work with all printers that accept its output, so you can usually skip this part of the filter definition.
You might, however, have some printers that are or inappropriate for the output that the filter produces. For example, you might want to dedicate one printer for fast turnaround, only sending files that require no filtering to that printer. Other printers of identical type can be used for files that need extensive filtering before they can be printed.
The LP print service recognizes fast and slow filters, as described in Types of Filters.
Slow filters that are invoked by printing modes (using the lp -y command) must be run on the system from which the print request originated. The LP print service cannot pass values for modes to print servers. It can, however, match a file content type (specified after the -T option of the lp command) to a content type on a print server. Therefore, if you want to activate special modes on a print server, you must specify content types that permit the LP print service to match input types and output types.
Options specify how different types of information are converted into command-line arguments to the filter command. This information can include specifications from a user (with the print request), the printer definition, and the specifications implemented by any filters used to process the request.
There are 13 sources of information for defining print filter options, each of which is represented by a keyword. Each option is defined in a template. A template is a statement in a filter definition that defines an option to be passed to the filter command, based on the value of one of the characteristics of the filter.
The options specified in a filter definition can include none, all, or any subset of the 13 keywords. In addition, a single keyword can be defined more than once, if multiple definitions are required for a complete filter definition. The following table contains descriptions of the 13 keywords available for defining Options in a print filter definition.
Table 7–6 Print Filter Options Keywords
Keyword |
Possible Patterns |
Example |
|
---|---|---|---|
Content type (input) |
INPUT |
content-type |
troff |
Content type (output) |
OUTPUT |
content-type |
postscript, impress |
Printer type |
TERM |
printer-type |
att495 |
Printer name |
PRINTER |
printer-name |
lp1 |
Character pitch |
CPI |
scaled-decimal |
10 |
Line pitch |
LPI |
scaled-decimal |
6 |
Page length |
LENGTH |
scaled-decimal |
66 |
Page width |
WIDTH |
scaled-decimal |
80 |
Pages to print |
PAGES |
page-list |
1-5,13-20 |
Character set |
CHARSET |
character-set |
finnish |
Form name |
FORM |
form-name |
invoice2 |
Number of copies |
COPIES |
integer |
3 |
MODES |
mode |
landscape |
A print filter definition can include more than one template. Multiple templates are entered on a single line and separated with commas, or they are entered on separate lines, preceded by the Options: prefix.
The format of a template is as follows:
keywordpattern = replacement
The keyword identifies the type of option being registered for a particular characteristic of the filter.
The pattern is a specific option for the keyword.
The replacement is what happens when the keyword has the noted value.
For an example of how an option is defined for a particular filter, suppose you want to have the print service scheduler assign print requests to filters following this criteria:
If the type of OUTPUT to be produced by the filter is impress, then pass the -I option to the filter.
If the type of OUTPUT to be produced by the filter is postscript, then pass the -P option to the filter.
To specify these criteria, provide the following templates as options to the lpfilter command:
Options: OUTPUT impress=-I, OUTPUT postscript=-P |
If the Options line becomes too long, put each template on a separate line, as follows:
Options: OUTPUT impress=-I Options: OUTPUT postscript=-P |
In both templates, the keyword is defined as OUTPUT. In the first template, the pattern is impress and the value of the replacement is --I. In the second template, the value of pattern is postscript and the value of replacement is -P.
To find out which values to supply for each type of template (that is, for the pattern and replacement arguments for each keyword), consider the following:
The values for the INPUT templates come from the file content type that needs to be converted by the filter.
The values for the OUTPUT templates come from the output type that has to be produced by the filter.
The value for the TERM template is the printer type.
The value for the PRINTER template is the name of the printer that will print the final output.
The values for the CPI, LPI, LENGTH, and WIDTH templates come from the user's print request, the form being used, or the default values for the printer.
The value for the PAGES template is a list of pages that should be printed. Typically, it is a list of page ranges separated by commas. Each page range consists of a pair of numbers separated by a dash, or a single number. (For example, 1–5,6,8,10 indicates pages 1 through 5, plus pages 6, 8, and 10.) However, whatever value was given in the -P option to a print request is passed unchanged.
The value for the CHARSET template is the name of the character set to be used.
The value for the FORM template is the name of the form requested by the lp -f command (the command used to submit a print request).
The value of the COPIES template is the number of copies of the file to print. If the filter uses this template, the LP print service will reduce to one the number of copies of the filtered file it prints, since this “single copy” includes the multiple copies produced by the filter.
The value of the MODES template comes from the lp -y command. Because a user can specify several -y options, there might be several values for the MODES template. The values will be applied in the left-to-right order given by the user.
The replacement part of a template shows how the value of a template should be given to the filter program. It is typically a literal option, sometimes with the placeholder asterisk (*) included to show where the value goes. The pattern and replacement also can use the regular expression syntax of the ed command for more complex conversion of user input options into filter options. All regular expression syntax of ed is supported, including the \( ... \) and \n constructions, which can be used to extract portions of the pattern for copying into the replacement, and the &, which can be used to copy the entire pattern into the replacement. For more information, see ed(1).
If a comma or an equal sign (=) is included in a pattern or a replacement, precede it with a backslash (\). A backslash in front of any of these characters is removed when the pattern or replacement is used.
Log in as superuser, lp, or assume an equivalent role on the print server.
Create a print filter program.
For information on print filter programs, see Writing a Print Filter Program. By convention, filter programs for PostScript printers are located in the /usr/lib/lp/postscript directory. You should put programs you create under the /usr/lib/lp directory in a directory of your choosing.
Create a print filter definition.
For information on print filter definitions, see Creating a Print Filter Definition. You should save the printer filter definition in a text file. By convention, filter definitions are located in the /etc/lp/fd directory and are identified with the .fd suffix.
Add the print filter to a print server.
For instructions, see How to Add a Print Filter.
The following example shows a print filter definition to convert N37 or Nlp to simple.
Input types: N37, Nlp, simple Output types: simple Command: /usr/bin/col Options: MODES expand = -x Options: INPUT simple = -p -f |
In this example, the print filter program is named col. Once you add the new print filter to a print server, a user's print requests will be handled as follows:
When a user enters the following command:
$ lp -y expand report.doc |
The print filter program is run with the following arguments to convert the file:
/usr/bin/col -x -p -f |
When a user enters the following command:
$ lp -T N37 -y expand report.doc |
The print filter program is run with the following arguments to convert the file:
/usr/bin/col -x |
The following example shows a print filter definition to convert from troff to PostScript.
Input types: troff Output types: postscript Printer types: PS Filter type: slow Command: /usr/lib/lp/postscript/dpost Options: LENGTH * = -l* Options: MODES port = -pp, MODES land = -pl Options: MODES group \=\([1-9]\) = -n\l |
In this example, the filter program is named dpost. It takes one input type, troff, produces a postscript output, and works with any printer of type PS (PostScript). Users need to give just the abbreviation port or land when they ask for the paper orientation to be in portrait mode or landscape mode. Because these options are not intrinsic to the LP print service, users must specify them using the lp -y command.
After you add the new print filter to a print server, print requests will be handled as follows:
When a user enters the following command to submit a troff file type for printing on a PostScript printer (type PS), with requests for landscape orientation and a page length of 60 lines:
$ lp -T troff -o length=60 -y land -d luna ch1.doc |
The print filter program dpost is run with the following arguments to convert the file:
/usr/lib/lp/postscript/dpost -l60 -pl |
When a user enters the following command:
$ lp -T troff -y group=4 -d luna ch1.doc |
The print filter program dpost is run with the following arguments to convert the file:
/usr/lib/lp/postscript/dpost -n4 |
When you want to provide a new form, you must define its characteristics by entering information about nine required characteristics (such as page length and page width) as input to the lpforms command. The LP print service uses this information to:
Initialize the printer so that printing is done properly on the form
Send reminders to the system administrator about how to handle the form
The form name can be anything you choose, as long as it does not contain more than 14 alphanumeric characters and underscores. The information must be in the following format:
Page length: scaled number Page width: scaled number Number of pages: integer Line pitch: scaled number Character pitch: scaled number Character set choice: character-set-name [,mandatory] Ribbon color: ribbon-color Comment: informal notes about the form Alignment pattern: [content-type] alignment pattern |
The optional phrase [,mandatory] means that the user cannot override the character set choice in the form. The content-type can be given, although this is optional, with an alignment pattern. If this attribute is given, the print service uses it to determine, as necessary, how to filter and print the file.
With two exceptions, the information can appear in any order. The exceptions are the Alignment pattern (which must always be last), and the comment (which must always follow the line with the Comment: prompt). If the comment contains a line beginning with a key phrase (like Page length, Page width, and so on), precede that line with a > character so the key phrase is not at the beginning of the line. The initial > character is stripped from the comment and is not displayed.
Not all of the information must be given. When you do not specify values for the items listed in the following table the default values are assigned. Before running the lpforms command, gather the following information about the new form:
Table 7–7 Default Form Values
Item |
Default |
Description |
---|---|---|
Page length |
66 lines |
The length of the form, or the length of each page in a multipage form. This information can be the number of lines, or the size in inches or centimeters. |
Page width |
80 columns |
The width of the form, in characters, inches, or centimeters. |
Number of pages |
1 |
The number of pages in a multipage form. The LP print service uses this number with a print filter (if available) to restrict the alignment pattern to a length of one form. See the description of alignment pattern below. If no filter is available, the LP print service does not truncate the output. |
Line pitch |
6 lines per inch |
A measurement of how close lines appear on the form. This is also called leading. It is the distance between two lines, from baseline to baseline, measured by either lines per inch or lines per centimeter. |
Character pitch |
10 characters per inch |
A measurement of how close together characters appear on the form. It is the distance between characters, measured by either characters per inch or characters per centimeter. |
Character set choice |
Any |
The character set, print wheel, or font cartridge that should be used when this form is used. Users can choose a different character set for their own print requests when using this form, or you can require that only one character set be used. |
Ribbon color |
Any |
If the form should always be printed using a certain color ribbon, the LP print service can give a mount alert message indicating which color to use. |
Comment |
(No default) |
Any remarks that might help users understand the form. For example, the remarks could indicate the name of the form, its revision, its purpose, or restrictions on its use. |
(No default) |
A sample file that the LP print service uses to fill one blank form. When mounting the form, you can print this pattern on the form to align it properly. You can also define a content type for this pattern so that the print service knows how to print it. |
The LP print service does not try to mask sensitive information in the alignment pattern. If you do not want sensitive information printed on sample forms—for example when you align checks—then you should mask the appropriate data. The LP print service keeps the alignment pattern stored in a safe place, where only those logged in as root or lp can read it.
When you have gathered the information for the form, you enter it as input to the lpforms command. You should record this information first in a separate file so you can edit it before entering it with the lpforms command. You can then use the file as input instead of typing each piece of information separately after a prompt.
Log in as superuser, lp, or assume an equivalent role on the print server.
Create a form definition file.
For a description on creating print forms, see Creating a New Printer Form. You should save the printer definition in a text file.
Add the form to the LP print service.
# lpadmin -p printer-name -M -f form-name |
Add the form to a print server.
For instructions, see How to Add a Form.