b8e73603ac88854a68232de54cb305942e8380f2
[Printer-EVOLIS.git] / inkscape-render.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5 use autodie;
6
7 my $card_svg = 'card/ffzg-2010.svg';
8
9 warn "# card template: $card_svg\n";
10
11 my ($nr,$ime,$prezime) = ( qw/
12 200900000042
13 Dobrica
14 Pavlinušić
15 / );
16
17 my $mapping = {
18 '200908109999' => $nr,
19 'Knjižničarko' => $ime,
20 'Čitalić' => $prezime,
21 };
22
23 sub mapping { $mapping->{ $_[0] } }
24
25 my $re = join('|', keys %$mapping);
26
27 mkdir 'out' unless -d 'out';
28 my $out = 'out/' . $nr;
29
30 foreach my $existing ( glob $out . '*' ) {
31         warn "# remove $existing ", -s $existing, " bytes\n";
32         unlink $existing;
33 }
34
35 open(my $svg_template, '<', $card_svg);
36 open(my $svg,          '>', "$out.svg");
37
38 while(<$svg_template>) {
39
40         if ( m{($re)} ) {
41                 warn "mapping $1\n";
42                 s{($1)}{mapping($1)}e;
43         }
44
45         print $svg $_;
46
47 }
48
49 close($svg_template);
50 close($svg);
51
52 open(my $inkscape, '|-', 'inkscape --shell --without-gui');
53
54 sub inkscape_export {
55         my $part = shift;
56
57         my $shell = "$out.svg --export-area-page --export-id $part";
58
59         print $inkscape "$shell --export-pdf $out.$part.pdf\n";
60         print $inkscape "$shell --export-png $out.$part.png --export-dpi 150\n";
61 }
62
63 inkscape_export 'print-front';
64 inkscape_export 'print-back';
65
66 # export visible
67 print $inkscape "$out.svg --export-png $out.png --export-dpi 300\n";
68
69 close($inkscape);
70
71 __END__
72
73 #system "inkscape --file $out.print.svg  --export-pdf $out.pdf";
74
75 system "inkscape --file $out.print.svg --export-area-page --export-pdf $out.print-front.pdf --export-id print-front";
76 system "inkscape --file $out.print.svg --export-area-page --export-pdf $out.print-back.pdf --export-id print-back";
77 system "pdftk  $out.print-front.pdf $out.print-back.pdf cat output $out.print-duplex.pdf";
78
79 #system "inkscape --file $out.screen.svg --export-png $out.png --export-dpi 180";
80
81 #system "inkscape --file $out.screen.svg --export-png $out.300.png --export-dpi 300";
82
83 system "inkscape --file $out.print.svg --export-area-page --export-png $out.print-front.png --export-dpi 150 --export-id print-front --export-id-only";
84 system "inkscape --file $out.print.svg --export-area-page --export-png $out.print-back.png --export-dpi 150 --export-id print-back --export-id-only";
85
86
87 #system "qiv $out.png";
88 #system "xpdf $out.pdf";