diff options
author | Karl Berry <karl@freefriends.org> | 2012-02-04 00:52:08 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-02-04 00:52:08 +0000 |
commit | 6520e34c1a3077670ffdee218186448cfa45a839 (patch) | |
tree | 683e99c1ccea5d100c7ccb786e8c93069610b502 /Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl | |
parent | 5167c138dddec7ef4eb62ec2b81e4511ea7d6e39 (diff) |
pdfcrop 1.33 (1feb12)
git-svn-id: svn://tug.org/texlive/trunk@25282 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl')
-rwxr-xr-x | Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl | 92 |
1 files changed, 62 insertions, 30 deletions
diff --git a/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl b/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl index 2be3fda5a0a..e4f2ca181ed 100755 --- a/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl +++ b/Master/texmf-dist/scripts/pdfcrop/pdfcrop.pl @@ -4,7 +4,7 @@ $^W=1; # turn warning on # # pdfcrop.pl # -# Copyright (C) 2002, 2004, 2005, 2008-2011 Heiko Oberdiek. +# Copyright (C) 2002, 2004, 2005, 2008-2012 Heiko Oberdiek. # # This program may be distributed and/or modified under the # conditions of the LaTeX Project Public License, either version 1.2 @@ -21,10 +21,10 @@ $^W=1; # turn warning on # my $file = "pdfcrop.pl"; my $program = uc($&) if $file =~ /^\w+/; -my $version = "1.32"; -my $date = "2011/08/10"; +my $version = "1.33"; +my $date = "2012/02/01"; my $author = "Heiko Oberdiek"; -my $copyright = "Copyright (c) 2002-2011 by $author."; +my $copyright = "Copyright (c) 2002-2012 by $author."; # # Reqirements: Perl5, Ghostscript # History: @@ -96,6 +96,7 @@ my $copyright = "Copyright (c) 2002-2011 by $author."; # command line, switch then to symbol link/copy # method. # 2011/08/10 v1.32: * Detection for gswin64c.exe added. +# 2012/02/01 v1.33: * Input file can be `-' (standard input). ### program identification my $title = "$program $version, $date - $copyright\n"; @@ -368,6 +369,8 @@ Expert options: An empty value or `none' uses the default of the TeX engine. ($::opt_pdfversion) +Input file: If the name is `-', then the standard input is used and + the output file name must be explicitly given. Examples: \L$program\E --margins 10 input.pdf output.pdf \L$program\E --margins '5 10 5 20' --clip input.pdf output.pdf @@ -477,34 +480,21 @@ if ($::opt_bbox_even) { ### input file $inputfile = shift @ARGV; -if (! -f $inputfile) { - if (-f "$inputfile.pdf") { - $inputfile .= ".pdf"; - } - else { - die "$Error Input file `$inputfile' not found!\n"; - } +if ($inputfile eq '-') { + @ARGV == 1 or die "$Error Missing output file name!\n"; + print "* Input file: <stdin>\n" if $::opt_debug; } - -print "* Input file: $inputfile\n" if $::opt_debug; - -if ($::opt_pdfversion eq 'auto') { - open(IN, '<', $inputfile) or die "!!! Error: Cannot open `$inputfile'!\n"; - my $buf; - read(IN, $buf, 1024) or die "!!! Error: Cannot read the header of `$inputfile' failed!\n"; - close(IN); - if ($buf =~ /%PDF-1.([0-7])\s/) { - $::opt_pdfversion = $1; - print "* PDF header: %PDF-1.$::opt_pdfversion\n" if $::opt_verbose; - $::opt_pdfversion = 2 if $::opt_pdfversion < 2; - } - else { - die "!!! Error: Cannot find PDF header of `$inputfile'!\n"; +else { + if (! -f $inputfile) { + if (-f "$inputfile.pdf") { + $inputfile .= ".pdf"; + } + else { + die "$Error Input file `$inputfile' not found!\n"; + } } + print "* Input file: $inputfile\n" if $::opt_debug; } -print '* Using PDF minor version: ', - ($::opt_pdfversion ? $::opt_pdfversion : "engine's default"), - "\n" if $::opt_debug; ### output file if (@ARGV) { @@ -630,7 +620,31 @@ $SIG{'__DIE__'} = \&clean; # use safe file name for use within cmd line of gs (unknown shell: space, ...) # and XeTeX (hash, curly braces, ...) my $inputfilesafe = $inputfile; -if (not $inputfile =~ /^[\w\d\.\-\:\/@]+$/) { # /[\s\$~'"#{}%]/ +if ($inputfile eq '-') { + $inputfilesafe = "$tmp-stdin.pdf"; + print "* Temporary input file: $inputfilesafe\n" if $::opt_debug; + push @unlink_files, $inputfilesafe; + open(OUT, '>', $inputfilesafe) or die "$Error Cannot write `$inputfilesafe'!\n"; + binmode(OUT); + my $size = 0; + my $len = 0; + my $buf = ''; + my $buf_size = 65536; + do { + $len = read STDIN, $buf, $buf_size; + if (not defined $len) { + my $msg = $!; + chomp $msg; + die "$Error Reading standard input ($msg)!\n"; + } + print OUT $buf or die "$Error Writing `$inputfilesafe'!\n"; + $size += $len; + } + while ($len); + close(OUT); + print "* File size (STDIN): $size\n" if $::opt_debug; +} +elsif (not $inputfile =~ /^[\w\d\.\-\:\/@]+$/) { # /[\s\$~'"#{}%]/ $inputfilesafe = "$tmp-img.pdf"; push @unlink_files, $inputfilesafe; my $symlink_exists = eval { symlink("", ""); 1 }; @@ -651,6 +665,24 @@ if (not $inputfile =~ /^[\w\d\.\-\:\/@]+$/) { # /[\s\$~'"#{}%]/ } } +if ($::opt_pdfversion eq 'auto') { + open(IN, '<', $inputfilesafe) or die "!!! Error: Cannot open `$inputfilesafe'!\n"; + my $buf; + read(IN, $buf, 1024) or die "!!! Error: Cannot read the header of `$inputfilesafe' failed!\n"; + close(IN); + if ($buf =~ /%PDF-1.([0-7])\s/) { + $::opt_pdfversion = $1; + print "* PDF header: %PDF-1.$::opt_pdfversion\n" if $::opt_verbose; + $::opt_pdfversion = 2 if $::opt_pdfversion < 2; + } + else { + die "!!! Error: Cannot find PDF header of `$inputfilesafe'!\n"; + } +} +print '* Using PDF minor version: ', + ($::opt_pdfversion ? $::opt_pdfversion : "engine's default"), + "\n" if $::opt_debug; + my @gsargs = ( "-sDEVICE=bbox", "-dBATCH", |