]> git.sur5r.net Git - pdfstitch/blob - pdfstitch
Allow "blank" in pageorder to insert blank page
[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     if($nr ne "blank")
33     {
34         my $xo = $outpdf->importPageIntoForm($inpdf, $nr);
35
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);
42
43         my $xpos = ($column - 1) * $meta->{width};
44         my $ypos = $height - ($row * $meta->{height});
45         $content->formimage($xo, $xpos, $ypos);
46     }
47     $column++;
48     if($column > $meta->{columns})
49     {
50         $row++;
51         $column=1;
52     }
53
54 }
55
56 $outpdf->saveas(basename($metafile, ('.pdf.stitch','.stitch')) . '-stitched.pdf');
57