#!/usr/bin/perl -w # Converts text into two-column landscape PDF, where the first column is in # "bkoo" format, and the second column is the original text. # # Requires enscript and ps2pdf. # # I suggest trying this with texts from http://www.gutenberg.org. # # For more about "bkoo", see http://bkoo.org. use strict; sub print_pages { my ($lines_ref, $fh, $num_lines) = @_; foreach (@$lines_ref) { print $fh join "", map { (join "", sort { lc $a cmp lc $b } split //, substr $_, 0, -1) . (substr $_, -1, 1) } split /(?<=\W)/, $_; } print $fh "\n" x ($num_lines - @$lines_ref); foreach (@$lines_ref) { print $fh $_; } } my $lines_per_page = 66; my @orig_lines; open my $pipe, "|enscript -B -L $lines_per_page -r -2 -o - |ps2pdf - -" or die "can't open enscript + ps2pdf pipe"; while (<>) { push @orig_lines, $_; if ($. % $lines_per_page == 0) { print_pages \@orig_lines, $pipe, $lines_per_page; @orig_lines = (); } } print_pages \@orig_lines, $pipe, $lines_per_page if @orig_lines; close $pipe;