1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
#!/usr/bin/perl
# Use -w for extra help
use strict;
use warnings;
use PDF::API2;
#Load the DBI database interface
use DBI;
use DBD::mysql;
#
use File::Path;
# CONFIG VARIABLES
use constant mm => 25.4 / 72;
use constant in => 1 / 72;
use constant pt => 1;
use constant pageX => 210;
use constant pageY => 297;
use constant nomtempPNG => "temp.png";
use constant nomtempJPG => "temp.jpg";
use constant nomDossier => "temp";
my @tableauNomJPG;
my $i = 0;
my @tableauNomPNG;
my $j = 0;
my $databaseISBN = "ISBN";
my $databaseIMG = "filmessai";
my $host = "192.168.10.88";
my $port = "3306";
my $user = "root2";
my $pw = "xxxxxxx";
my $pdf = PDF::API2->new( -file => "$0.pdf" );
my $page = $pdf->page;
$page->mediabox( pageX / mm, pageY / mm );
#$page->bleedbox( 5/mm, 5/mm, 100/mm, 143/mm);
$page->cropbox( 7.5 / mm, 7.5 / mm, 202.5/ mm, 289.5 / mm );
#$page->artbox ( 10/mm, 10/mm, 95/mm, 138/mm);
#(
#(297-(4*60))/3=19
use constant sep => 19;
use constant rext => 60;
use constant rint => 20;
use constant posCerX => 105;
use constant posCerYBas => sep+rext;
use constant posCerYHaut => posCerYBas+rext+sep+rext;
use constant Xdelta => 45;
use constant posX => 45;
use constant Ydelta => 19;
use constant posYbas => 19;
use constant posYhaut => posYbas+(2*rext)+Ydelta;
#isbn
#use constant isbn_x => posX+73.6;
use constant isbn_x => posX+76.6;
use constant isbn_bas => posYbas+22;
use constant isbn_haut => posYhaut+22;
#img01
use constant img01_x => posX+47.5;
use constant img01_bas => posYbas+5;
use constant img01_haut => posYhaut+5;
#img02
use constant img02_x => posX+21.4;
use constant img02_bas => posYbas+14.5;
use constant img02_haut => posYhaut+14.5;
#img03
use constant img03_x => posX+7.5;
use constant img03_bas => posYbas+45;
use constant img03_haut => posYhaut+45;
#img04
use constant img04_x => posX+21.4;
use constant img04_bas => posYbas+75.5;
use constant img04_haut => posYhaut+75.5;
#img05
use constant img05_x => posX+47.5;
use constant img05_bas => posYbas+85;
use constant img05_haut => posYhaut+85;
#img06
use constant img06_x => posX+73.6;
use constant img06_bas => posYbas+75.5;
use constant img06_haut => posYhaut+75.5;
#img07
use constant img07_x => posX+87.5;
use constant img07_bas => posYbas+45;
use constant img07_haut => posYhaut+45;
my $background = $page->gfx;
$background->strokecolor('lightgrey');
#bas
$background->circle( posCerX / mm, posCerYBas / mm, rext / mm );
$background->circle( posCerX / mm, posCerYBas / mm, rint / mm );
#haut
$background->circle( posCerX / mm, posCerYHaut / mm, rext / mm );
$background->circle( posCerX / mm, posCerYHaut / mm, rint / mm );
$background->stroke;
my ($px, $py);
my $param;
$param = "1";
print_isbn($page, $pdf, $param, isbn_x, isbn_bas, 25, 15);
$param = "3";
print_img($page, $pdf, $param, img01_x,img01_bas, 25, 30);
$param = "4";
print_img($page, $pdf, $param, img02_x,img02_bas, 25, 30);
$param = "5";
print_img($page, $pdf, $param, img03_x,img03_bas, 25, 30);
$param = "6";
print_img($page, $pdf, $param, img04_x,img04_bas, 25, 30);
$param = "7";
print_img($page, $pdf, $param, img05_x,img05_bas, 25, 30);
$param = "8";
print_img($page, $pdf, $param, img06_x,img06_bas, 25, 30);
$param = "14";
print_img($page, $pdf, $param, img07_x,img07_bas, 25, 30);
$param = "2";
print_isbn($page, $pdf, $param, isbn_x, isbn_haut, 25, 15);
$param = "9";
print_img($page, $pdf, $param, img01_x, img01_haut, 25, 30);
$param = "10";
print_img($page, $pdf, $param, img02_x, img02_haut, 25, 30);
$param = "11";
print_img($page, $pdf, $param, img03_x, img03_haut, 25, 30);
$param = "12";
print_img($page, $pdf, $param, img04_x, img04_haut, 25, 30);
$param = "2";
print_img($page, $pdf, $param, img05_x, img05_haut, 25, 30);
$param = "13";
print_img($page, $pdf, $param, img06_x, img06_haut, 25, 30);
$param = "15";
print_img($page, $pdf, $param, img07_x, img07_haut, 25, 30);
$pdf->save;
$pdf->end();
rmtree(nomDossier);
#####################
sub print_isbn {
my ($pageCourant, $pdfCourant, $paramCourant, $px, $py, $dx, $dy) = @_;
my $nomImg = sprintf ( 'temp%09s.jpg', $i);
print $nomImg."\n";
mkdir nomDossier;
my $url = '.\\'.nomDossier.'\\'.$nomImg;
print $url."\n";
push (@tableauNomPNG, $url);
output_isbn_temp ($paramCourant);
my $photo1 = $pageCourant->gfx;
my $url = '.\\'.nomDossier.'\\'.nomtempPNG;
die("Unable to find image file: $!") unless -e $tableauNomPNG[$j];
my $photo_file1 = $pdfCourant->image_png($tableauNomPNG[$j]);
#print "px: ".$px." py: ".$py."\n";
$photo1->image( $photo_file1, $px / mm, $py / mm, $dx / mm, $dy / mm );
$j++;
}
sub output_isbn_temp {
my ($in_id) = @_;
print $in_id."\n";
my $dsn = "dbi:mysql:$databaseISBN:$host:$port";
# Make a connection to your database
my $dbh = DBI->connect($dsn,$user,$pw) || die "Cannot open db";
my $sql = "SELECT blob_file FROM blobs WHERE serial_number='".$in_id."'";
print $sql."\n";
my $sth = $dbh->prepare($sql);
my $file = $sth->execute;
my $ref = $sth->fetchrow_hashref;
my $newdata = $$ref{'blob_file'};
# We are done with the statement handle
$sth->finish;
$dbh->disconnect;
open OUTPUT, ">".$tableauNomPNG[$j];
binmode OUTPUT;
print OUTPUT $newdata;
close OUTPUT;
}
sub print_img {
my ($pageCourant, $pdfCourant, $paramCourant, $px, $py, $dx, $dy) = @_;
my $nomImg = sprintf ( 'temp%09s.jpg', $i);
print $nomImg."\n";
mkdir nomDossier;
my $url = '.\\'.nomDossier.'\\'.$nomImg;
print $url."\n";
push (@tableauNomJPG, $url);
output_img_temp ($paramCourant);
my $photoCourant = $pageCourant->gfx;
die("Unable to find image file: $!") unless -e $tableauNomJPG[$i];
my $photo_fileCourant = $pdfCourant->image_jpeg($tableauNomJPG[$i]);
print "px: ".$px." py: ".$py."\n";
$photoCourant->image( $photo_fileCourant, $px / mm, $py / mm, $dx / mm, $dy / mm );
$i++;
}
sub output_img_temp {
my ($in_id) = @_;
print "parma image: ".$in_id."\n";
my $dsn = "dbi:mysql:$databaseIMG:$host:$port";
# Make a connection to your database
my $dbh = DBI->connect($dsn,$user,$pw) || die "Cannot open db";
my $sql = "SELECT Affiche FROM fimotech_affiches WHERE IDFilm='".$in_id."'";
print $sql."\n";
my $sth = $dbh->prepare($sql);
my $file = $sth->execute;
my $ref = $sth->fetchrow_hashref;
my $newdata = $$ref{'Affiche'};
# We are done with the statement handle
$sth->finish;
$dbh->disconnect;
print "file out: ".$tableauNomJPG[$i]."\n";
open OUTPUT, ">".$tableauNomJPG[$i];
binmode OUTPUT;
print OUTPUT $newdata;
close OUTPUT;
} |
Partager