]> git.sur5r.net Git - pdfstitch/blob - pdfstitch
Inital commit
[pdfstitch] / pdfstitch
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use File::Basename;
6 use PDF::API2;
7 use YAML;
8
9 my $metafile = $ARGV[0];
10
11 die "Please specify a .pdf.stitch to process!\n" unless defined $metafile;
12 die "Can't open $metafile!\n" unless -r $metafile;
13
14 my $meta = YAML::LoadFile($metafile);
15
16 my $width = $meta->{width} * $meta->{columns};
17 my $height = $meta->{height} * $meta->{rows};
18
19 my $inpdf = PDF::API2->open($meta->{input});
20 my $outpdf = PDF::API2->new();
21
22 my $page = $outpdf->page();
23
24 $page->mediabox($width + 100, $height + 100);
25
26 my $content = $page->gfx();
27 my $column = 1;
28 my $row = 1;
29
30 foreach my $nr (@{$meta->{pageorder}})
31 {
32     my $xo = $outpdf->importPageIntoForm($inpdf, $nr);
33
34     my ($llx, $lly, $urx, $ury);
35     $llx = $meta->{x} + $meta->{pageoffsets}->{$nr}->{x};
36     $lly = $meta->{y} + $meta->{pageoffsets}->{$nr}->{y};
37     $urx = $llx + $meta->{width};
38     $ury = $lly + $meta->{height};
39     $xo->bbox($llx, $lly, $urx, $ury);
40
41     my $xpos = ($column - 1) * $meta->{width};
42     my $ypos = $height - ($row * $meta->{height});
43     print "Stitching page $nr at $xpos,$ypos...\n";
44     $content->formimage($xo, $xpos, $ypos);
45     $column++;
46     if($column > $meta->{columns})
47     {
48         $row++;
49         $column=1;
50     }
51
52 }
53
54 $outpdf->saveas(basename($meta->{input}, '.pdf') . '-stitched.pdf');
55