diff options
author | Guilhem Moulin <guilhem.moulin@chalmers.se> | 2011-05-15 04:35:57 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem.moulin@chalmers.se> | 2011-05-15 04:35:57 +0200 |
commit | 81bea0d2669c26e3d449e6bd682a40c3b282fc89 (patch) | |
tree | 1561634f2a70f3c39a744315ddcd62b659fb7cd5 | |
parent | 6612d5beec5300d2c9ea807dfb156e8722ca0df2 (diff) |
reintroducing the _ caracter
-rwxr-xr-x | pdftool.pl | 29 |
1 files changed, 19 insertions, 10 deletions
@@ -55,8 +55,10 @@ The document will be treated as follows: =over 4 -=item * Convert from PDF to PostScript (if necessary, and only for -smallest interval that contains all the selected pages), +=item * Convert from PDF to PostScript (if necessary, and if possible - +that is if all page numbers are relative to the begining of the +document -, convert only the smallest interval that contains all the selected +pages), =item * Select the page range, @@ -82,6 +84,10 @@ may be a page number, or a page range of the form I<first>-I<last>. If I<first> is omitted, the first page is assumed, and if I<last> is omitted, the last page is assumed. +The prefix character `_' indicates that the page number is relative +to the end of the document, counting backwards. If just this +character with no page number is used, a blank page will be inserted. + =item B<-w, --width=>I<length> Specify the width of the output file. If the height is not specified as @@ -287,9 +293,9 @@ die "Margins are too big" if $outwidth <= $margin*2 or $outheight <= $margin*2; # Check options # die "Bad page range: `$select'" if - defined $select && not $select =~ /^(\s*\d*-?\d*\s*,)*\s*\d*-?\d*\s*$/; -for (split /\s*,\s*/, $select) { - $_ =~ /^(\d*)\s*-?\s*(\d*)$/; + defined $select && not $select =~ /^(_?\d*-?_?\d*,)*_?\d*-?_?\d*$/; +for (split /,/, $select) { + $_ =~ /^_?(\d*)-?_?(\d*)$/; die "Bad page range: `$select'" if ($1 ne "" && $1 <= 0) or ($2 ne "" && $2 <=0); } @@ -395,11 +401,14 @@ if ($filetype eq "PDF") { } my ($first, $last); - if (defined $select) { + # pdftops doesn't provide any way to have page numbers relative to + # the end of the document, hence there is no detection of the + # smallest interval if $select contains `_' + if (defined $select && not $select =~ /_/) { # Convert to PS only the pages we are interested in ($first, $last) = (1<<16,-(1<<16)); - for (split /\s*,\s*/, $select) { - $_ =~ /^(\d*)\s*(-?)\s*(\d*)$/; + for (split /,/, $select) { + $_ =~ /^(\d*)(-?)(\d*)$/; my ($rmin,$sep,$rmax) = ($1,$2,$3); undef $first if $sep && not $rmin; undef $last if $sep && not $rmax; @@ -415,8 +424,8 @@ if ($filetype eq "PDF") { # Calculate the new page range my @newselect; - for (split /\s*,\s*/, $select) { - $_ =~ /^(\d*)\s*(-?)\s*(\d*)$/; + for (split /,/, $select) { + $_ =~ /^(\d*)(-?)(\d*)$/; my ($rmin,$sep,$rmax) = ($1,$2,$3); if (defined $first) { $rmin -= $first-1 if $rmin; |