Index: view =================================================================== RCS file: /var/cvs/twiki/bin/view,v retrieving revision 1.1.1.1 diff -c -r1.1.1.1 view *** view 19 Jun 2002 13:53:38 -0000 1.1.1.1 --- view 11 Jul 2002 23:30:13 -0000 *************** *** 71,76 **** --- 71,79 ---- my $wikiUserName = &TWiki::userToWikiName( $userName ); my $revdate = ""; my $revuser = ""; + my $pdftitle = ""; + my $pdfcall = ""; + my $viewPdf = $query->param( "pdf" ) || ""; my $viewRaw = $query->param( "raw" ) || ""; my $unlock = $query->param( "unlock" ) || ""; my $skin = $query->param( "skin" ) || &TWiki::Prefs::getPreferencesValue( "SKIN" ); *************** *** 87,92 **** --- 90,99 ---- . "\n"; return; } + if ( $viewPdf ) { + $pdftitle = &TWiki::Store::readTemplate( "pdftitle", $skin ); + $pdfcall = &TWiki::Store::readTemplate( "pdfcall", $skin ); + } writeDebugTimes( "view - readTemplate" ); if( ! &TWiki::Store::webExists( $webName ) ) { *************** *** 258,265 **** --- 265,274 ---- $revuser = &TWiki::userToWikiName( $revuser ); my $temp = &TWiki::getRenderedVersion( "r1.$rev - $revdate GMT - $revuser" ); $tmpl =~ s/%REVINFO%/$temp$mirrorNote/go; + $pdftitle =~ s/%REVINFO%/$temp$mirrorNote/go if ( $viewPdf ); } else { $tmpl =~ s/%REVINFO%/$mirrorNote/go; + $pdftitle =~ s/%REVINFO%/$mirrorNote/go if ( $viewPdf ); } $tmpl = &TWiki::handleCommonTags( $tmpl, $topic ); *************** *** 281,286 **** --- 290,321 ---- my $contentType = $query->param( "contenttype" ); if( $contentType ) { print "Content-type: $contentType\n\n"; + } elsif ( $viewPdf ) { + + # Put title page in tmp. + $pdftitle = &TWiki::handleCommonTags( $pdftitle, $topic ); + my $titlefile = "/tmp/twiki2pdf.title.$$.htm"; + open TITLE, ">$titlefile" or die "open $titlefile: $!"; + print TITLE "$pdftitle" or die "print $titlefile: $!"; + close TITLE or die "close $titlefile: $!"; + + # Put actual text into tmp. + my $bodyfile = "/tmp/twiki2pdf.body.$$.htm"; + open BODY, ">$bodyfile" or die "open $bodyfile: $!"; + print BODY "$tmpl" or die "print $bodyfile: $!"; + close BODY or die "close $bodyfile: $!"; + + # Put together the call. + $pdfcall =~ s/%PDFBODY%/$bodyfile/go; + $pdfcall =~ s/%PDFTITLE%/$titlefile/go; + $| = 1; # Make sure header gets written before system output! + print "Content-type: application/pdf\n\n"; + $| = 0; + $ENV{"PATH"} = ""; + $pdfcall =~ m|^(/[^`]*)|; + system("$1") or writeDebugTimes( "pdf - error: $!" ); + unlink $bodyfile, $titlefile; + exit 0; } else { TWiki::writeHeader( $query ); }