--- old/lib/TWiki/Contrib/GenPDF.pm 2007-03-21 11:46:12.000000000 -0400 +++ new/lib/TWiki/Contrib/GenPDF.pm 2007-08-09 10:25:21.885811100 -0400 @@ -50,7 +50,7 @@ use CGI; use TWiki::Func; use TWiki::UI::View; -use File::Temp; +use File::Temp qw( tempfile ); use Error qw( :try ); use vars qw( $VERSION $RELEASE ); @@ -252,12 +252,13 @@ $text =~ s/ 'GenPDFAddOnXXXXXXXXXX', - DIR => File::Spec->tmpdir(), - SUFFIX => '.html'); + my ($fh, $name) = tempfile('GenPDFAddOnXXXXXXXXXX', + DIR => File::Spec->tmpdir(), + SUFFIX => '.html'); + open $fh, ">$name"; print $fh $text; - - return $fh; + close $fh; + return $name; } @@ -387,33 +388,31 @@ # HTMLDOC location # $TWiki::htmldocCmd must be set in TWiki.cfg - use constant { - BANNER => "", - TITLE => "", - SUBTITLE => "", - HEADERTOPIC => "", - TITLETOPIC => "", - SKIN => "print.pattern", - RECURSIVE => undef, - FORMAT => "pdf14", - TOCLEVELS => 5, - PAGESIZE => "a4", - ORIENTATION => "portrait", - WIDTH => 860, - HEADERSHIFT => 0, - KEYWORDS => '%FORMFIELD{"KeyWords"}%', - SUBJECT => '%FORMFIELD{"TopicHeadline"}%', - TOCHEADER => "...", - TOCFOOTER => "..i", - HEADFOOTFONT => "", - BODYIMAGE => "", - LOGOIMAGE => "", - NUMBEREDTOC => undef, - DUPLEX => undef, - PERMISSIONS => undef, - MARGINS => undef, - BODYCOLOR => undef, - }; + use constant BANNER => ""; + use constant TITLE => ""; + use constant SUBTITLE => ""; + use constant HEADERTOPIC => ""; + use constant TITLETOPIC => ""; + use constant SKIN => "print.pattern"; + use constant RECURSIVE => undef; + use constant FORMAT => "pdf14"; + use constant TOCLEVELS => 5; + use constant PAGESIZE => "a4"; + use constant ORIENTATION => "portrait"; + use constant WIDTH => 860; + use constant HEADERSHIFT => 0; + use constant KEYWORDS => '%FORMFIELD{"KeyWords"}%'; + use constant SUBJECT => '%FORMFIELD{"TopicHeadline"}%'; + use constant TOCHEADER => "..."; + use constant TOCFOOTER => "..i"; + use constant HEADFOOTFONT => ""; + use constant BODYIMAGE => ""; + use constant LOGOIMAGE => ""; + use constant NUMBEREDTOC => undef; + use constant DUPLEX => undef; + use constant PERMISSIONS => undef; + use constant MARGINS => undef; + use constant BODYCOLOR => undef; # header/footer topic $prefs{'hftopic'} = $query->param('pdfheadertopic') || TWiki::Func::getPreferencesValue("GENPDFADDON_HEADERTOPIC") || HEADERTOPIC; @@ -628,11 +627,13 @@ $htmlData =~ s|.*( 'GenPDFAddOnXXXXXXXXXX', - DIR => File::Spec->tmpdir(), - #UNLINK => 0, # DEBUG - SUFFIX => '.html'); - print $contentFile $hfData . $htmlData; + my ($cfh, $contentFile) = tempfile('GenPDFAddOnXXXXXXXXXX', + DIR => File::Spec->tmpdir(), + #UNLINK => 0, # DEBUG + SUFFIX => '.html'); + open $cfh, ">$contentFile"; + print $cfh $hfData . $htmlData; + close $cfh; push @contentFiles, $contentFile; } @@ -640,11 +641,10 @@ my $titleFile = _createTitleFile($webName); # Create a temp file for output - my $outputFile = new File::Temp(TEMPLATE => 'GenPDFAddOnXXXXXXXXXX', - DIR => File::Spec->tmpdir(), - #UNLINK => 0, # DEBUG - SUFFIX => '.pdf'); - + my ($ofh, $outputFile) = tempfile('GenPDFAddOnXXXXXXXXXX', + DIR => File::Spec->tmpdir(), + #UNLINK => 0, # DEBUG + SUFFIX => '.pdf'); # Convert contentFile to PDF using HTMLDOC my @htmldocArgs; push @htmldocArgs, "--book", @@ -682,7 +682,7 @@ push @htmldocArgs, @contentFiles; - print STDERR "Calling htmldoc with args: @htmldocArgs\n"; +# print STDERR "Calling htmldoc with args: @htmldocArgs\n"; # Disable CGI feature of newer versions of htmldoc # (thanks to Brent Roberts for this fix) @@ -717,11 +717,15 @@ } } catch Error::Simple with { }; - - while(<$outputFile>){ + open $ofh, $outputFile; + while(<$ofh>){ print; } - close $outputFile; + close $ofh; + + # Cleaning up temporary files + unlink $outputFile, $titleFile; + unlink @contentFiles; } 1;