summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpdftool.pl60
1 files changed, 29 insertions, 31 deletions
diff --git a/pdftool.pl b/pdftool.pl
index 45fccaf..c578145 100755
--- a/pdftool.pl
+++ b/pdftool.pl
@@ -525,11 +525,10 @@ sub pdftops {
# Need to copy the whole input to an auxiliary file, since
# conversion from PDF to PS requires random access to the data
- $infile = catfile( tmpdir(), "pdftool-stdin-$$.". lc $filetype );
+ $infile = &mktemp( "pdftool-stdin-$$.". lc $filetype );
open my $AUX, '>', $infile
or die "Error: Cannot write into `" .$infile. "': $!\n";
- push @auxfiles, $infile;
# cat > $infile
while (<$READ>) {
@@ -623,11 +622,10 @@ sub psbbox {
# The input is not seekable: have to create a seekable auxiliary
# file
- my $auxfile = catfile( tmpdir(), "pdftool-in$config->{index}-$$.ps" );
+ my $auxfile = &mktemp( "pdftool-in$config->{index}-$$.ps" );
open my $AUX, '>', $auxfile
or die "Cannot write into `" .$auxfile. "': $!\n";
- push @auxfiles, $auxfile;
# cat > $auxfile
while (<$IN>) {
@@ -642,7 +640,8 @@ sub psbbox {
# Need to duplicate IN, since it will be closed in the parent process
open *IN, '<&=', $IN or die "Cannot fdopen: $!";
- my @cmd = (@gs, '-sDEVICE=bbox', '-dQUIET', '-dBATCH', '-dNOPAUSE', '-');
+ my @cmd = (@gs, '-sDEVICE=bbox', '-dQUIET', '-dBATCH', '-dNOPAUSE',
+ '-f', '-');
my $pid = open3 '<&IN', '>&OUT', *OUT, @cmd;
my ($p,$c) = (0,0); # Page & character counter
@@ -888,33 +887,23 @@ sub psnup {
# Final file: setup the correct orientation/page size
#
sub write {
- my ($landscape, $rotate, @ins) = @_;
- my $IN;
-
- my @args;
- my $index = 1;
- if ($#ins > 0) {
- # We have to create temporary files for every PostScript file
- foreach my $FIN (@ins) {
- my $auxfile = catfile( tmpdir(),
- "pdftool-gsin$index-$$.ps" );
+ my ($landscape, $rotate, @FINS) = @_;
+
+ my @args = ('-f', '-');
+ my $IN = $FINS[0];
+
+ for (my $index=2; $index<=1+$#FINS; $index++) {
+ # We have to create temporary files for every PostScript file
+ my $auxfile = &mktemp( "pdftool-gsin$index-$$.ps" );
+ push @args, '-f', $auxfile;
- open my $AUX, '>', $auxfile
- or die "Error: Cannot write into `" .$auxfile. "': $!\n";
- push @auxfiles, $auxfile;
- while (<$FIN>) {
- print $AUX ($_) or die "Cannot print: $!";
- }
- push @args, '-f', $auxfile;
- close $FIN or die "Cannot close: $!";
- $index++;
- }
- open $IN, '<', File::Spec->devnull() or
- die "Cannot open the null device: $!"
- }
- else {
- @args = ('-f', '-');
- $IN = $ins[0];
+ open my $AUX, '>', $auxfile
+ or die "Error: Cannot write into `" .$auxfile. "': $!\n";
+ my $FIN = $FINS[$index-1]; # Bug: can't <$FINS[$index-1]>
+ while (<$FIN>) {
+ print $AUX ($_) or die "Cannot print: $!";
+ }
+ close $FIN or die "Cannot close: $!";
}
my ($ow, $oh) = ($out{width}, $out{height});
@@ -1051,3 +1040,12 @@ sub min {
return $m;
}
+
+#
+# Make a temporary file, and remove it afterwards
+#
+sub mktemp {
+ my $auxfile = catfile( tmpdir(), $_[0] );
+ push @auxfiles, $auxfile;
+ return $auxfile;
+}