fix rendering size
[Printer-EVOLIS.git] / scripts / inkscape-render.pl
index 36be513..3745678 100755 (executable)
@@ -4,14 +4,17 @@ use warnings;
 use strict;
 use autodie;
 
-die "unsage: $0 card/template.svg 201008159999 Ime Prezime\n" unless @ARGV;
+die "unsage: $0 card/template.svg 201008159999 login Ime Prezime\n" unless @ARGV;
 
-my ($card_svg,$nr,$ime,$prezime) = @ARGV;
+my ($card_svg,$nr,$login,$ime,$prezime) = @ARGV;
+
+my $png = $ENV{PNG} || 0;
 
 warn "# svg: $card_svg nr: $nr $ime $prezime\n";
 
 my $mapping = {
 '200908109999' => $nr,
+'login0123456789@ffzg.hr' => $login,
 'Knjižničarko' => $ime,
 'Čitalić' => $prezime,
 };
@@ -35,7 +38,7 @@ while(<$svg_template>) {
 
        if ( m{($re)} ) {
                warn "mapping $1\n";
-               s{($1)}{mapping($1)}e;
+               s{($1)}{mapping($1)}ge;
        }
 
        print $svg $_;
@@ -52,15 +55,17 @@ sub inkscape_export {
 
        my $shell = "$out.svg --export-area-page --export-id $part";
 
+       $part =~ s/print-//; # FIXME change svg files
+
        print $inkscape "$shell --export-pdf $out.$part.pdf\n";
-       print $inkscape "$shell --export-png $out.$part.png --export-dpi 150\n";
+       print $inkscape "$shell --export-png $out.$part.png --export-dpi 150\n" if $png;
 }
 
 inkscape_export 'print-front';
 inkscape_export 'print-back';
 
 # export visible
-print $inkscape "$out.svg --export-png $out.png --export-dpi 300\n";
+print $inkscape "$out.svg --export-png $out.png --export-dpi 300\n" if $png;
 
 close($inkscape);
 
@@ -68,10 +73,10 @@ foreach my $pdf ( glob "$out*.pdf" ) {
        my $pbm = $pdf;
        $pbm =~ s/pdf$/pbm/;
        warn "# rendering $pdf => $pbm using ghostscript\n";
-       system "gs -dNOPAUSE -dBATCH -q -r300x300 -dDEVICEWIDTHPOINTS=243 -dDEVICEHEIGHTPOINTS=155 -sDEVICE=pbmraw -sOutputFile=$pbm -f $pdf";
+       system "gs -dNOPAUSE -dBATCH -q -r300x300 -dDEVICEWIDTHPOINTS=243 -dDEVICEHEIGHTPOINTS=155 -dPDFFitPage -sDEVICE=pbmraw -sOutputFile=$pbm -f $pdf";
 }
 
-system "pdftk $out.print-front.pdf $out.print-back.pdf cat output $out.print-duplex.pdf";
+system "pdftk $out.front.pdf $out.back.pdf cat output $out.duplex.pdf" if $ENV{DUPLEX};
 
 __END__