#!/usr/bin/perl -wT use strict; use diagnostics; use CGI ':standard'; use CGI::Carp 'fatalsToBrowser'; $CGI::POST_MAX = 100_000_000; # 100 megabytes $ENV{PATH} = '/bin:/usr/bin:/home/ed/bin'; my $VIEW = 'Convert to PDF'; my $SAVE = "$VIEW for saving"; if (not param()) { print header(-expires => 'now'), start_html('Text to PDF converter'), h1('Text to PDF converter'), p("This is a simple converter from plain text to PDF. It " . "doesn't do any formatting, simply producing monospaced text " . "in the output PDF."), p("Enter the filename of a plain text file and press 'Convert to PDF'."), start_multipart_form(), 'Text filename: ', filefield(-name => 'uploaded_file', -size => 50, -maxlength => 80 ), submit('submit', $VIEW), p(< 'http://www.iki.fi/~mtr/genscript/' }, 'Enscript') . ' and ' . CGI::a({ href => 'http://www.ghostscript.com/' }, 'GhostScript') . '.'), address(CGI::a({ href => 'mailto:ed@membled.com' }, 'Edward Avis')), end_html(); } else { my $f = param('uploaded_file'); # both filename and filehandle my $which = param('submit'); my $type; if ($which eq $VIEW) { $type = 'application/pdf' } elsif ($which eq $SAVE) { $type = 'application/octet-stream' } else { die 'neither button pressed' } print header(-type => $type, -expires => 'now'); open(TO_PDF, "| txt2ps | pip -io ps2pdf -.ps -.pdf") or die "cannot run txt2ps and pip ps2pdf: $!"; while (<$f>) { print TO_PDF $_ or die "cannot pipe to txt2ps: $!"; } close TO_PDF or die "error closing pipe to txt2ps: $!"; }