asa2pdf -- line printer emulation

(convert files with ASA carriage control to an Adobe PDF file)

Traditionally, FORTRAN programs place carriage-control characters in the first column of their output, which then need interpreted by printers or programs according to the ASA vertical format control standard in order to display properly. (ASA was the American Standards Association -- now ANSI.)

Once common, direct operating-system support of ASA files is now rare, although VMS still supports ASA files.

Character Meaning
+ Do not advance; overstrike previous line.
blank Advance one line.
null lines Treated as if they started with a blank
0 Advance two lines.
- Advance three lines (IBM extension).
1 Advance to top of next page.
all others Discarded

The program asa2pdf.c(1) formats the output of a file that uses ASA carriage control characters and converts the file to an Adobe PDF file. That is, it emulates a line impact printer but the output is an Adobe PDF file instead of a printed page.

To properly view the PDF output requires a PDF processor such as xpdf,acroread/AcroRd32,gv or ghostview.

The PDF is clear-text ASCII so that it is easy to use other Unix/Linux utilities such as spell, diff, grep, .... on the processed output files. It is trivial to change this simple program to use dashed lines instead of shading, allow alternate margins and pages per line and so on. If you need that much variety I suggest you look for the utilities asa(1)/nasa(1), enscript(1), a2ps(1), and ps2pdf(1).

Note that old standards like the Unix command pr(1) can be used with asa2pdf(1) to add page numbers and titles. expand(1) can remove tab characters; fold(1) and fmt(1) can be used to wrap the text, cut(1) can let you trim or select columns; cat -n can be used to number lines; paste(1) can be used to put files side-by-side.

Versions that can include background forms and graphics metafiles ( simple xfig(1) or plot(1) drawing files, for example) and other options (simulating Xerox DJDE commands, color) are feasible.

