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