From 81bea0d2669c26e3d449e6bd682a40c3b282fc89 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sun, 15 May 2011 04:35:57 +0200 Subject: reintroducing the _ caracter --- pdftool.pl | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'pdftool.pl') diff --git a/pdftool.pl b/pdftool.pl index ed6b887..3cd37c8 100755 --- a/pdftool.pl +++ b/pdftool.pl @@ -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-I. If I is omitted, the first page is assumed, and if I 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 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; -- cgit v1.2.3