]> git.sur5r.net Git - pdfstitch/blob - genmeta
Inital commit
[pdfstitch] / genmeta
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use PDF::API2;
6 use YAML;
7
8 my $infile = $ARGV[0];
9
10 die "Please specify PDF to examine!\n" unless defined $infile;
11 die "Could not open $infile!\n" unless -r $infile;
12
13 my $outfile = "${infile}.stitch";
14
15 die "$outfile exists, aborting!\n" if -e $outfile;
16
17 print 'Creating metafile for '.$infile."...\n";
18
19 my $pdf = PDF::API2->open($infile);
20
21 my $page = $pdf->openpage(1);
22 my ($llx, $lly, $urx, $ury) = $page->get_mediabox;
23
24 my $meta = {
25     input => $infile,
26     x => (($urx - $llx)*0.1)/2,
27     y => (($ury - $lly)*0.1)/2,
28     width => ($urx - $llx)*0.9,
29     height => ($ury - $lly)*0.9,
30     columns => int(sqrt($pdf->pages)),
31     rows => int(sqrt($pdf->pages)),
32     pageorder => [(1 .. $pdf->pages)],
33 };
34
35 foreach $page (1..$pdf->pages)
36 {
37     $meta->{pageoffsets}->{$page}->{x} = 0;
38     $meta->{pageoffsets}->{$page}->{y} = 0;
39 }
40
41 YAML::Bless($meta)->keys(['input','x','y','width','height','columns','rows', 'pageorder','pageoffsets']);
42 YAML::DumpFile($outfile,$meta);
43