Details are available using the -h (help) switch on the asa2pdf(1) command:


  asa2pdf -h  # The help switch
   +------------------------------------------------------------------------------+
   |NAME:                                                                         |
   |asa2pdf: A filter to convert text files with ASA carriage control to a PDF.   |
   +------------------------------------------------------------------------------+
   |SYNOPSIS:                                                                     |
   |   asa2pdf(1) reads input from standard input. The first character            |
   |   of each line is interpreted as a control character. Lines beginning with   |
   |   any character other than those listed in the ASA carriage-control          |
   |   characters table are interpreted as if they began with a blank,            |
   |   and an appropriate diagnostic appears on standard error. The first         |
   |   character of each line is not printed.                                     |
   |     +------------+-----------------------------------------------+           |
   |     | Character  |                                               |           |
   |     +------------+-----------------------------------------------+           |
   |     | +          | Do not advance; overstrike previous line.     |           |
   |     | blank      | Advance one line.                             |           |
   |     | null lines | Treated as if they started with a blank       |           |
   |     | 0          | Advance two lines.                            |           |
   |     | -          | Advance three lines (IBM extension).          |           |
   |     | 1          | Advance to top of next page.                  |           |
   |     | all others | Discarded (except for extensions listed below)|           |
   |     +------------+-----------------------------------------------+           |
   | Extensions                                                                   |
   |    H  Advance one-half line.                                                 |
   |    R  Do not advance; overstrike previous line. Use red text color           |
   |    G  Do not advance; overstrike previous line. Use green text color         |
   |    B  Do not advance; overstrike previous line. Use blue text color          |
   |    r  Advance one line. Use red text color                                   |
   |    g  Advance one line. Use green text color                                 |
   |    b  Advance one line. Use blue text color                                  |
   |    ^  Overprint but add 127 to the ADE value of the character                |
   |       (ie., use ASCII extended character set)                                |
   +------------------------------------------------------------------------------+
   |PRINTABLE PAGE AREA                                                           |
   !  The page size may be specified using -H for height, -W for width, and -u    |
   !  to indicate the points per unit (72 makes H and W in inches,                |
   !  1 is used when units are in font points). For example:                      |
   |    -u 72 -H 8.5 -W 11   # page Height and Width in inches                    |
   |    -u 72 -B 0.5 -L 0.5 -R 0.5 -T 0.5 # margins (Top, Bottom, Left, Right)    |
   |  common media sizes with -u 1:                                               |
   |    +-------------------+------+------------+                                 |
   |    | name              |  W   |        H   |                                 |
   |    +-------------------+------+------------+                                 |
   |    | Letterdj (11x8.5) | 792  |       612  | (LandScape)                     |
   |    | A4dj              | 842  |       595  |                                 |
   |    | Letter (8.5x11)   | 612  |       792  | (Portrait)                      |
   |    | Legal             | 612  |       1008 |                                 |
   |    | A5                | 420  |       595  |                                 |
   |    | A4                | 595  |       842  |                                 |
   |    | A3                | 842  |       1190 |                                 |
   |    +-------------------+------+------------+                                 |
   +------------------------------------------------------------------------------+
   |SHADING                                                                       |
   |    -g 0.800781     # gray-scale value  for shaded bars ( 0 < g 1 )           |
   |                    # 0 is black, 1 is white.                                 |
   |    -i 2            # repeat shade pattern every N lines                      |
   |    -d ' '          # dashcode pattern (seems buggy)                          |
   +------------------------------------------------------------------------------+
   |MARGIN LABELS                                                                 |
   |    -n -c -s ''     # margin label string. -n is short for -s NOFORN,         |
   |                    # -c is short for -s CLASSIFIED. The default is no        |
   |                    # label unless the environmental variable CLASS is set    |
   |                    # to 'C' or 'c'; which is the same as if -c is present.   |
   +------------------------------------------------------------------------------+
   |TEXT OPTIONS                                                                  |
   |   -l 60            # lines per page                                          |
   |   -f Courier       # font names: Courier, Courier-Bold,Courier-Oblique       |
   |                      Helvetica, Symbol, Times-Bold, Helvetica-Bold,          |
   |                      ZapfDingbats, Times-Italic, Helvetica-Oblique,          |
   |                      Times-BoldItalic, Helvetica-BoldOblique,                |
   |                      Times-Roman, Courier-BoldOblique                        |
   +------------------------------------------------------------------------------+
   |   -S 0             # right shift 1 for non-ASA files                         |
   |   -N               # add line numbers                                        |
   +------------------------------------------------------------------------------+
   |   -v 2             # version number                                          |
   |   -h               # display this help                                       |
   +------------------------------------------------------------------------------+
   |ENVIRONMENTAL VARIABLES:                                                      |
   | $IMPACT_TOP Will be printed in large red letters across the page top.        |
   | $IMPACT_GRAY sets the default gray-scale value, same as the -g switch.       |
   +------------------------------------------------------------------------------+
   |EXAMPLES:                                                                     |
   !-----------------                                                             |
   | # create non-ASA file in portrait mode with a dashed line under every line   |
   | asa2pdf -S 1 -W 8.5 -H 11 -i 1 -d '2 4 1' -T 1 -B .75 < INFILE > junko.pdf   |
   !-----------------                                                             |
   | # banner on top                                                              |
   | env IMPACT_GRAY=1 IMPACT_TOP=CONFIDENTIAL asa2pdf < test.txt > test.pdf      |
   !-----------------                                                             |
   | # 132 landscape                                                              |
   |  asa2pdf -s LANDSCAPE <asa2pdf.c >junko.A.pdf                                |
   !-----------------                                                             |
   | # 132 landscape with line numbers with dashed lines                          |
   |  asa2pdf -s 'LANDSCAPE LINE NUMBERS' -d '3 1 2' \                            |
   |  -N -T .9 <asa2pdf.c >test.pdf                                               |
   !-----------------                                                             |
   | # portrait 80 non-ASA file with dashed lines                                 |
   |  asa2pdf -s PORTRAIT -S 1 -W 8.5 -H 11 -i 1 -d '2 4 1' \                     |
   |  -T 1 -B .75 < asa2pdf.c > test.pdf                                          |
   !-----------------                                                             |
   | # portrait 80 with line numbers , non-ASA                                    |
   |  asa2pdf -s 'PORTRAIT LINE NUMBERS' -l 66 -S 1 -W 8.5 -H 11 \                |
   |  -i 1 -T 1 -B .75 -N < asa2pdf.c > test.pdf                                  |
   !-----------------                                                             |
   | # titling                                                                    |
   |  asa2pdf -d '1 0 1' -t "$USER" -i 1 -c -P -N -T 1 \                          |
   |  -s "asa2pdf.c" <asa2pdf.c >test.pdf                                         |
   +------------------------------------------------------------------------------+