Search code examples
barcodeprestashop-1.7

Insertion code does not work in 1.7 which was working in 1.6


I have a Prestashop 1.6 module which has in one point prepares a PDF with barcodes. The same module I upgraded to 1.7 but now PDF generates without the barcode. I did not change any thing in the template nor controller but bar code does not appear.

I followed this link to prepare bar codes for 1.6 version.

Following is my controller code where bar code prepared.

// Initiat PDF class
$pdf = new PDFGenerator((bool)Configuration::get('PS_PDF_USE_CACHE'));

// Prepare barcode
$barcode_params = $pdf->serializeTCPDFtagParameters(array(
   '123456789',
  'C39',
  '',
  '',
  50,
  20,
  0.2,
  array(
   'position'=>'S',
   'border'=>false,
   'padding'=>0,
   'fgcolor'=>array(0,0,0),
   'bgcolor'=>array(255,255,255),
   'text'=>true,
   'font'=>'Helvetica',
   'fontsize'=>8,
   'stretchtext'=>0),
   'N'));

Following is template code,

<tr>
 <td>
   <b>Shipper Order Number:</b>

 </td>
 <td >    
   <tcpdf method="write1DBarcode" params="{$barcode_params}"/>                                    
 </td>
</tr>

Any advice would be greatly appreciated..


Solution

  • Ok, I resolved this issue myself.

    But not with this method. for some reason

    <tcpd method="write1DBarcode" ... ' 
    

    seems does not work.

    So what I did was I bypassed 'HTMLTemplate..'  class creation and smarty templates all together  for labels and instead used a normal method to output a PDF custom HTML label using native function of TCPD class. 

    so here is the codes I used for producing the PDF label.

    $style = array(
    'position' => 'C',
    'align' => 'C',
    'stretch' => false,
    'fitwidth' => true,
    'cellfitalign' => '',
    'border' => true,
    'hpadding' => 'auto',
    'vpadding' => 'auto',
    'fgcolor' => array(0,0,0),
    'bgcolor' => array(255,255,255),
    'text' => true,
    'font' => 'helvetica',
    'fontsize' => 8,
    'stretchtext' => 4
    );
    
    $html = '<html><head><title></title><style>table { border-collapse: 
    collapse;font-family:arial;}td {padding: 10px; vertical-align: center;}';
    $html .= '</style></head><body>';
    
    foreach ($orders_array as $order)
    {
     $html = $this->prepare_html_label($order); //  this is where my html 
     template is prepared with actual values
     $pdf->setXY(93,472);
     $pdf->Ln(5);
     $pdf->write1DBarcode('*'.$order['awb'].'*', 'C128', '', '', '', 18, 0.4, 
     $style, 'N');
     $pdf->Ln(10);
     $pdf->writeHTML($html, true, false, true, false, '');
    }
    
    $pdf->Output('labels.pdf', 'D');
    }
    
    
    Problem solved.! 
    Hope this helps some one.