X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=yarrg%2Fweb%2Fautohandler;h=8ff09966b953143dfd474a4a0d43c66913f47c38;hp=7344f076fb2c9d871d233a53b41d4669059285a5;hb=1f6f88af87868d6e059be154ed6b56dd9ea7ac6c;hpb=59bee7afb77216585b904bd20f17e71005e9778c diff --git a/yarrg/web/autohandler b/yarrg/web/autohandler index 7344f07..8ff0996 100644 --- a/yarrg/web/autohandler +++ b/yarrg/web/autohandler @@ -33,7 +33,54 @@ copyright message. - +<%perl> + +use CommodsWeb; + +my $printable= printable($m); +if ($printable =~ m/^pdf|^ps/) { + my $output; + my $got= $m->call_self(\$output); + if ($got) { + my @htargs= qw(htmldoc --continuous --gray --size 210x279mm + --left 1cm --right 1cm); + $printable =~ m/^[a-z]+/; + push @htargs, '-t',$&; + if ($printable =~ m/2$/) { + push @htargs, qw(--nup 2); + } + push @htargs, qw(-); + + my $tmpfile= IO::File::new_tmpfile(); + print $tmpfile $output or die $!; + $tmpfile->flush() or die $!; + seek $tmpfile,0,0 or die $!; + my $htmldoc= open HTMLDOC, "-|"; + defined $htmldoc or die $!; + if (!$htmldoc) { + eval { + $ENV{'HTMLDOC_NOCGI'}=1; + open STDIN, '<&', $tmpfile or die $!; + + exec @htargs; + die $!; + }; + print STDERR "HTMLDOC FAILURE $@"; + _exit(1); + } + my ($data,$read); + $r->content_type($printable eq 'pdf' ? 'application/pdf' : + 'application/postscript'); + while ($read= read HTMLDOC,$data,32768) { print $data; } + defined $read or die $!; + $?=0; $!=0; close HTMLDOC or die "$! $? $output "; + return; + } +} +set_ctype_utf8(); +$r->content_type('text/html; charset=UTF-8'); + + -% $m->call_next; - -<%init> -use CommodsWeb; -set_ctype_utf8(); -$r->content_type('text/html; charset=UTF-8'); - +% $m->call_next();