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}})
34 my $xo = $outpdf->importPageIntoForm($inpdf, $nr);
36 my ($llx, $lly, $urx, $ury);
37 $llx = $meta->{x} + $meta->{pageoffsets}->{$nr}->{x};
38 $lly = $meta->{y} + $meta->{pageoffsets}->{$nr}->{y};
39 $urx = $llx + $meta->{width};
40 $ury = $lly + $meta->{height};
41 $xo->bbox($llx, $lly, $urx, $ury);
43 my $xpos = ($column - 1) * $meta->{width};
44 my $ypos = $height - ($row * $meta->{height});
45 $content->formimage($xo, $xpos, $ypos);
48 if($column > $meta->{columns})
56 $outpdf->saveas(basename($metafile, ('.pdf.stitch','.stitch')) . '-stitched.pdf');