9 my $metafile = $ARGV[0];
11 die "Please specify a .pdf.stitch to process!\n" unless defined $metafile;
12 die "Can't open $metafile!\n" unless -r $metafile;
14 my $meta = YAML::LoadFile($metafile);
16 my $width = $meta->{width} * $meta->{columns};
17 my $height = $meta->{height} * $meta->{rows};
19 my $inpdf = PDF::API2->open($meta->{input});
20 my $outpdf = PDF::API2->new();
22 my $page = $outpdf->page();
24 $page->mediabox($width + 100, $height + 100);
26 my $content = $page->gfx();
30 foreach my $nr (@{$meta->{pageorder}})
32 my $xo = $outpdf->importPageIntoForm($inpdf, $nr);
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);
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);
46 if($column > $meta->{columns})
54 $outpdf->saveas(basename($meta->{input}, '.pdf') . '-stitched.pdf');