Jump to content

How to add Non-standard font from PDF invoice


WAILINNSOE

Recommended Posts

Hello all friend , our country language have standard font and non-standard font so i can't add non-standard font from PDF ..PDF generate time that show square letter (can't read).

 

Plz help to me

 

now i already created language for non standard font  zu . that all working but Pdf generate time don't work

 

so

 

i created prestashop/tools/tcpdf/fonts for  zawgyi-one.z , zawgyi-one.php , zawgyi-one.ctg.z

 

(using website http://fonts.snm-portal.com/)

 

and

 

prestashop/override/classes/PDF/ for created PDFGenerator.php

 

using this code

 

<?php
class PDFGenerator extends PDFGeneratorCore {
    public function __construct($use_cache = false, $orientation = 'P'){
        // Override the font for your language
        $this->font_by_lang['zu'] = 'zawgyi-one';
        parent::__construct($use_cache, $orientation);
    }
}

 

and again changed

 

public_html/classes/pdf  (PDFGenerator.php)

 

const DEFAULT_FONT = 'freeserif';

 

but still PDF invoice generate time don't working

 

Plz help to me

 

 

Link to comment
Share on other sites

  • 4 years 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 ^^

  • Like 1
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...