| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | # written by Marco Pessotto | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | # use FindBin; | ||
| 8 | # use lib "$FindBin::Bin/../lib"; | ||
| 9 | use PDF::Imposition; | ||
| 10 | use Getopt::Long; | ||
| 11 | use Pod::Usage; | ||
| 12 | |||
| 13 | my ($signature, $help, $suffix, $cover, $title, $paper, $paper_thickness, $version, | ||
| 14 | $font_size, $cropmark_length, $cropmark_offset); | ||
| 15 | |||
| 16 | my $schema = '2up'; | ||
| 17 | |||
| 18 | my $opts = GetOptions ( | ||
| 19 | 'signature|sig|s=s' => \$signature, | ||
| 20 | 'help|h' => \$help, | ||
| 21 | 'suffix=s' => \$suffix, | ||
| 22 | 'cover' => \$cover, | ||
| 23 | 'schema=s' => \$schema, | ||
| 24 | 'title=s' => \$title, | ||
| 25 | 'paper=s' => \$paper, | ||
| 26 | 'paper-thickness=s' => \$paper_thickness, | ||
| 27 | 'font-size=s' => \$font_size, | ||
| 28 | 'cropmark-length=s' => \$cropmark_length, | ||
| 29 | 'cropmark-offset=s' => \$cropmark_offset, | ||
| 30 | version => \$version, | ||
| 31 | ) or die; | ||
| 32 | my ($file, $outfile) = @ARGV; | ||
| 33 | |||
| 34 | if ($help) { | ||
| 35 | pod2usage("Using PDF::Imposition version " . | ||
| 36 | $PDF::Imposition::VERSION . "\n"); | ||
| 37 | exit 2; | ||
| 38 | } | ||
| 39 | |||
| 40 | if ($version) { | ||
| 41 | print PDF::Imposition->version . "\n"; | ||
| 42 | exit; | ||
| 43 | } | ||
| 44 | |||
| 45 | die "Missing input" unless $file; | ||
| 46 | die "$file is not a file" unless -f $file; | ||
| 47 | |||
| 48 | my %args = ( | ||
| 49 | file => $file, | ||
| 50 | schema => $schema, | ||
| 51 | ); | ||
| 52 | |||
| 53 | if ($outfile) { | ||
| 54 | $args{outfile} = $outfile; | ||
| 55 | } | ||
| 56 | elsif ($suffix) { | ||
| 57 | unless ($suffix =~ m/\A-/) { | ||
| 58 | $suffix = '-' . $suffix; | ||
| 59 | } | ||
| 60 | $args{suffix} = $suffix; | ||
| 61 | } | ||
| 62 | if (defined $signature) { | ||
| 63 | $args{signature} = $signature; | ||
| 64 | } | ||
| 65 | if ($cover) { | ||
| 66 | $args{cover} = 1; | ||
| 67 | } | ||
| 68 | if ($paper) { | ||
| 69 | $args{paper} = $paper; | ||
| 70 | } | ||
| 71 | if ($paper_thickness) { | ||
| 72 | $args{paper_thickness} = $paper_thickness; | ||
| 73 | } | ||
| 74 | if ($title) { | ||
| 75 | $args{title} = $title; | ||
| 76 | } | ||
| 77 | if ($font_size) { | ||
| 78 | $args{font_size} = $font_size; | ||
| 79 | } | ||
| 80 | if ($cropmark_length) { | ||
| 81 | $args{cropmark_length} = $cropmark_length; | ||
| 82 | } | ||
| 83 | if ($cropmark_offset) { | ||
| 84 | $args{cropmark_offset} = $cropmark_offset; | ||
| 85 | } | ||
| 86 | print "Using PDF::Imposition " . PDF::Imposition->version . "\n"; | ||
| 87 | my $imposer = PDF::Imposition->new(%args); | ||
| 88 | my $out = $imposer->impose; | ||
| 89 | |||
| 90 | # and that's all | ||
| 91 | print "Imposed PDF left in $out\n"; | ||
| 92 | |||
| 93 | =head1 NAME | ||
| 94 | |||
| 95 | pdf-impose.pl -- script to impose a PDF using the L<PDF::Imposition> class. | ||
| 96 | |||
| 97 | =head1 SYNOPSIS | ||
| 98 | |||
| 99 | pdf-impose.pl infile.pdf [outfile.pdf] | ||
| 100 | |||
| 101 | This script is a simple wrapper around L<PDF::Imposition>. Refer to | ||
| 102 | the perldoc documentation (C<perldoc PDF::Imposition>) for details | ||
| 103 | about the options. | ||
| 104 | |||
| 105 | =head2 Options: | ||
| 106 | |||
| 107 | =over 4 | ||
| 108 | |||
| 109 | =item --schema | ||
| 110 | |||
| 111 | Available schemas: C<2up> C<duplex2up> C<2down> C<2x4x2> C<2x4x1> C<2side> | ||
| 112 | C<1x4x2cutfoldbind> C<4up> C<1repeat2top> C<1repeat2side> C<1repeat4> | ||
| 113 | C<ae4x4> C<1x8x2> | ||
| 114 | |||
| 115 | The schema to use: defaults to C<2up>. See C<perldoc PDF::Imposition> | ||
| 116 | for details about the available schemas. | ||
| 117 | |||
| 118 | =item --cover | ||
| 119 | |||
| 120 | Boolean: if the schema supports it, put the last page of the PDF on | ||
| 121 | the last page of the last signature if there is a need of blank page | ||
| 122 | padding, so when folding the first page and the last page will match. | ||
| 123 | |||
| 124 | For example, for a 2up schema, if you have 6 pages, you will get a | ||
| 125 | signature of 8 pages, with 2 blank pages at the end. With this option | ||
| 126 | you get the two blank pages before the last one, which in turn will be | ||
| 127 | put in the same physical page of the first one. | ||
| 128 | |||
| 129 | =item --signature | --sig | -s <num> | ||
| 130 | |||
| 131 | <num> must be a multiple of 4 or a range like, e.g. 40-80 | ||
| 132 | |||
| 133 | =item --suffix <string> | ||
| 134 | |||
| 135 | defaults to 'imp'. The dash is automatically added, to avoid | ||
| 136 | confusing it with options. If you want more control, pass the | ||
| 137 | desired output file as second argument to the script. | ||
| 138 | |||
| 139 | =item --paper <size> | ||
| 140 | |||
| 141 | You can specify the dimension providing a (case insensitive) string | ||
| 142 | with the paper name (2a, 2b, 36x36, 4a, 4b, a0, a1, a2, a3, a4, a5, | ||
| 143 | a6, b0, b1, b2, b3, b4, b5, b6, broadsheet, executive, ledger, legal, | ||
| 144 | letter, tabloid) or a string with width and height separated by a | ||
| 145 | column, like C<11cm:200mm>. Supported units are mm, in, pt and cm. | ||
| 146 | |||
| 147 | =item --paper-thickness | ||
| 148 | |||
| 149 | Accept a measure, e.g. C<0.15mm>. | ||
| 150 | |||
| 151 | This option is needed only for schemas which support cutting | ||
| 152 | correction. Default to C<0.1mm>, which should be appropriate for the | ||
| 153 | common paper 80g/m2. You can do the math measuring a stack height and | ||
| 154 | dividing by the number of sheets. | ||
| 155 | |||
| 156 | =item --font-size 8pt | ||
| 157 | |||
| 158 | The font size of the headers and footers with the job name, date, and | ||
| 159 | page numbers. Defaults to 8pt. | ||
| 160 | |||
| 161 | =item --cropmark-offset 1mm | ||
| 162 | |||
| 163 | The distance from the logical page corner and the cropmark line. | ||
| 164 | Defaults to 1mm. | ||
| 165 | |||
| 166 | =item --cropmark-length 12mm | ||
| 167 | |||
| 168 | Size of the cropmark lines. Defaults to 12mm. | ||
| 169 | |||
| 170 | =item title | ||
| 171 | |||
| 172 | Set the PDF Title metadata | ||
| 173 | |||
| 174 | =item --help | ||
| 175 | |||
| 176 | Show this help and exit | ||
| 177 | |||
| 178 | =item --version | ||
| 179 | |||
| 180 | Show the PDF::Imposition version | ||
| 181 | |||
| 182 | =back | ||
| 183 | |||
| 184 | If outfile is not provided, it will use the suffix to create the | ||
| 185 | output filename. | ||
| 186 | |||
| 187 | =head1 LICENSE | ||
| 188 | |||
| 189 | This program is free software; you can redistribute it and/or modify | ||
| 190 | it under the terms of either: the GNU General Public License as | ||
| 191 | published by the Free Software Foundation; or the Artistic License. | ||
| 192 | |||
| 193 | =cut | ||
| 194 |