Jump to content

Barcode insertion code does not work in 1.7 which was working in 1.6


Presta Roshan

Recommended Posts

Hi everyone,

Hope you guys are enjoying a good weekend...

But for me having this issue kills my mood

I'v been working on a module to upgrade to support from 1.6 to 1.7 Prestashop version. 

This module which was working fine and generates proper bar codes in PDF for admin tasks.

( I implemented exactly as its described like in this  thread to print bar codes in my PDF)

 

But since when I upgraded and while testing I found out that the Smarty template code below does not produce the bar code which used to work fine in 1.6.

 

<tcpdf method="write1DBarcode" params="{$order.other_data.awb_barcode}" />

 

I have no other problems while upgrading it. only this is the issue.

I'm not sure if this is because of a bug or perhaps implementation of bar code in 1.7 has been changed.. 

Can anyone guide me to fix this issue?

 

Thanks in advance..

 

In my controller this is how I prepare serialized bar code string 

// 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'));

 

And in my Smarty template

 

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

  </td>
  <td >    
       <tcpdf method="write1DBarcode" params="{$order.other_data.awb_barcode}" />                                    
  </td>
</tr>

 

 

 

 

  • Like 1
Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

  • 6 months later...
On 30/01/2018 at 2:13 PM, Presta Roshan said:

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.

 

 

 

On 30/01/2018 at 2:13 PM, Presta Roshan said:

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.

 

 

 

 

Can you explain in which files and line code you added this?

Link to comment
Share on other sites

  • 2 years later...
  • 1 year later...

SOLVED - Hello guys , i've been searching many times and tried to use TCPDFBarcode module i wrote the code as mentioned in the TCPDF Documentation but did not work

i got an idea, which is to convert text to barcode using only html and css, i found it using a font family, and tried many times to include it in prestashop and finally found a solution ,

TCPDF can't recognize new fonts we have to convert it to its supported formats, so follow those steps :

A : Generate font by CLI (if there is a command line interface in your server otherwise read A steps and go to B steps)

1 - download woff2 file from : https://fonts.gstatic.com/s/librebarcode39/v19/-nFnOHM08vwC6h8Li1eQnP_AHzI2G_Bx0g.woff2
2 - convert it to .ttf format using this link : https://cloudconvert.com/woff2-to-ttf
3 - put .ttf file to this path \vendor\tecnickcom\tcpdf\tools (optionally: rename it because you will use that name as font-family name, Ex : barcodefont)
4 - use this command line to convert/add font by TCPDF : php tcpdf_addfont.php -i barcodefont.ttf (php required in your local host if you use B steps)
then 3 files will be generating to this path : \vendor\tecnickcom\tcpdf\fonts including font name 

barcodefont.php
barcodefont.ctg.z

barcodefont.z

B : convert font to TCPDF formats using your local machine

1 - install prestashop to your local host using xampp with compatible php version to prestashop 1.7 (xampp V3.3.0) Google that if you are not familiar with local host server
2 - after doing A steps , put those 3 files to \vendor\tecnickcom\tcpdf\fonts in your server
3 - use this in *.tpl file : <p style="font-family: 'barcodefont';font-size: 30px;text-align:center">*{$YOUR_VAR} or your text*</p>
NOTE : * is required before and after text, it's an encode technique of 'C39 type'
 

if you want to include some variables in invoice.tpl follow those steps:

1 - go to classes/pdf/HTMLTemplateInvoice.php

2 - search for getContent function 

3 - and add your variables before Data array ($data)  Ex

$phone_mobile= $invoice_address->phone_mobile; 
$phone= $invoice_address->phone;
$nb_orders = count(Order::getCustomerOrders((int)$this->order->id_customer));
// this is total orders of a client

4 - then add them below to Data array

'phone_mobile' => $phone_mobile,
'
phone' => $phone,
'nb_orders' => $nb_orders,

5 - then insert your variable to invoice.tpl like this : {$phone_mobile)

if you want to convert it to barcode use this : 

<p style="font-family: 'barcodefont';font-size: 30px;text-align:center">*{$phone_mobile}*</p> // do not forget * before and after variable

DONE, if you find this useful share it ^^

  • Thanks 1
Link to comment
Share on other sites

  • 9 months later...
On 6/14/2022 at 6:49 AM, ebdeuslave said:

SOLVED - Hello guys , i've been searching many times and tried to use TCPDFBarcode module i wrote the code as mentioned in the TCPDF Documentation but did not work

i got an idea, which is to convert text to barcode using only html and css, i found it using a font family, and tried many times to include it in prestashop and finally found a solution ,

TCPDF can't recognize new fonts we have to convert it to its supported formats, so follow those steps :

A : Generate font by CLI (if there is a command line interface in your server otherwise read A steps and go to B steps)

1 - download woff2 file from : https://fonts.gstatic.com/s/librebarcode39/v19/-nFnOHM08vwC6h8Li1eQnP_AHzI2G_Bx0g.woff2
2 - convert it to .ttf format using this link : https://cloudconvert.com/woff2-to-ttf
3 - put .ttf file to this path \vendor\tecnickcom\tcpdf\tools (optionally: rename it because you will use that name as font-family name, Ex : barcodefont)
4 - use this command line to convert/add font by TCPDF : php tcpdf_addfont.php -i barcodefont.ttf (php required in your local host if you use B steps)
then 3 files will be generating to this path : \vendor\tecnickcom\tcpdf\fonts including font name 

barcodefont.php
barcodefont.ctg.z

barcodefont.z

B : convert font to TCPDF formats using your local machine

1 - install prestashop to your local host using xampp with compatible php version to prestashop 1.7 (xampp V3.3.0) Google that if you are not familiar with local host server
2 - after doing A steps , put those 3 files to \vendor\tecnickcom\tcpdf\fonts in your server
3 - use this in *.tpl file : <p style="font-family: 'barcodefont';font-size: 30px;text-align:center">*{$YOUR_VAR} or your text*</p>
NOTE : * is required before and after text, it's an encode technique of 'C39 type'
 

if you want to include some variables in invoice.tpl follow those steps:

1 - go to classes/pdf/HTMLTemplateInvoice.php

2 - search for getContent function 

3 - and add your variables before Data array ($data)  Ex

$phone_mobile= $invoice_address->phone_mobile; 
$phone= $invoice_address->phone;
$nb_orders = count(Order::getCustomerOrders((int)$this->order->id_customer));
// this is total orders of a client

4 - then add them below to Data array

'phone_mobile' => $phone_mobile,
'
phone' => $phone,
'nb_orders' => $nb_orders,

5 - then insert your variable to invoice.tpl like this : {$phone_mobile)

if you want to convert it to barcode use this : 

<p style="font-family: 'barcodefont';font-size: 30px;text-align:center">*{$phone_mobile}*</p> // do not forget * before and after variable

DONE, if you find this useful share it ^^

 

 

You are amazing! this totally worked thank you so much!!!

 

I was stuck at the "run php command" part for a while since my server is not very easy to use and I am new to prestashop 1.7

However, in case this can help anybody, I used this site: https://fonts.palettize.me/ to obtain the .php, .ctg.z and .z files and then it worked perfectlly.

currently using: prestashop 1.7.6.8

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...