6 use Data::Dump qw(dump);
9 my ( $svg_template, $csv_file ) = @ARGV;
11 die "usage: $0 template.svg data.csv\n" unless -r $svg_template && -r $csv_file;
16 open(my $fh, '<:encoding(utf8)', $svg_template);
23 my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute.
24 or die "Cannot use CSV: ".Text::CSV->error_diag ();
28 open(my $inkscape, '|-', 'inkscape --shell --without-gui');
30 open my $fh, "<:encoding(utf8)", $csv_file or die "$csv_file: $!";
31 while ( my $row = $csv->getline( $fh ) ) {
32 if ( ! $vars ) { # header row
34 $vars->{ '%VAR_' . $_ . '%' } = $col++ foreach @$row;
35 warn "variables ",dump $vars;
39 foreach my $pattern ( keys %$vars ) {
40 $new_svg =~ s/\Q$pattern\E/$row->[$vars->{$pattern}]/sgx ||
41 warn "didn't find $pattern in $svg_template";
43 my $tmp_path = sprintf "/tmp/%s-%04d", $svg_template, $nr++;
44 open(my $fh, '>', "$tmp_path.svg");
48 print $inkscape "$tmp_path.svg --export-area-page --export-pdf $tmp_path.pdf\n";
50 warn "# $_ ", -s $_, " bytes\n" foreach glob "$tmp_path.*";
53 $csv->eof or $csv->error_diag();
58 warn "generated $nr files in /tmp/$svg_template-*.pdf\n";
60 my $print_pdf = 'nup.pdf';
62 system "pdfnup --suffix nup --nup '2x5' --paper a4paper --no-landscape --scale 1.0 --frame true --noautoscale true --outfile $print_pdf -- /tmp/$svg_template-*.pdf";
64 warn "PRINT file: $print_pdf ", -s $print_pdf, " bytes\n";