chiark / gitweb /
printable trading plans
[ypp-sc-tools.db-live.git] / yarrg / web / autohandler
index 7344f07..55b9a93 100644 (file)
  copyright message.
 
 
-</%doc><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+</%doc><%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');
+
+</%perl><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <!--
     This HTML is generated by the YARRG website, which is
     <& copyrightdate &>.
     covered by the AGPL.
 -->
 
-% $m->call_next;
-
-<%init>
-use CommodsWeb;
-set_ctype_utf8();
-$r->content_type('text/html; charset=UTF-8');
-</%init>
+% $m->call_next();