4.18. PostScript and the ifhp Filter

There are some printers that only support PostScript. We will show how to configure the ifhp filter to support these printers. Create the /tmp/one.ps PostScript file:

    %!PS-Adobe-3.0
    %% one page (i.e. - a page with a 1 on it)
    /Courier findfont 200 scalefont setfont
    72 300 moveto (1) show
    showpage


This PostScript file starts with the standard PostScript header - %! or the acceptable alternative \004%!. If a PostScript file does not start with either of these two character sequences the printer may behave in unexpected ways. The ifhp filter will check to make sure that the file starts with these sequences.

Modify the printcap as shown below and use lpc lpd to restart lpd.

    lp:sd=/var/spool/lpd/%P
      :force_localhost
      :lp=/tmp/lp
      # modify the path to ifhp appropriately
      :ifhp=model=ps
      :filter=/usr/local/libexec/filters/ifhp


Now print the file /tmp/one.ps, and then display the output in /tmp/lp using a text editor such as vi or emacs that displays control characters in a visible format:

    h4: {202} % cp /dev/null /tmp/lp
    h4: {203} % lpr /tmp/one.ps
    h4: {204} % vi /tmp/lp
    ^D%!
    %!PS-Adobe-3.0
    %% one page (i.e. - a page with a 1 on it)
    %%/Times-Roman
    /Courier
    findfont 200 scalefont setfont
    72 300 moveto
    (1) show
    showpage
    ^D


As you can see, the PostScript ˆD (Control-D or \004) End of Job characters have been prefixed and appended to the file. This will ensure that the job will be handled properly by the printer.