To Contents

Hpmodeset Users Guide

Glenn Maughan,

v2.1, 22 January 1996

Many of the newer model Hewlett-Packard printers do not have a control panel to change printer settings. In a Windows/DOS environment you are typically given drivers that allow you to change the printer settings. However, in a Unix environment such as Linux you usually do not get such nice drivers! I purchased a new LaserJet printer and found I could not control it completely under Linux. To reduce my frustrations I developed this utility.


  1. Introduction
  2. Switches
    1. General Switches
    2. Configuration Switches
    3. Printer Switches
    4. File List
  3. Usage
  4. Configuration
    1. Globals Section
  5. Languages Section
    1. Variables Section
    2. Config Syntax
    3. Encapsulation Order
  6. Contributors
  7. Where to find it

1 Introduction

Hpmodeset provides a configurable utility for controlling printer settings in a Unix environment. Most newer model printers have a control language that can be used to change the way documents will be printed. For example, all Hewlett-Packard printers support the language PJL (Printer Job Language) for changing printer settings.

The settings you can change on a printer usually include features such as, toner saving modes, extra margins, orientation, duplex printing and so on. Hpmodeset can be configured to set the features that your printer supports.

To Contents

2 Switches

The current configuration of hpmodeset on your system can be listed by executing with the -help switch:

$ hpmodeset -help

This will output the current configuration of hpmodeset on your system. It will look similar to the following:

    hpmodeset [-help | -config | -license]
    hpmodeset [] [] file ...
General switches:
    -help               display this help message and current printer switches
    -config             display the printer configuration information
    -license            display the licensing information (GNU General Public License)
Configuration switches:
    -configfile=  use  as the configuration file and store
                        in .store
    -notext		do not allow unknown printer languages to be passed through as
			straight text
    -pjlonly            output PJL commands only.  Do not process file list.
Example printer switches: (default values shown in braces)
    -formlines=[5-128 {60}]
    -economode=[ON | {OFF} | on | off]
    -pageprotect=[ON | {AUTO} | on | auto]
    -resolution=[300 | {600}]
    -orientation=[{PORTRAIT} | LANDSCAPE | portrait | landscape]
    -mptray=[{CASSETTE} | MANUAL | FIRST | cassette | manual | first]
    -copies=[1-999 {1}]
    -manualfeed=[ON | {OFF} | on | off]
    -personality=[{AUTO} | PCL | POSTSCRIPT | auto | pcl | postscript]
    -ret=[OFF | LIGHT | {MEDIUM} | DARK | off | light |
        medium | dark]
    -paper=[LETTER | LEGAL | {A4} | EXECUTIVE | COM10 | MONACH |
        C5 | CL | B5 | CUSTOM | letter | legal |
        a4 | executive | com10 | monach | c5 | cl |
        b5 | custom]
    -timeout=[5-300 {15}]                                                                

To Contents

2.1 General Switches

The following switches are available at all times. If used, all other switches on the command line are ignored. Only one of the switches can be used at a time.

Display a short description of the command line syntax. This also lists all printer control switches currently available and their valid options.
List the current configuration in the form of each command line switch, the printer control command, valid options and the default option.
Show the copyright and licensing information.

To Contents

2.2 Configuration Switches

The following switches are used to select a specific configuration file to be read and to adjust the way hpmodeset operates. The order in which these switches appears on the command line is unimportant. However, for readability, they should be listed first before any printer control switches or the file list.

Use <file> as the configuration file. hpmodeset will read and parse the configuration settings in <file> and store the resulting configuration in a file named <file>.store. Running
Do not allow unknown print file languages to be output. By default, any print file containing an unknown printer language is output as straight text (without an ENTER LANGUAGE command). This option turns off this feature.
Only output the PJL commands. Ignore any file list. This is useful for sending SET DEFAULT commands to printers to make persistent changes to the printer settings.

To Contents

2.3 Printer Switches

The general form of a printer control command line switch is as follows:


where switch is one of the recognised printer switches and value is a valid textual value for that switch. For example, hpmodeset may be configured to understand a switch to turn draft mode on or off. The user may then add the following switch to hpmodeset's command line:


