X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fweb%2Fautohandler;h=55b9a93695552295b4899d5a52fd0fd5ca4f3651;hp=7344f076fb2c9d871d233a53b41d4669059285a5;hb=f7c3c04f684b0e9cac4518beeece11853ef75109;hpb=3766fb8d851fe463a5b8b469cf148c28efb1c578 diff --git a/yarrg/web/autohandler b/yarrg/web/autohandler index 7344f07..55b9a93 100644 --- a/yarrg/web/autohandler +++ b/yarrg/web/autohandler @@ -33,7 +33,45 @@ copyright message. - +<%perl> + +use CommodsWeb; + +my $printable= printable($m); +if ($printable eq 'pdf' || $printable eq 'ps') { + my $output; + my $got= $m->call_self(\$output); + if ($got) { + 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 qw(htmldoc -t),$printable,qw( + --continuous --gray --size 210x279mm -); + 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();