support login
[Printer-EVOLIS.git] / scripts / inkscape-render.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5 use autodie;
6
7 die "unsage: $0 card/template.svg 201008159999 login Ime Prezime\n" unless @ARGV;
8
9 my ($card_svg,$nr,$login,$ime,$prezime) = @ARGV;
10
11 warn "# svg: $card_svg nr: $nr $ime $prezime\n";
12
13 my $mapping = {
14 '200908109999' => $nr,
15 'login123@ffzg.hr' => $login,
16 'Knjižničarko' => $ime,
17 'Čitalić' => $prezime,
18 };
19
20 sub mapping { $mapping->{ $_[0] } }
21
22 my $re = join('|', keys %$mapping);
23
24 mkdir 'out' unless -d 'out';
25 my $out = 'out/' . $nr;
26
27 foreach my $existing ( glob $out . '*' ) {
28         warn "# remove $existing ", -s $existing, " bytes\n";
29         unlink $existing;
30 }
31
32 open(my $svg_template, '<', $card_svg);
33 open(my $svg,          '>', "$out.svg");
34
35 while(<$svg_template>) {
36
37         if ( m{($re)} ) {
38                 warn "mapping $1\n";
39                 s{($1)}{mapping($1)}ge;
40         }
41
42         print $svg $_;
43
44 }
45
46 close($svg_template);
47 close($svg);
48
49 open(my $inkscape, '|-', 'inkscape --shell --without-gui');
50
51 sub inkscape_export {
52         my $part = shift;
53
54         my $shell = "$out.svg --export-area-page --export-id $part";
55
56         $part =~ s/print-//; # FIXME change svg files
57
58         print $inkscape "$shell --export-pdf $out.$part.pdf\n";
59         print $inkscape "$shell --export-png $out.$part.png --export-dpi 150\n";
60 }
61
62 inkscape_export 'print-front';
63 inkscape_export 'print-back';
64
65 # export visible
66 print $inkscape "$out.svg --export-png $out.png --export-dpi 300\n";
67
68 close($inkscape);
69
70 foreach my $pdf ( glob "$out*.pdf" ) {
71         my $pbm = $pdf;
72         $pbm =~ s/pdf$/pbm/;
73         warn "# rendering $pdf => $pbm using ghostscript\n";
74         system "gs -dNOPAUSE -dBATCH -q -r300x300 -dDEVICEWIDTHPOINTS=243 -dDEVICEHEIGHTPOINTS=155 -sDEVICE=pbmraw -sOutputFile=$pbm -f $pdf";
75 }
76
77 system "pdftk $out.front.pdf $out.back.pdf cat output $out.duplex.pdf";
78
79 __END__
80
81 #system "inkscape --file $out.print.svg  --export-pdf $out.pdf";
82
83 system "inkscape --file $out.print.svg --export-area-page --export-pdf $out.print-front.pdf --export-id print-front";
84 system "inkscape --file $out.print.svg --export-area-page --export-pdf $out.print-back.pdf --export-id print-back";
85 system "pdftk  $out.print-front.pdf $out.print-back.pdf cat output $out.print-duplex.pdf";
86
87 #system "inkscape --file $out.screen.svg --export-png $out.png --export-dpi 180";
88
89 #system "inkscape --file $out.screen.svg --export-png $out.300.png --export-dpi 300";
90
91 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";
92 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";
93
94
95 #system "qiv $out.png";
96 #system "xpdf $out.pdf";