This would encapsulate the printer files in the printer control command to turn draft mode on. The value is optional. If the user does not add a value after the equals sign then the default option is used:


would encapsulate the printer files in the default draft mode printer control command.

Any number of printer control switches can be added to the command line. The list of file names to encapsulate will be read following the last valid printer control switch. Note that the equals sign is required whether a value has been given or not.

To Contents

2.4 File List

The files containing printer language commands (as understandable by your printer). Each file will be encapsulated within the printer control commands that represent the options selected by the user. The resulting file will then be sent to stdout. If the file name

To Contents

3 Usage

hpmodeset generates encapsulated printer files to its standard output. To determine the switches available in your local configuration run hpmodeset with the -help switch. This will list all available command line switches along with the valid values for each switch.

The user can redirect the output of hpmodeset to a file, pipe it directly to a print command (like lpr), or to another filter for further processing.

hpmodeset file1 < file2
hpmodeset -draft=on file1 | lpr

The first example above encapsulates file1 within printer control commands (in this case none) and redirects the output to file2. The second example pipes the output (encapsulated in a draft command) to the lpr command.

To read standard input use the file marker -, as in the following example:

cat file1 | hpmodeset -draft=on - | lpr

To Contents

4 Configuration

hpmodeset is configured through a text file that defines the available printer control switches, their command syntax and valid options. The configuration file is composed of a number of sections. Each section has the following form:

Section SectionName

The valid SectionNames are globals, languages, and variables. Each SectionEntry has a different format depending on the section it is contained within.

To Contents

4.1 Globals Section

The globals section is mandatory. It contains a number of global settings for hpmodeset to function correctly. The syntax for SectionEntry in the globals section is as follows:

GlobalVariableName VariableValue

The GlobalVariableName may be one of job_header, job_trailer, reset_command, end_of_command or white_space.

The VariableValue for each of these settings must be a string of characters surrounded by double quotes. Entries for every GlobalVariableName must appear in the config file.

The globals section typically looks like:

Section globals
    job_header        "%/27/%%-12345X@PJL COMMENT (C) 1995/1996 Glenn Maughan" 
    job_trailer	      "%/27/%%-12345X@PJL COMMENT end of job"
    reset_command     "@PJL RESET%N%/27/%%-12345X"
    end_of_command    "%N"
    white_space       " "		

To Contents

5 Languages Section

The languages section defines the languages supported by the printer and the magic numbers to search for to determine the language used in a print file. This section should define the languages that your printer supports. The syntax for a SectionEntry in the languages section is as follows:

Language EnterCommand LeaveCommand Offset MagicString

The Language is an arbitrary name used for the language. For example postscript and pcl are valid language names.

The EnterCommand is the printer control command to enter the language in question. This command should be complete. ie., the printer should expect a stream of code in the language specified immediately after the EnterCommand.

The LeaveCommand specifies a command to use when leaving the language. For example, PostScript expects a Control-D character after every PostScript file. This can be specified in the LeaveCommand.

The Offset specifies the byte to start searching for the MagicString. One (1) is the first byte in the file, not zero (0). The MagicString is an arbitrary string of characters that will uniquely determine the type of code in the print file. For example, PostScript code can be recognised by the magic string "%!" starting at byte one (1) of a print file.

A typical languages section that supports both PostScript and PCL for the PJL language would look like the following:

Section languages
    postscript	"@PJL ENTER LANGUAGE = POSTSCRIPT"    "%/3/"    1    "%%!"
    pcl		"@PJL ENTER LANGUAGE = PCL"	      ""        1    "%/27/E%/27/"

To Contents

5.1 Variables Section

The final, and most important section in the config file is the variables section. This section defines the available command line switches, their valid options, the default option and the printer command to set the variable. The syntax for SectionEntry in the variables section is as follows:

Switch Variable Options Default

