Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Hello,
Zend_Barcode a été revu par Matthew et devrait être intégré au core rapidement pour la sortie de ZF 1.10alpha. Le composant est divisé en 2 sous-composant : les objects et les renderers. 4 objets sont présents : Code39, Code25, Interleaved 2of5 et ITF14. 2 renderers sont présents : Image et Pdf.
Avant la sortie finale, je pense intégrer la famille complète des EAN/UPC. Si vous avez des suggestions concernant le choix de type de code-barres, n'hésitez pas à me les remonter.
Note : aucun code-barres 2D ne sera présent dans le 1.10 (Datamatrix ou autres Flashcode).
Je vais écrire un article sur l'utilisation dans la semaine mais la documentation officielle est un bon point de départ (en anglais )
@+
Hors ligne
Bonjour,
Je suis en train de tester ce nouveau composant...
Je me retrouve cependant confronté a un probleme, j'arrive bien a afficher le code barre comme une image, mais je n'arrive pas à l'enregistrer dans un pdf...
Voici la manière dont je l'utilise :
$jpgsPath = ROOT_PATH . DS . 'library' . DS . 'Wbx' . DS . 'Pdf' . DS . 'jpgs';
$validityDate = '10/12/2010';
$productModel = substr($productModel, 0, 7);
$pdf = new Zend_Pdf();
//Style par défaut
$style = new Zend_Pdf_Style();
$lineColor = new Zend_Pdf_Color_GrayScale(0.2);
$style->setLineColor($lineColor);
$style->setLineWidth(1);
$fontBold = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
$pdf->pages[] = ($page1 = $pdf->newPage('A4'));
$pdf->pages[] = ($page2 = $pdf->newPage('A4'));
$pdf->pages[] = ($page3 = $pdf->newPage('A4'));
//page 1
$imagePath = $jpgsPath . DS . $productModel . '_p1.jpg';
$imageHeader = Zend_Pdf_Image::imageWithPath($imagePath);
$page1->drawImage($imageHeader, 0, 0, 595, 842);
//page 2
$imagePath = $jpgsPath . DS . $productModel . '_p2.jpg';
$imageHeader = Zend_Pdf_Image::imageWithPath($imagePath);
$page2->drawImage($imageHeader, 0, 0, 595, 842);
$page2->setFont($fontBold, 8);
$page2->drawText($validityDate, 262, 110);
$page2->drawText($validityDate, 460, 110);
$barcodeOptions = array(
'barHeight' => 31 ,
'barThickWidth' => 3 ,
'barThinWidth' => 1 ,
'text' => 'TOTO');
$pdfOptions = array('topOffset' => 10 ,
'leftOffset' => 10);
$renderer = Zend_Barcode::factory('code39', 'pdf', $barcodeOptions, $pdfOptions);
$renderer->setResource($pdf, 1);
$renderer->render();
$imagePath = ROOT_PATH . DS . 'library' . DS . 'Wbx' . DS . 'Pdf' . DS . 'jpgs' . DS . $productModel . '_p3.jpg';
$imageHeader = Zend_Pdf_Image::imageWithPath($imagePath);
$page3->drawImage($imageHeader, 0, 0, 595, 842);
$pdf->save(ROOT_PATH . DS . 'library' . DS . 'Wbx' . DS . 'Pdf' . DS . 'pdfs' . DS . 'test.pdf');
le probleme est qu'il me retourne une exception avec ce message : Invalid file path
Comment puis je régler ce soucis?
Merci...
Hors ligne
Hello,
Je ne vois pas d'où viens ton "Invalid file path", il faudrait plus d'infos : sans doute lié à l'un des Zend_Pdf_Image::imageWithPath()
Concernant la partie Zend_Barcode :
$renderer = Zend_Barcode::factory('code39', 'pdf', $barcodeOptions, $pdfOptions); $renderer->setResource($pdf, 1); $pdf = $renderer->draw(); //render émet les headers
@+
Hors ligne
@moms : regarde la ligne de ton exception, ça te dira où est le problème. Tu as sans doute un nom de répertoire foireux dans tes chemins du genre "ROOT_PATH . DS ...."
A+, Philippe
Hors ligne
Merci mikaelkael et philippe pour vos réponses, je regarde ça de plus prêt et je vous tiens au courant...
Hors ligne
Hello,
Cette exception était générée car je n'avais pas donné de chemin pour la police du zend_barcode :
Zend_Barcode::setBarcodeFont(ROOT_PATH . '/library/'Wbx/Pdf/fonts/FreeSerif.ttf');
Voici mon code corrigé, ca pourra peut etre servir a quelqu'un :
$jpgsPath = ROOT_PATH . DS . 'library' . DS . 'Wbx' . DS . 'Pdf' . DS . 'jpgs';
$validityDate = '10/12/2010';
$productModel = substr($productModel, 0, 7);
$pdf = new Zend_Pdf();
//Style par défaut
$fontBold = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
//largeur A4 : 595 | hauteur A4 : 842
$pdf->pages[] = ($page1 = $pdf->newPage('A4'));
$pdf->pages[] = ($page2 = $pdf->newPage('A4'));
$pdf->pages[] = ($page3 = $pdf->newPage('A4'));
//page 1
$imagePath = $jpgsPath . DS . $productModel . '_p1.jpg';
$imageHeader = Zend_Pdf_Image::imageWithPath($imagePath);
$page1->drawImage($imageHeader, 0, 0, 595, 842);
//page 2
$imagePath = $jpgsPath . DS . $productModel . '_p2.jpg';
$imageHeader = Zend_Pdf_Image::imageWithPath($imagePath);
$page2->drawImage($imageHeader, 0, 0, 595, 842);
$page2->setFont($fontBold, 8);
$page2->drawText($validityDate, 262, 110);
$page2->drawText($validityDate, 460, 110);
//BARCODE
Zend_Barcode::setBarcodeFont(ROOT_PATH . DS . 'library' . DS . 'Wbx' . DS . 'Pdf' . DS . 'fonts' . DS . 'FreeSerif.ttf');
$barcodeOptions = array(
'text' => 32123456 ,
'barHeight' => 40 ,
'barThickWidth' => 5 ,
'barThinWidth' => 1 ,
'fontSize' => 12);
$pdfOptions = array('topOffset' => 710 ,
'leftOffset' => 390);
$renderer = Zend_Barcode::factory('ean8', 'pdf', $barcodeOptions, $pdfOptions);
$renderer->setResource($pdf, 1);
$renderer->draw();
//page 3
$imagePath = ROOT_PATH . DS . 'library' . DS . 'Wbx' . DS . 'Pdf' . DS . 'jpgs' . DS . $productModel . '_p3.jpg';
$imageHeader = Zend_Pdf_Image::imageWithPath($imagePath);
$page3->drawImage($imageHeader, 0, 0, 595, 842);
$pdf->render();
$pdf->save(ROOT_PATH . DS . 'library' . DS . 'Wbx' . DS . 'Pdf' . DS . 'pdfs' . DS . 'test.pdf');
@ plus...
Hors ligne
OK, je vais regarder dans le détail pour rajouter un message plus explicite.
Merci.
Hors ligne