summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@chalmers.se>2011-05-12 18:43:34 +0200
committerGuilhem Moulin <guilhem.moulin@chalmers.se>2011-05-12 18:43:34 +0200
commitf812a0988f2136e5a6598c3825a4a396a4bf26c8 (patch)
tree0d4e316f4813afe04d5a1d1aa63cbfec2ec25ec9
parentafb0888a13da8a67e0c659130fe9c525105d96dc (diff)
manual, license
-rwxr-xr-xpdftool.pl112
1 files changed, 59 insertions, 53 deletions
diff --git a/pdftool.pl b/pdftool.pl
index 8320747..b374c45 100755
--- a/pdftool.pl
+++ b/pdftool.pl
@@ -1,5 +1,13 @@
#! /usr/bin/perl -w
+# This program is free software. It comes without any warranty, to the
+# extent permitted by applicable law. You can redistribute it and/or
+# modify it under the terms of the Do What The Fuck You Want To Public
+# License, Version 2, as published by Sam Hocevar.
+# See http://sam.zoy.org/wtfpl/COPYING for more details.
+
+
+$VERSION = "0.4, 12 May 2011";
use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat
bundling auto_version auto_help);
@@ -16,19 +24,19 @@ pdftool.pl - a PDF swiss army knife
=head1 SYNOPSIS
-B<pdftool.pl> [-s I<pages>] [-w I<width> ] [-h I<heigth>] [-p I<paper>]
-[-W I<width>] [-H I<heigth>] [-P I<paper>] [-p I<paper>] [-m I<margin>]
-[-b I<border>] [-c] [--book] [--column] [-n I<nup>] [-t] [-q]
-[I<infile> [I<outfile>]]
+B<pdftool.pl> [B<-w> I<width> ] [B<-h> I<heigth>] [B<-p> I<paper>]
+[B<-W> I<width>] [B<-H> I<heigth>] [B<-P> I<paper>] [B<-s> I<pages>]
+[B<-m> I<margin>] [B<-b> I<border>] [B<-c>] [B<--book>] [B<--column>]
+[B<-n> I<nup>] [B<--screen>] [B<-q>] [I<infile> [I<outfile>]]
=head1 DESCRIPTION
-I<PDFTool> combines the tools in the PSUtils bundle in a nice way. The
+B<PDFTool> combines the tools in the PSUtils bundle in a nice way. The
input should be either a Portable Document Format (PDF) file, or a
-PostScript file. The output format is the same as the input one.
+PostScript file. The output format is PDF only.
If no input file is given, or if a single hyphen-minus (B<->) is given as
-file name, I<PDFTool> will read the PDF or PostScript data from the standard
+file name, B<PDFTool> will read the PDF or PostScript data from the standard
input. In that case, and if the input data is in PDF format, an
auxiliary file will be created (since the conversion from PDF to PS
requires random access to the data), and removed afterwards. Also, if the crop
@@ -36,22 +44,26 @@ option (B<-c>) is set, an auxiliary file will be created, and removed
afterwards.
If no output file is given, or if a single hyphen-minus (B<->) is given as
-file name, I<PDFTool> will send the data (of the same type as the input) to
-the standard output.
+file name, B<PDFTool> will send the data to the standard output.
+
+By default, B<PDFTool> rotates the pages in order to ensure that your pdf will
+be printable using your favorite duplex mode for portrait documents (tumble if
+you prefer to turn the pages like those of a book). See the B<--screen>
+option to bypass this behavior.
The document will be treated as follows:
-=over 8
+=over 4
-=item Conversion from PDF to PostScript (if necessary),
+=item * Conversion from PDF to PostScript (if necessary),
-=item Selection of the page range,
+=item * Selection of the page range,
-=item Rearranging pages for printing books or booklets,
+=item * Rearranging pages for printing books or booklets,
-=item Putting multiple pages per sheets,
+=item * Putting multiple pages per sheets,
-=item Conversion from PS to PDF (if necessary).
+=item * Conversion back from PS to PDF.
=back
@@ -59,7 +71,7 @@ The document will be treated as follows:
=over 8
-=item B<-s, --select>
+=item B<-s, --select=>I<pages>
Specifies the pages which are to be selected.
I<Pages> is a comma separated list of page ranges, each of which
@@ -71,51 +83,51 @@ 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>
+=item B<-w, --width=>I<length>
Specify the width of the output file. If the height is not specified as
well, it will be ignored. The known units are B<pt>, B<in>, B<cm> and
B<mm>. The default unit is B<pt>.
-=item B<-h, --height>
+=item B<-h, --height=>I<length>
Specify the height of the output file. If the width is not specified as
well, it will be ignored. The known units are B<pt>, B<in>, B<cm> and
B<mm>. The default unit is B<pt>.
-=item B<-p, --paper>
+=item B<-p, --paper=>I<paper>
Specify the paper size of the output file, as an alternative to B<-w>
and B<-h>. Can be set to B<a0>, B<a1>, B<a2>, B<a3>, B<a4>, B<a5>, B<b5>,
B<letter>, B<legal>, B<ledger>, B<tabloid>, B<statement>, B<executive>,
B<folio>, B<quarto>, or B<10x14>. The default output paper size is B<a4>.
-=item B<-W, --Width>
+=item B<-W, --Width=>I<length>
Same as the option B<-w>, but for the input file. This option is useless if
the crop option (B<-c>) is set.
-=item B<-H, --Height>
+=item B<-H, --Height=>I<length>
Same as the option B<-h>, but for the input file. This option is useless if
the crop option (B<-c>) is set.
-=item B<-P, --Paper>
+=item B<-P, --Paper=>I<paper>
Same as the option B<-p>, but for the input file. By default,
-I<PDFTool> will try to guess this value from the header of the file,
+B<PDFTool> will try to guess this value from the header of the file,
and fail if the information is missing. This option is useless if the
crop option (B<-c>) is set.
-=item B<-b, --border>
+=item B<-b, --border=>I<length>
Add a margin around each logical page on a sheet. Possible units are B<pt>,
B<in>, B<cm> and B<mm>. The default unit is B<pt>. The default border is
B<1cm> if the crop option (B<-c>) is set, and B<0> otherwise.
-=item B<-m, --margin>
+=item B<-m, --margin=>I<length>
Add a margin around the whole page. Possible units are B<pt>, B<in>, B<cm>
and B<mm>. The default unit is B<pt>. The default margin is B<0>.
@@ -124,27 +136,27 @@ and B<mm>. The default unit is B<pt>. The default margin is B<0>.
If this option is set, the PostScript code will interpreted to calculate the
maximal effective bounding box. This operation may take time and be quite
-demanding for the CPU.
+demanding for the CPU. See the note for the border option (B<-b>) above.
=item B<--book>
Rearrange pages for printing books or booklets.
-=item B<-n, --nup>
+=item B<-n, --nup=>I<num>
Puts multiple logical pages onto each physical sheet of paper. The inner
margin might be same as the outer one (depending on the booklet option
B<-b>), see B<-m> for details.
-If I<nup> is less than 10, the option B<->I<nup> may be used as an
+If I<num> is less than 10, the option B<->I<nup> may be used as an
alternative.
-=item B<-t, --tumble>
+=item B<--screen>
-By default, B<PDFTool> ensures that your pdf will be printable using the
-DuplexNoTumble mode, hence even pages of landscape files are rotated by
-180°. This option removes this behavior; also, landscape files are rotated
-in order to make it easy to read on the computer.
+By default, B<PDFTool> ensures that your pdf will be printable using
+your "default" duplex mode (see B<DESCRIPTION>). B<--screen> tries to
+make the output PDF ready to read on your computer instead. It has no
+effect for portrait documents.
=item B<--column>
@@ -153,7 +165,7 @@ columns down the paper.
=item B<-q, --quiet>
-I<PDFTool> normally prints the page numbers of the pages output; this
+B<PDFTool> normally prints the page numbers of the pages output; this
option suppresses this.
=item B<--help>
@@ -162,7 +174,7 @@ Display a brief help.
=item B<--version>
-Display the version number of the I<PDFTool> program.
+Display the version number of the B<PDFTool> program.
=item B<--man>
@@ -175,26 +187,20 @@ Display the manual page.
The following comand can be used to remotely crop a PDF file, convert it
to A4 paper, and rearrange the pages to print a booklet:
-ssh remote pdftool.pl -cpA4 --book -2 -b2cm -m-1cm < in.pdf > out.pdf
+C<< ssh remote pdftool.pl -cpA4 --book -2 -b2cm -m-1cm < in.pdf | lpr >>
-=head1 REQUIRE
+=head1 REQUIREMENTS
Requires PSUtils installed and available in the command line
http://www.tardis.ed.ac.uk/~ajcd/psutils/.
=head1 AUTHOR
-Public domain, (c) Guilhem Moulin.
-
-=head1 VERSION
-
-Version: 0.3, 27 December 2010
+Copyright 2010-2011 Guilhem Moulin. See the source for copying
+conditions.
=cut
-# TODO: inline it in the header
-$main::VERSION = "0.3, 27 December 2010";
-
my $tmpdir = '/tmp';
@@ -212,8 +218,7 @@ my $nup = 1;
my $column;
my $quiet;
my $man;
-my $tumble;
-my $landscape;
+my $screen;
GetOptions( "select|s=s" => \$select,
"w|width=s" => \$outwidth,
@@ -227,7 +232,7 @@ GetOptions( "select|s=s" => \$select,
"crop|c" => \$crop,
"book" => \$book,
"nup|n=i" => \$nup,
- "t|tumble" => \$tumble,
+ "screen" => \$screen,
"1" => sub { $nup = 1 },
"2" => sub { $nup = 2 },
"3" => sub { $nup = 3 },
@@ -442,7 +447,7 @@ if (defined $crop) {
unless (seek IN, 0, 1) {
# The input is not seekable: have to create a seekable auxiliary file
- my $auxfile = "$tmpdir/psresize-stdin-$$.ps";
+ my $auxfile = "$tmpdir/pdftool-stdin-$$.ps";
open AUXFD, '>', "$auxfile"
or die "Can't write into `$auxfile': $!";
@@ -550,10 +555,11 @@ if (defined $book) {
#
# PSNup
#
+my $landscape;
if ((($bbox[2]-$bbox[0] > $bbox[3]-$bbox[1])
and not ($outwidth-2*$margin > $outheight-2*$margin))
or
- (defined $tumble
+ (defined $screen
and not ($bbox[2]-$bbox[0] > $bbox[3]-$bbox[1])
and ($outwidth-2*$margin > $outheight-2*$margin))) {
($outheight, $outwidth) = ($outwidth, $outheight);
@@ -571,7 +577,7 @@ my $land = ($outwidth > $outheight);
$land = not $land if ($rotate%2);
my $pagespecs;
-if (defined $tumble || not $land) {
+if (defined $screen || not $land) {
$pagespecs = "$nup:" . join ('+', @$ospecs);
} else {
$pagespecs = 2*$nup . ':' . join ('+', @$ospecs) . ',' . join ('+', @$especs);
@@ -588,8 +594,8 @@ push @pids, [$pid, @cmd];
# Final file: Convert back to PDF
#
my $pagedevice;
-if (defined $tumble || $land || $landscape) {
- $rotate = ($rotate+1)%4 if not (defined $tumble) and $land;
+if (defined $screen || $land || $landscape) {
+ $rotate = ($rotate+1)%4 if not (defined $screen) and $land;
$pagedevice = "/Orientation $rotate /PageSize [$outwidth $outheight]";
} else {
$pagedevice = "/PageSize [$outwidth $outheight]";