Skip to content

Commit

Permalink
New parameter --defaultcrop to define genmeta crop factor
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Hagen authored and sur5r committed Aug 8, 2017
1 parent 3adb6b5 commit 674ff5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ On FreeBSD, you can install them with:

1. Run `pdfstitch` on your input PDF:

`./pdfstitch [--genmeta] foobar.pdf`
`./pdfstitch [--genmeta] [--defaultcrop=0.9] foobar.pdf`

This will generate a YAML file called `foobar.pdf.stitch`. Edit this file according to the desired output.
This is also the default action if called with a PDF.
This is also the default action if called with a PDF. Per default 10% (factor 0.9) is applied as crop factor.
You can adjust this value with the --defaultcrop parameter.
2. Optional: Generate a preview and/or cropped PDF:

`./pdfstitch --preview foobar.pdf.stitch`
Expand Down
33 changes: 19 additions & 14 deletions pdfstitch
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ my $genmeta = '';
my $preview = '';
my $crop = '';
my $stitch = '';
my $defaultcrop = '0.9';

Getopt::Long::Configure("bundling");


my $usage = <<ENDUSAGE;
pdfstitch - Copyright (C) 2017 by Jakob Haufe <sur5r\@sur5r.net>
Usage: $0 [-hgpcs] [--genmeta] [--preview] [--crop] [--stitch] {PDF file|.stitch file}
Usage: $0 [-hgpcs] [--genmeta] [--defaultcrop=<factor>] [--preview] [--crop] [--stitch] {PDF file|.stitch file}
-h, --help Display this message
-g, --genmeta Generate .stitch file for stitching based on given PDF
(default when called with a PDF)
-p, --preview Generate preview PDF containing overlays to analyze
cropping
-c, --crop Generate cropped PDF according to given .stitch
-s, --stitch Generate stitched PDF
(default when called with a .stitch file)
-h, --help Display this message
-g, --genmeta Generate .stitch file for stitching based on given PDF
(default when called with a PDF)
-d, --defaultcrop=0.9 Set default crop factor for genmeta (defaults to 0.9)
-p, --preview Generate preview PDF containing overlays to analyze
cropping
-c, --crop Generate cropped PDF according to given .stitch
-s, --stitch Generate stitched PDF
(default when called with a .stitch file)
pdfstitch is free software under the GNU AGPL version 3. See LICENSE for details.
ENDUSAGE
Expand All @@ -41,14 +43,17 @@ GetOptions
(
'h|help' => \$help,
'g|genmeta' => \$genmeta,
'd|defaultcrop=s' => \$defaultcrop,
'p|preview' => \$preview,
'c|crop' => \$crop,
's|stitch' => \$stitch
) or die "Call with --help to see available options.\n";

die $usage if $help;

die "--genmeta can not be combined with other actions!\n" if($genmeta and ($preview or $crop or $stitch));
die "--genmeta can only be combined with --defaultcrop!\n" if($genmeta and ($preview or $crop or $stitch));

die "--defaultcrop can only be combined with --genmeta!\n" if($defaultcrop and ($preview or $crop or $stitch));

die "No input file specified!\n" unless $ARGV[0];

Expand Down Expand Up @@ -103,10 +108,10 @@ if($genmeta)

my $meta = {
input => basename($infile),
x => (($urx - $llx)*0.1)/2,
y => (($ury - $lly)*0.1)/2,
width => ($urx - $llx)*0.9,
height => ($ury - $lly)*0.9,
x => (($urx - $llx)*(1-$defaultcrop))/2,
y => (($ury - $lly)*(1-$defaultcrop))/2,
width => ($urx - $llx)*$defaultcrop,
height => ($ury - $lly)*$defaultcrop,
columns => int(sqrt($pdf->pages)),
rows => int(sqrt($pdf->pages)),
pageorder => [(1 .. $pdf->pages)],
Expand Down

0 comments on commit 674ff5d

Please sign in to comment.