The Switch defines the command line syntax for each switch. This must be a word preceeded by a hyphen (-) character. The Variable is the printer command used to set the variable. This must be a string of characters surrounded by double quotes ("). The Options is a comma separated list of valid options in the form of either a word, a number (optionally signed) or a numeric interval (in the form "lower-upper"). The Default option is the option that will be used if the user specifies the switch with no value.

Any number of variables may be specified. The Switch should not include the equals sign (=). This is added automatically by the hpmodeset utility when parsing the command line.

The following listing is a sample of a variables section:

Section variables		
    -autocont		"@PJL SET AUTOCONT ="		ON,OFF,on,off		OFF	
    -autoselect		"@PJL SET AUTOSELECT ="		ON,OFF,on,off		ON
							longedge,shortedge	LONGEDGE
    -clearablewarnings	"@PJL SET CLEARABLEWARNINGS ="	JOB,ON,job,on		ON
    -contextswitch	"@PJL SET CONTEXTSWITCH ="	ON,OFF,on,off		ON	
    -copies		"@PJL SET COPIES ="		1-999			1
    -cplock		"@PJL SET CPLOCK ="		OFF,ON,off,on		OFF
    -density		"@PJL SET DENSITY ="		1-5			3	

To Contents

5.2 Config Syntax

The syntax for a configuration file is described in the following concrete syntax. There are four basic terminal types: number, word, string and switch and interval. Each is defined as follows:

An optionally signed integer or real number. For example, 1, 1.0, -1 and -1.0 are valid numbers.
A word is a single token of characters starting with an letter (a-z or A-Z).
a word with a leading hyphen character (-).
two numbers separated by a hyphen character (-).
A string is an arbitrary number of characters surrounded by double quotes ("). Control characters and unprintable characters can be embeded within a string using the Eiffel syntax for special characters.
carriage return
horizontal tab
any character with its decimal ASCII code surrounded by slashes and with a leading percent sign. eg, '%/34/' is the double quote character. This is the only way to embed a double quote within a string. (This made the lexical analyser a little simpler!)
Hp_Config 		::= 	Section_list;
Section_list		::=	{Section [";"] ...};
Section			::=	"Section" Section_body "EndSection";
Section_body		::= 	Variables | Globals | Languages;

Variables 		::= 	"variables" Variable_list;
Variable_list		::= 	{Printer_variable [";"] ...};
Printer_variable	::= 	Switch_type Variable_syntax Options Default;	
Variable_syntax		::= 	String_type;
Options			::= 	{Setting "," ...};
Setting			::= 	Alpha_type | Numeric_type | String_type | Interval_type;
Default			::= 	Setting;

Globals			::=	"globals" Globals_list;
Globals_list		::= 	{Global [";"] ...};
Global			::= 	Alpha_type String_type;

Languages		::= 	Language_list;
Language_list		::=	{Language [";"] ...};
Language		::=	Alpha_type Language_command Numeric_type 
Language_command	::=	String_type;
Language_magic_string 	::= 	String_type;

Switch_type		::=	"'-' ('a'..'z') *(~('a'..'z') | '_' | ('0'..'9'))";
Alpha_type		::=	"~('a'..'z') *(~('a'..'z') | '_' | ('0'..'9'))";
Numeric_type		::=	"$Z";
Interval_type		::=	"$N '-' $N";
String_type		::=	"'%"' *($. - '%"') '%"'";

To Contents

5.3 Encapsulation Order

hpmodeset encapsulates files in the following order:

The job_header is output first: job_header end_of_command

Followed by each option specified on the command line: Variable white_space Option end_of_command.

Followed by the relevant language enter command determined by examining each print file: EnterCommand end_of_command

Followed by the raw print file stream.

This is repeated for each print file.

The complete job is then ended with: job_trailer end_of_command reset_command/

To Contents

6 Contributors

The Linux Community: The first version released to the public was version 1.2. It was released to the Linux community in binary form only. It was downloaded approximatelly 400 times in the first 3 days after release! Many new ideas and encouragement for a new release was received in the following weeks. This release is the result.

Eiffel: The Eiffel language made writing this utility easy.

To Contents

7 Where to find it?

Note (Jan Kučera). The informatin below is outdated.

Hpmodeset was written by Glenn Maughan". All bugs and suggestions should be sent to Glenn.

The latest version of hpmodeset is available via ftp at Also the html version of this documentation can be browsed at

To Contents

Odskok zpátky Odskok na hlavní stránku