convert cups raster to evolis using cups driver
[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 foreach my $pdf ( glob "$out*.pdf" ) {
72         my $pbm = $pdf;
73         $pbm =~ s/pdf$/pbm/;
74         warn "# rendering $pdf => $pbm using ghostscript\n";
75         system "gs -dNOPAUSE -dBATCH -q -r300x300 -dDEVICEWIDTHPOINTS=243 -dDEVICEHEIGHTPOINTS=155 -sDEVICE=pbmraw -sOutputFile=$pbm -f $pdf";
76 }
77
78 system "pdftk $out.print-front.pdf $out.print-back.pdf cat output $out.print-duplex.pdf";
79
80 __END__
81
82 #system "inkscape --file $out.print.svg  --export-pdf $out.pdf";
83
84 system "inkscape --file $out.print.svg --export-area-page --export-pdf $out.print-front.pdf --export-id print-front";
85 system "inkscape --file $out.print.svg --export-area-page --export-pdf $out.print-back.pdf --export-id print-back";
86 system "pdftk  $out.print-front.pdf $out.print-back.pdf cat output $out.print-duplex.pdf";
87
88 #system "inkscape --file $out.screen.svg --export-png $out.png --export-dpi 180";
89
90 #system "inkscape --file $out.screen.svg --export-png $out.300.png --export-dpi 300";
91
92 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";
93 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";
94
95
96 #system "qiv $out.png";
97 #system "xpdf $out.pdf";