4

I have a working bash script which converts text files to postscript using enscript 1.6.5.90-2 on Kubuntu 14.04.

It does several other things to make the output look better like setting margins, wrapping lines, etc. (which is why I need enscript instead of other simpler printing tools.)

The script currently prints a title in the page header, but now I need a footer too.

Can anybody show me a current working example using enscript to produce footer lines?

I see --footer=FOOTER in the man page, but I also see that the default footer height is zero points. I have tried a number of ways to get footers to print. None of them produce any error messages, but they don't print footers either.

I don't have room for everything I want to see in the header alone so I need to put some of it in the footer.

0

1 Answer 1

3

I believe that, if you want footers, you have to write a custom hdr file and then select it with the --fancy-header option. I have written one (below) that may work for you.

There is a nine-year-old bug report on this problem. The approach in that bug report attempts a more comprehensive solution and requires re-compiling enscript. My approach is not as comprehensive but eliminates the need for a re-compile.

This header file is based on simple.hdr. To use it, copy and paste it into a file called, say, simple2.hdr, and, for system-wide use, place it in the directory /usr/share/enscript. For personal use, it can be placed in the ~/.enscript/ directory:

% -- code follows this line --
%Format: fmodstr    $D{%a %b %d %H:%M:%S %Y}
%Format: pagenumstr $V$%

%HeaderHeight: 38
%FooterHeight: 15

/do_header {   % print default simple header

  % Footer
  gsave
    d_footer_x d_footer_y HFpt_h 3 div add translate
    HF setfont

    user_footer_p {
      d_footer_x  d_footer_y moveto user_footer_left_str show

      d_footer_w user_footer_center_str stringwidth pop sub 2 div
      0 moveto user_footer_center_str show

      d_footer_x d_footer_w add user_footer_right_str stringwidth pop sub
      d_footer_y moveto user_footer_right_str show
    } if
  grestore

  % Header
  gsave
    d_header_x d_header_y HFpt_h 3 div add translate
    HF setfont

    user_header_p {
      5 0 moveto user_header_left_str show

      d_header_w user_header_center_str stringwidth pop sub 2 div
      0 moveto user_header_center_str show

      d_header_w user_header_right_str stringwidth pop sub 5 sub
      0 moveto user_header_right_str show
    } {
      5 0 moveto fname show
      45 0 rmoveto fmodstr show
      45 0 rmoveto pagenumstr show
    } ifelse
  grestore

} def

Usage is quite simple. You can then invoke it with something like:

enscript --fancy-header=simple2 --header="HEADER" --footer="LEFT|CTR|RIGHT"

Note that, although enscript supports many character sets, it does not support UTF-8. Files that are not in a natively supported character set can be filtered through iconv first before passing them to enscript.

4
  • +1 for finding a report that old! I guess enscript isn't used much any more or someone would have fixed something as basic as this. I'll study the report and your code a bit before accepting your answer. Unfortunately, my script is part of a project, so I won't be able to ask other users to implement a patch like this as well.
    – Joe
    Nov 3, 2014 at 9:49
  • @Joe The bug report was going for a more comprehensive solution. By contrast, my .hdr file was aimed simply at allowing one to print footers without any of the other changes suggested by the bug report. No re-compile necessary. If the other users cannot modify /usr/share/enscript, it is also possible to install the simple2.hdr file in `~/.enscript/'.
    – John1024
    Nov 3, 2014 at 19:13
  • As for enscript being little used, that happened after CUPS chose a different text-to-ps converter. I find, with one exception, that enscript is far more feature-full than what CUPS uses. The exception is that enscript does not support UTF8. In such cases, filter the text through iconv before passing it to enscript.
    – John1024
    Nov 3, 2014 at 19:31
  • Thanks for the great information. It wasn't clear to me that your solution works without the patch. I use .enscriptrc. I didn't notice that .enscript is also available for the use you suggest. The enscript man page lists all those variables, but I didn't make the connection that you had to use them in custom header files.
    – Joe
    Nov 3, 2014 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.