#!/bin/bash # # Generates printer diagnostic files, so you can read a printer's real page # capacity straight off the paper instead of guessing from paper geometry. # # Usage: # ./pagetest.sh [width] [lines] - numbered lines padded with '#', to find # a printer's real lines-per-page (the # last line number printed on page 1) # (default width=64, lines=100) # ./pagetest.sh ruler [width] - a single long ruler line marking every # 10th column with its tens digit and # every 5th with '+', to find a # printer's real chars-per-line exactly # (default width=200) # # Print the result with PRINTER_A4=false in printer.conf (no rotation): # ./txt2printr.sh pagetest.txt dir="$(dirname "$0")" outfile="$dir/pagetest.txt" if [ "$1" = "ruler" ]; then width="${2:-200}" awk -v width="$width" ' BEGIN { line = "" for (i = 1; i <= width; i++) { if (i % 10 == 0) line = line (int(i / 10) % 10) else if (i % 5 == 0) line = line "+" else line = line "-" } print line } ' > "$outfile" echo "Wrote a $width-char ruler line to $outfile" echo "Every 10th column is marked with its tens digit (column 40 -> '4'," echo "column 100 -> '0'), every 5th with '+'. Read off the last marker" echo "that fully prints to get your printer's exact chars-per-line." else width="${1:-64}" lines="${2:-100}" awk -v width="$width" -v lines="$lines" ' BEGIN { for (i = 1; i <= lines; i++) { prefix = sprintf("%03d ", i) fill = width - length(prefix) if (fill < 0) fill = 0 line = prefix for (j = 0; j < fill; j++) line = line "#" print line } } ' > "$outfile" echo "Wrote $lines lines x $width chars to $outfile" fi echo "Print it with: PRINTER_DEV=/dev/lp0 \"$dir/txt2printr.sh\" \"$outfile\""