Jump to content
haylau

Add barcode to PDF delivery slip / Invoice

Recommended Posts

Hi

 

I would like to take our internal reference number and add it to the PDF delivery slip as a Barcode.

 

I can get the raw data there i think, and I know I "just" have to change the font of that raw data and it will display as a barcode

 

I have a ttf file with the barcode font in, is there any way I can get the PDF code to use this or am i asking too much?

Share this post


Link to post
Share on other sites

:(

 

Likely not possible? Shame really I would have thought it would benefit many users

Share this post


Link to post
Share on other sites

Because I searched and searched and couldn't find an answer, just lots of people asking, here is a solution.

 

This adds a barcode with the order number in it under the address on the invoice - I'm going to be using it for dispatch tracking - But you can use the exact same technique to create barcodes of anything printable anywhere on the templates.

 

Tested on PS 1.6.0.14.

 

Within /pdf/invoice.tpl

 

Just before

</table>
<!-- / ADDRESSES

add

<tr>
<td style="width: 17%"></td>
<td style="width: 83%">
 
{assign var=black value=[0,0,0]}{assign var=white value=[255,255,255]}
{assign var=stuff value=['position'=>'S', 'border'=>false, 'padding'=>4, 'fgcolor'=>$black, 'bgcolor'=>$white, 'text'=>false, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4]}
{assign var=params value=TCPDF::serializeTCPDFtagParameters(array($order->getUniqReference(), 'C39', '', '', 40, 15, 0.4, $stuff, 'N'))}
<tcpdf method="write1DBarcode" params="{$params}" />
 
</td>
</tr>
 
 
The item to be barcoded is , in this case, '$order->getUniqReference()' - you can use any variable available to smarty at the point you want to print.  For changing the size/style etc, see the TCPDF reference.
 
HTH
Edited by irrelevant (see edit history)

Share this post


Link to post
Share on other sites

 

Because I searched and searched and couldn't find an answer, just lots of people asking, here is a solution.

 

This adds a barcode with the order number in it under the address on the invoice - I'm going to be using it for dispatch tracking - But you can use the exact same technique to create barcodes of anything printable anywhere on the templates.

 

Tested on PS 1.6.0.14.

 

Within /pdf/invoice.tpl

 

Just before

</table>
<!-- / ADDRESSES

add

<tr>
<td style="width: 17%"></td>
<td style="width: 83%">
 
{assign var=black value=[0,0,0]}{assign var=white value=[255,255,255]}
{assign var=stuff value=['position'=>'S', 'border'=>false, 'padding'=>4, 'fgcolor'=>$black, 'bgcolor'=>$white, 'text'=>false, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4]}
{assign var=params value=TCPDF::serializeTCPDFtagParameters(array($order->getUniqReference(), 'C39', '', '', 40, 15, 0.4, $stuff, 'N'))}
<tcpdf method="write1DBarcode" params="{$params}" />
 
</td>
</tr>
 
 
The item to be barcoded is , in this case, '$order->getUniqReference()' - you can use any variable available to smarty at the point you want to print.  For changing the size/style etc, see the TCPDF reference.
 
HTH

 

 

Thanks for your code barcode print on invoice

 

It's Working but i have an error in invoice

 

Strict Standards: Non-static method TCPDF::serializeTCPDFtagParameters() should not be called statically in /home/districtcart/public_html/tools/smarty/sysplugins/smarty_internal_templatebase.php(171) : eval()'d code on line 152

 

can u Please help me to rectify this error in invoice

 

Thanks in Advance

Edited by harid (see edit history)

Share this post


Link to post
Share on other sites

Disable Debug mode.

i am already disable debug mode

 

here is the disable debug code

 

/* Debug only */
if (!defined('_PS_MODE_DEV_'))
define('_PS_MODE_DEV_', false);
/* Compatibility warning */
define('_PS_DISPLAY_COMPATIBILITY_WARNING_', false);
if (_PS_MODE_DEV_ === true)
{
@ini_set('display_errors', 'on');
@error_reporting(E_ALL | E_STRICT);
define('_PS_DEBUG_SQL_', true);
}
else
{
@ini_set('display_errors', 'off');
define('_PS_DEBUG_SQL_', false);
}
 
define('_PS_DEBUG_PROFILING_', false);
define('_PS_MODE_DEMO_', false);

Share this post


Link to post
Share on other sites

 

Try adding an

error_reporting(0);
in front of that lot.

 

 

Thanks for  your above barcode code print on invoice

 

It's Working but i have an error in invoice

 

Strict Standards: Non-static method TCPDF::serializeTCPDFtagParameters() should not be called statically in /home/districtcart/public_html/tools/smarty/sysplugins/smarty_internal_templatebase.php(171) : eval()'d code on line 152

 

Below error invoice pdf file has been attached

 

can u Please help me to rectify this error in invoice

 

Thanks in Advance

VVS_INV_000027.pdf

Edited by HARI DUDDELA (see edit history)

Share this post


Link to post
Share on other sites

You can also discard Strict Standards errors in php.ini.

Share this post


Link to post
Share on other sites

You can also discard Strict Standards errors in php.ini.

Thanks tuk problem solved in invoice

 

I have an another strict standard error in homepage

 

Strict Standards: Declaration of Dispatcher::loadRoutes() should be compatible with DispatcherCore::loadRoutes($id_shop = NULL) in /home/districtcart/public_html/override/classes/Dispatcher.php on line 36

Warning: Cannot modify header information - headers already sent by (output started at /home/districtcart/public_html/override/classes/Dispatcher.php:36) in/home/districtcart/public_html/classes/controller/FrontController.php on line 823

 

Warning: Cannot modify header information - headers already sent by (output started at /home/districtcart/public_html/override/classes/Dispatcher.php:36) in/home/districtcart/public_html/classes/controller/FrontController.php on line 824

 

Can u please help me to rectify this error 

 

Thank in advance

Edited by HARI DUDDELA (see edit history)

Share this post


Link to post
Share on other sites

That one looks like a problem in code added to the override folder - usually by a module.  Have you added any lately?

Share this post


Link to post
Share on other sites

irrelevant's solution works. If you want to get rid of the error in pdf and do not mind changing php files you could do the following (tested on PS 1.5):
 
1. In HTMLTemplateInvoice.php in /classes/pdf or /override/classes/pdf (if you have it there) add the following three lines to getContent() function before 

$this->smarty->assign(array(
$pdf = new PDFGenerator((bool)Configuration::get('PS_PDF_USE_CACHE'));
$barcode_params = $pdf->serializeTCPDFtagParameters(array($this->order->getUniqReference(), 'C128', '', '', 0, 0, 0.2, array('position'=>'S', 'border'=>false, 'padding'=>0, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'freesans', 'fontsize'=>8, 'stretchtext'=>0), 'N'));
$this->smarty->assign(array('barcode_params' => $barcode_params));

2. In your invoice.tpl template (in my case it was in /themes/my_theme/pdf) add where you want to place the barcode:

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

3. Change $this->order->getUniqReference() in step 1 to whatever you want to be coded in the barcode. I have order reference there. Read documentation to TCPDF write1DBarcode function here and change barcode parameters to you liking (font, size, border, padding, etc).

 

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

I have issue when I add <tcpdf method="write1DBarcode" params="{$barcode}"> to pdf.header.tpl just right after {$title}

 

I generate barcode with

       $pdf = new PDFGenerator((bool)Configuration::get('PS_PDF_USE_CACHE'));

        $barcode_params = $pdf->serializeTCPDFtagParameters(array(Configuration::get('PS_INVOICE_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('%06d', $order->invoice_number), 'C128', '', '', 0, 0, 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'));
        $this->barcode = array('barcode' => $barcode_params);
 
in HTMLTemplateInvoice.php and added 'barcode' => $this->barcode to classes/pdf/HTMLTemplate.php
 
When I uncomment the <tcpdf method="write1DBarcode" params="{$barcode}"> no logo, title and barcode is shown. 

Share this post


Link to post
Share on other sites

Thank you it's working for me in prestashop 1.6

 

 

Because I searched and searched and couldn't find an answer, just lots of people asking, here is a solution.

 

This adds a barcode with the order number in it under the address on the invoice - I'm going to be using it for dispatch tracking - But you can use the exact same technique to create barcodes of anything printable anywhere on the templates.

 

Tested on PS 1.6.0.14.

 

Within /pdf/invoice.tpl

 

Just before

</table>
<!-- / ADDRESSES

add

<tr>
<td style="width: 17%"></td>
<td style="width: 83%">
 
{assign var=black value=[0,0,0]}{assign var=white value=[255,255,255]}
{assign var=stuff value=['position'=>'S', 'border'=>false, 'padding'=>4, 'fgcolor'=>$black, 'bgcolor'=>$white, 'text'=>false, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4]}
{assign var=params value=TCPDF::serializeTCPDFtagParameters(array($order->getUniqReference(), 'C39', '', '', 40, 15, 0.4, $stuff, 'N'))}
<tcpdf method="write1DBarcode" params="{$params}" />
 
</td>
</tr>
 
 
The item to be barcoded is , in this case, '$order->getUniqReference()' - you can use any variable available to smarty at the point you want to print.  For changing the size/style etc, see the TCPDF reference.
 
HTH

 

Share this post


Link to post
Share on other sites

 

Because I searched and searched and couldn't find an answer, just lots of people asking, here is a solution.

 

This adds a barcode with the order number in it under the address on the invoice - I'm going to be using it for dispatch tracking - But you can use the exact same technique to create barcodes of anything printable anywhere on the templates.

 

Tested on PS 1.6.0.14.

 

Within /pdf/invoice.tpl

 

Just before

</table>
<!-- / ADDRESSES

add

<tr>
<td style="width: 17%"></td>
<td style="width: 83%">
 
{assign var=black value=[0,0,0]}{assign var=white value=[255,255,255]}
{assign var=stuff value=['position'=>'S', 'border'=>false, 'padding'=>4, 'fgcolor'=>$black, 'bgcolor'=>$white, 'text'=>false, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4]}
{assign var=params value=TCPDF::serializeTCPDFtagParameters(array($order->getUniqReference(), 'C39', '', '', 40, 15, 0.4, $stuff, 'N'))}
<tcpdf method="write1DBarcode" params="{$params}" />
 
</td>
</tr>
 
 
The item to be barcoded is , in this case, '$order->getUniqReference()' - you can use any variable available to smarty at the point you want to print.  For changing the size/style etc, see the TCPDF reference.
 
HTH

 

 

perfect. it works.

how can I add it inside mail from Mailalert module? thanks

Edited by ietax (see edit history)

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More