Open(); $pdf->SetPageMargins($CBG_TOP_MARGIN, $CBG_BOTTOM_MARGIN, $CBG_LEFT_MARGIN, $CBG_RIGHT_MARGIN); $pdf->SetFont($pmb_pdf_font, '', $CBG_TEXT_FONT_SIZE); $pdf->SetCBFontSize($CBG_CB_TEXT_SIZE); $pdf->SetCBXRes($CBG_CB_RES); $pdf->SetCBStyle(BCS_ALIGN_CENTER | BCS_BORDER | BCS_DRAW_TEXT); switch ($source) { case 'fromfile' : $mv=move_uploaded_file($_FILES['userfile']['tmp_name'],"../temp/".basename($_FILES['userfile']['tmp_name'])); if (!$mv) print "Could not upload file"; $fname="../temp/".basename($_FILES['userfile']['tmp_name']); //ouverture du fichier $f = @fopen($fname, 'r'); if (!$f) { print "error while opening file ".$fname; exit(); } // on charge tout en mémoire, on coupe aux espaces et on met le tout dans un tableau $filecontent = fread ($f, filesize($fname)); if (!$filecontent) { print "empty file ".$fname; exit(); } fclose($f); unlink($fname); $cbarray = preg_split("/[\s]+/", $filecontent, -1, PREG_SPLIT_NO_EMPTY); unset($filecontent); $nbr_cb = count($cbarray); if ($nbr_cb == 0) { $fini = true; print "no valid barcodes found in file ".$fname; exit(); } else { $i_cb = 0; $cb = $cbarray[$i_cb]; } $fini = false; break; case 'autoinc' : default : $cb = $cb_first; $fini = false; if ($nbr_cb < 1) $fini = true; break; } $cbwidth = $pdf->GetStickWidth() - $CBG_INNER_LEFT_MARGIN - $CBG_INNER_RIGHT_MARGIN; $cbheight = $pdf->GetStickHeight() - $CBG_INNER_TOP_MARGIN - $CBG_INNER_BOTTOM_MARGIN - $CBG_TEXT_HEIGHT ; // if ($bibli_name != '') { $cbheight -= $CBG_TEXT_HEIGHT; // } while ( ! $fini) { // Ajoute une étiquette $pdf->AddStick(); // texte if ($bibli_name != "") { $pdf->SetXY($pdf->GetStickX(), $pdf->GetStickY() + $CBG_INNER_TOP_MARGIN); $pdf->Cell($pdf->GetStickWidth(), $CBG_TEXT_HEIGHT, stripslashes($bibli_name.$truc), 0, 0, 'C'); } // code barre $x = $pdf->GetStickX() + $CBG_INNER_LEFT_MARGIN; $y = $pdf->GetStickY() + $CBG_INNER_TOP_MARGIN; if ($bibli_name != "") { $y += $CBG_TEXT_HEIGHT; } $pdf->DrawBarcode($cb, $x, $y, $cbwidth, $cbheight, 'c39'); // code barre en clair ( il faut desactiver son affichage ds le fichier class/barecode.php par define("BCS_DRAW_TEXT" , 0); au lieu de 128 $pdf->SetXY($pdf->GetStickX(), $pdf->GetStickY() + $CBG_INNER_TOP_MARGIN + $CBG_TEXT_HEIGHT + $cbheight); $pdf->Cell($pdf->GetStickWidth(), $CBG_TEXT_HEIGHT, $cb, 0, 0, 'C'); // incrémentation et test de fin switch ($source) { case 'fromfile' : $i_cb++; if ($i_cb >= $nbr_cb) { $fini = true; } else { $cb = $cbarray[$i_cb]; } break; case 'autoinc' : default : // incrémentation $i = strlen($cb) - 1; do { if ($cb{$i} == "9") { $cb{$i} = 0; if ($i == 0) { $cb = "1".$cb; } } else { $cb{$i} = chr(ord($cb{$i}) + 1); } $i--; } while (($i >= 0) && ($cb{$i+1} == 0)); // test de fin if ($pdf->GetNbrSticks() >= $nbr_cb) { $fini = true; } break; } } $pdf->Output('CB'.$cb_first.'-'.($cb_first+$nbr_cb).'.pdf', true);