Jump to content

Migrate from FPDF to TCPDF


Recommended Posts

Just wanna share my experience with TCPDF after I found out FPDF does not support Unicode in my language (Vietnamese):

1. Download TCPDF from TCPDF at Sourceforge

2. Unzip TCPDF into Tools folder, at the same place with FPDF

3. Modify the following files:
+ config\config.inc.php: add 01 line

define('_PS_TCPDF_PATH_',            _PS_TOOL_DIR_.'tcpdf/');



+ classes\PDF.php:

- Line 15:

include_once(_PS_TCPDF_PATH_.'tcpdf.php');


- Line 17:

class PDF extends TCPDF


- Line 51:

parent::__construct($orientation, $unit, $format, true, 'UTF-8');


- Line 162 + 297:

$pdf->getAliasNbPages();


- Line 498:

$this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']).' - '.self::l('Customized'), 'B', 'L');


- Line 520:

$this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']), 'B', 'L');


- Line 708:

return $font ? $font : 'freesans';



+ class\Tools.php: Go to line 784 to modify static public function iconv(...)

static public function iconv($from, $to, $string)
{
       //$converted = htmlentities($string, ENT_NOQUOTES, $from);
       //$converted = html_entity_decode($converted, ENT_NOQUOTES, $to);
       //return $converted;
       return $string;
}



Everything works well except you need to modify PDF.php manually to change PDF font. However I don't do it frequently, so either FreeSans or DejaVuSans is enough. Remember to include the bold version of the font, too.

  • Like 1
Link to comment
Share on other sites

Hello!!!

Thanks! Everything works great, but!!!

In Version 1.1.0.5 line numbers are not correct
so:

In file classes\PDF.php:
line 15 and 17 is correct,
Line 51 -> 50
Line 162 -> 161
Line 297 -> 296
Line 498 -> 497
Line 520 -> 519
Line 708 -> 707

Other files are ok!

Link to comment
Share on other sites

Thank rigorchik for the line number correction. I should have included the original code so it would be easier for newbies. A bit lazy when new year came :o)

By the way, I had to modify the column width of the product table since it is not enough to fit my description. The magic is line #452:

$w = array(90, 15, 25, 10, 25, 25);



I increased the column width from 90 to 92 and everything worked as expected for me. You may want to increase more but I am afraid it may ruin the order structure since items are placed manually. I wish if we could have a kind of layout like GridBagLayout in Java to automate calculation of sizes & positions.

Link to comment
Share on other sites

thanks so much. its finally work!

Somehow after modified ../classes/PDF.php as above.
PDF constructer function will try to include selected-font in your back-office >> preferrences >> PDF setting which refered to /fpdf/font/ (but new PDF search this font in it's own tcpdf/font/)

this will cause error "TCPDF ERROR: Could not include font definition file: "

to fix this error, in /classes/PDF.php constructor fix $_pdfparams to your desired font

line: 48 replace or comment out this line

'font' => (isset($conf['PS_PDF_FONT_'.$lang]) AND $conf['PS_PDF_FONT_'.$lang] == true) ? $conf['PS_PDF_FONT_'.$lang] : 'helvetica'



with this

'font' =>''



now PDF class will ignore PDF useless setting in web-user interface

Link to comment
Share on other sites

Well, I did not get the same message as you did when I left only DejaVuSans, FreeSans, etc. in the tcpdf/font folder. However generated PDF could not display Vietnamese characters so I had to include helvetica, times, courier, etc. Everything is running fine for me. So if you copy just helvetica, I think the problem can be solved without the modification you made.

(Why I copied only selected fonts? Because the CJK fonts eat up so much valuable space and lengthen ftp transfer time.)

thanks so much. its finally work!

Somehow after modified ../classes/PDF.php as above.
PDF constructer function will try to include selected-font in your back-office >> preferrences >> PDF setting which refered to /fpdf/font/ (but new PDF search this font in it's own tcpdf/font/)

this will cause error "TCPDF ERROR: Could not include font definition file: "

to fix this error, in /classes/PDF.php constructor fix $_pdfparams to your desired font

line: 48 replace or comment out this line
'font' => (isset($conf['PS_PDF_FONT_'.$lang]) AND $conf['PS_PDF_FONT_'.$lang] == true) ? $conf['PS_PDF_FONT_'.$lang] : 'helvetica'



with this

'font' =>''



now PDF class will ignore PDF useless setting in web-user interface

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...
  • 1 month later...

I did something wrong :)

I get this error:
Warning: require_once(/Applications/MAMP/htdocs/SHOP/config/../classes/FPDF.php) [function.require-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/SHOP/config/config.inc.php on line 22

Fatal error: require_once() [function.require]: Failed opening required '/Applications/MAMP/htdocs/SHOP/config/../classes/FPDF.php' (include_path='.:/Applications/MAMP/bin/php5/lib/php') in /Applications/MAMP/htdocs/SHOP/config/config.inc.php on line 22

This is line 22: require_once(dirname(__FILE__).'/../classes/'.$className.'.php');

What's it talking about??

Thx

Link to comment
Share on other sites

  • 2 weeks later...

Hi all!

In attach you can find configured php files and tcpdf folder download from http://sourceforge.net/project/showfiles.php?group_id=128076

IMPORTANT!

before replacing php files BACKUP OLD FILES!

Files to replace:

config\config.inc.php
classes\PDF.php
class\Tools.php

Upload TCPDF into Tools folder, at the same place with FPDF


Works fine to me and i hope that should work fine to others.

php.zip

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...
  • 2 weeks later...

Hello there and thanks for sharing this migration with us. I'm having the same problem as the person above me (keep getting blank page) and I know it has something to do with the PDF.php which I edited manually, downloaded the files in this thread but each time I'm getting the same result.

Running the default PDF.php gives me (PDF exports perfectly, well almost due to UTF-8 failure):


Warning: include_once(_PS_FPDF_PATH_fpdf.php) [function.include-once]: failed to open stream: No such file or directory in /home2/warjoker/public_html/eshop/classes/PDF.php on line 15

Warning: include_once() [function.include]: Failed opening '_PS_FPDF_PATH_fpdf.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home2/warjoker/public_html/eshop/classes/PDF.php on line 15

Fatal error: Class 'FPDF' not found in /home2/warjoker/public_html/eshop/classes/PDF.php on line 17


meanwhile the migrated PDF.php:


Warning: include_once(_PS_TCPDF_PATH_tcpdf.php) [function.include-once]: failed to open stream: No such file or directory in /home2/warjoker/public_html/eshop/classes/PDF.php on line 16

Warning: include_once() [function.include]: Failed opening '_PS_TCPDF_PATH_tcpdf.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home2/warjoker/public_html/eshop/classes/PDF.php on line 16

Fatal error: Class 'FPDF' not found in /home2/warjoker/public_html/eshop/classes/PDF.php on line 18



Any ideas please?
Link to comment
Share on other sites

hello thpoul,
i see you have the same problem with me.
i still havent fixed that but i found that from the moment i enter the include_once(_PS_TCPDF_PATH_tcpdf.php) in pdf.php i got the blank page and if i remove it the page shows up again!!
maybe there is something wrong with the path...??

Link to comment
Share on other sites

I don't think there is something wrong with the path there. If you set it correctly on your config.inc.php there shouldn't be a problem. Thing is that even if you run PDF.php in a fresh install the syntax error is still there for some reason.

Link to comment
Share on other sites

  • 4 weeks later...

I couldn't apply the instructions from the first post to 1.2 as the files have changed significantly, so I was looking for a simpler solution as I only need Eastern and Western Euopean characters.

Looking at this thread.

Hi all,

i found this on a forum (original post http://www.prestashop.com/forums/viewthread/14105/#79197).
I just uploaded files (classes folder needs override) and čžš works without problems.
It's for PS 1.1

In back office in pdf settings you have to choose CP1250 and font arialmt.

Boik

Do they fix FPDF just for characters in the Czech language or is it a more general solution? As far as I could tell it didn't involve TCPDF, just adding a more useful font to FPDF.

I can see that classes/PDF.php has the available fonts hardcoded in so that file needs changing to add arielmt. Also install the arialmt font fron the zip file and select arialmt in Back Office >> Preferences >> PDF?
Link to comment
Share on other sites

Hi all!

In attach you can find configured php files and tcpdf folder download from http://sourceforge.net/project/showfiles.php?group_id=128076

IMPORTANT!

before replacing php files BACKUP OLD FILES!

Files to replace:

config\config.inc.php
classes\PDF.php
class\Tools.php

Upload TCPDF into Tools folder, at the same place with FPDF


Works fine to me and i hope that should work fine to others.

Thanks, but it can not work with 1.2.2

can anyone fix it?

many thanks
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
  • 3 weeks later...
  • 2 months later...
  • 2 months later...

If anyone is interested... for PS 1.3 RC6.

Like bimbee wrote in his first post:

1. Download TCPDF from TCPDF at Sourceforge

2. Unzip TCPDF into Tools folder, at the same place with FPDF (default: /tools/tcpdf)

3. Edit the file: /config/config.inc.php

a)

Find:

define('_PS_FPDF_PATH_',            _PS_TOOL_DIR_.'fpdf/');


Replace with:

define('_PS_TCPDF_PATH_',            _PS_TOOL_DIR_.'tcpdf/');



B)

Find:

include_once(_PS_FPDF_PATH_.'fpdf.php');
class PDF_PageGroup extends FPDF


Replace with:

include_once(_PS_TCPDF_PATH_.'tcpdf.php');
class PDF_PageGroup extends TCPDF




4. Edit the file: /classes/PDF.php

a)

Find:

FPDF::FPDF($orientation, $unit, $format);


Replace with:

parent::__construct($orientation, $unit, $format, true, 'UTF-8');



B)

Find:

'encoding' => (isset($conf['PS_PDF_ENCODING_'.$isoCode]) AND $conf['PS_PDF_ENCODING_'.$isoCode] == true) ? $conf['PS_PDF_ENCODING_'.$isoCode] : 'iso-8859-1',


Replace with:

'encoding' => (isset($conf['PS_PDF_ENCODING_'.$isoCode]) AND $conf['PS_PDF_ENCODING_'.$isoCode] == true) ? $conf['PS_PDF_ENCODING_'.$isoCode] : 'utf-8',



c)

Find:

return (isset(self::$_pdfparams[self::$_iso]) AND is_array(self::$_pdfparams[self::$_iso]) AND self::$_pdfparams[self::$_iso]['encoding']) ? self::$_pdfparams[self::$_iso]['encoding'] : 'iso-8859-1';


Replace with:

return (isset(self::$_pdfparams[self::$_iso]) AND is_array(self::$_pdfparams[self::$_iso]) AND self::$_pdfparams[self::$_iso]['encoding']) ? self::$_pdfparams[self::$_iso]['encoding'] : 'utf-8';



d)

Find:

return $font ? $font : 'Arial';


Replace with:

return $font ? $font : 'freesans';




That's it. Works for me.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

open admin/tabs/AdminPDF.php

find

$fontFiles = scandir(_PS_FPDF_PATH_.'font');



replace with

$fontFiles = scandir(_PS_TCPDF_PATH_.'fonts');



and find

$encodingFiles = scandir(_PS_FPDF_PATH_.'font/makefont');



replace with

$encodingFiles = scandir(_PS_TCPDF_PATH_.'fonts/utils/enc');

Link to comment
Share on other sites

finally got it.

edit /classes/Tools.php
Find:

static public function  iconv ( $from  , $to ,  $string )
   {
   if (function_exists('iconv'))
   return iconv($from, $to.'//TRANSLIT', str_replace('¬•', '¥', str_replace('¬£', '£', str_replace('‚Ǩ', '€', $string))));
   return html_entity_decode(htmlentities($string, ENT_NOQUOTES, $from), ENT_NOQUOTES, $to);
   return $string ;
   } 



Replace with:

    static public function  iconv ( $from  , $to ,  $string )
   {
   /*if (function_exists('iconv'))
   return iconv($from, $to.'//TRANSLIT', str_replace('¬•', '¥', str_replace('¬£', '£', str_replace('‚Ǩ', '€', $string))));
   return html_entity_decode(htmlentities($string, ENT_NOQUOTES, $from), ENT_NOQUOTES, $to);*/
   return $string ;
   }     

Link to comment
Share on other sites

  • 3 weeks later...

The instructions work, except the

define('_PS_TCPDF_PATH_',            _PS_TOOL_DIR_.'tcpdf/'); 


this line, put in config.inc.php gives several path errors in 1.3.1, and that's understandable since there was nothing to replace with it.
The config.inc.php does not have

define('_PS_FPDF_PATH_',            _PS_TOOL_DIR_.'fpdf/'); 


So the line should go to defines.inc.php under

define('_PS_FPDF_PATH_',            _PS_TOOL_DIR_.'fpdf/');


The only problem remaining si the currency symbol that doesn't show, but i replaced it with EUR from BO-Payment-Currencies and i'm satisfied with it.

Link to comment
Share on other sites

  • 3 weeks later...

Hello everybody,

I come from SLOVENIA where we use čžš like many other languages. I also set charset to UTF-8 and I try to solve the PDF problems by instructions from mstiopa for PS 1.3 RC6. I stop at first step. Oh I have to say I work on PS 1.3.1.1.
In file /config/config.inc.php I can't find line define('_PS_FPDF_PATH_', _PS_TOOL_DIR_.'fpdf/'); . OK , I undarstand if line is not there I create new one and insert define('_PS_TCPDF_PATH_', _PS_TOOL_DIR_.'tcpdf/'); .

I also insert or change all missing lines to suggested files but I get only empty screen when I open PDF invoice.

Now question.
Does anybody have clear instructions - step by step how to solve this problem.
Thank you ...

regards
Boris

Link to comment
Share on other sites

Hi , I am using **Prestashop 1.2.5**

Thanks for these tips
I've applied them and everyhing worked except for these issues

1- the product description justification in invoices (**solved**)

*** I have solved this problem , in /clases/pdf.php look for lines like this

$this->MultiCell($w[0], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']), 'B');


end replace like this

$this->MultiCell($w[0], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']), 'B', 'L');


there are two or three of these , the default justification in the TCPDF is 'J' justified , that was the reason, other way is to change the implementation of TCPDF::MultiCell() and leave the align argument default value to 'L' instead of 'J'.



2- The japanese YEN symbol was removed (**solved**)

*** to solve this look for this method in /classes/pdf.php

   static private function convertSign($s)
   {
       return str_replace('¥', chr(165), str_replace('£', chr(163), str_replace('€', chr(128), $s)));
       return $s;
   }


and replace with

   static private function convertSign($s)
   {
       //return str_replace('¥', chr(165), str_replace('£', chr(163), str_replace('€', chr(128), $s)));
       return $s;
   }


I dont know what side effects these changes would produce.



3- the page number/totalpagenumber numbers on the footer ( prints like this Page 1/{nb1}(**solved**)

*** Solved this modifying /classes/pdf.php

           function _beginpage($orientation, $arg2)
      {
       parent::_beginpage($orientation, $arg2);
       if($this->NewPageGroup)
       {
           // start a new group
           $n = sizeof($this->PageGroups)+1;
           $alias = "{nb$n}";
           $this->PageGroups[$alias] = 1;
           $this->CurrPageGroup = $alias;
           $this->NewPageGroup=false;
       }
       elseif($this->CurrPageGroup)
           $this->PageGroups[$this->CurrPageGroup]++;
            }




4- generating the invoices from BO/Orders/Invoices->Print PDF Invoices generates blank pages(**Pending**)


I have attached two pfds genereated from our shop , one is the "old" pdf generated which doesnot print kanji and the new one with prints all kanji but with those issues

Any idea where should I start to look to try to solve them

thanks

Prestashop V1.2.5

000002-6.pdf

000002-7.pdf

Link to comment
Share on other sites

Continuing with this ,
Our shop needs to print the invoince(two copies), in order to solve this I just simple called the printing function twice, but this gave me an undesired result, I've attached the pdf generated, could anyone give a hint on what could be wrong

***
to call the printing function twice I changed /admin/pdf.php in line 30

if (!isset($_GET['id_order']))
       die (Tools::displayError('order ID is missing'));
   $order = new Order(intval($_GET['id_order']));
   if (!Validate::isLoadedObject($order))
       die(Tools::displayError('cannot find order in database'));
   PDF::invoice2($order); //here i call invoice2() instead of the original invoice()



and add this method to /classes/PDF.php in which I call the invoice function twice

      //invoice duplicado 
   public static function invoice2($order)
   {
       $pdf = new PDF('P', 'mm', 'A4');

       if (Validate::isLoadedObject($order))
       {
           self::invoice($order, 'D', true, $pdf);            
           self::invoice($order, 'D', true, $pdf);        
       };                

       return $pdf->Output('invoices.pdf', 'D');        
   }


removing the extra call, produces a correct pdf file. I attatched the pdfs generated calling twice and once
forgot to mention, this happened after migrating to the new pdf library, the old one was ok.

invoices.pdf

invoices(2).pdf

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...

Works on presta 1.3.1! Great Thanks! Followed all steps. Made few changes.

1) 3. Edit the file: /config/config.inc.php

a)

Find:

 define('_PS_FPDF_PATH_',            _PS_TOOL_DIR_.'fpdf/');



Replace with:

define('_PS_TCPDF_PATH_',            _PS_TOOL_DIR_.'tcpdf/');



Just in /config/define.inc.php

2) B)

Find:

 include_once(_PS_FPDF_PATH_.'fpdf.php');
class PDF_PageGroup extends FPDF



Replace with:

 include_once(_PS_TCPDF_PATH_.'tcpdf.php');
class PDF_PageGroup extends TCPDF



Located in the Classes/pdf.php

3) Find:

return $font ? $font : 'Arial';



Replace with:

return $font ? $font : 'dejavusans';



Also in the classes/pdf.php

Freesans doesn't worked for me in correct types. Dejavusans font look great and works.

Thanks fellows! I hope it can helps for 1.3.1 users.

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

I try this tactic in Version 1.3.2.3 but no luck for now it look like that PDF.pdf isnt the same as in 1.3.1. versinon. I cant find the lines

include_once(_PS_FPDF_PATH_.'fpdf.php');
class PDF_PageGroup extends FPDF 



to replace it with

include_once(_PS_TCPDF_PATH_.'tcpdf.php');
class PDF_PageGroup extends TCPDF 



Is there any body who would upload this files to dounload them or help us to get this working thx.

Link to comment
Share on other sites

I checked the ./classes/PDF.php of Ver 1.3.2.3, the lines are there, starts from line 15 as following

include_once(_PS_FPDF_PATH_.'fpdf.php');

class PDF_PageGroup extends FPDF
{



Please make sure you are looking into the correct file and your file has not been customized by someone before.

Link to comment
Share on other sites

PLEASE HELP. I have two problems.

1.) When I migrate from FPDF to TCPDF everithing work great exept € sign looks like these �. If there is a solition for this or how to change in Eur if posible.

2.) For editing invoices i use jbx_custominvoice module and it have a problem becouse of TCPDF give me error
(TCPDF ERROR: Could not include font definition file: arial)
How to edit jbx_custominvoice.php file to work in my shop with TCPDF?

Thank you very much for any tips you my have.

jbx_custominvoice.php

Link to comment
Share on other sites

  • 2 months later...
  • 4 weeks later...

Followed #45 Istox's and #37 tata.mata's tutorial.

Also followed #1 blmbee's tutorial-to add/edit Line51, Line162+297, Line 498 and Line 520 in my 1.3.6.0 PDF.php file(the Lines number is different).

But still get white screen on generating pdf.

Can anyone please make it work for 1.3.6.0. It would be a great help.

Thanks in advance!

Link to comment
Share on other sites

I figure out, i cahnge AdminPDF.php that i can change fonts in administration, and set cp1251 - dejavusasns and it worked.


hi xejay, will you please public your /classes/PDF.php here, 1.3.6.0 vision is near your 1.3.5.0 vision.
1.3.6.0 users may be enlightened by your PDF.php file.
Link to comment
Share on other sites

  • 2 weeks later...

I am quite new here. My prestashop version is 1.3.6.0.

I am stuck with pdf files generated in Prestashop. Korean charactors in the pdf files not showing correctly, showing like ‘?? ???? ???’. I did trasnlate from English to Korean under Tools. In Korean view, all showing like ????? ??? ??? except for numbers. I could see, in Engish view, some English words which I translated from, but some Koreans still showing like ??? ???? ???.

Would anyone please help me out?

Link to comment
Share on other sites

  • 1 month later...
Mine after change like instruction, when i click on the PDF generator link, it says:

TCPDF ERROR: Some data has already been output to browser, can't send PDF file

So anyone know how to fix this error?

I'm using the latest PS, 1.3.7

Thanks.


The way I fixed this problem is add
ob_clean();

at tcpdf.php between line 8066 & 8068. Have a try! :)

Link to comment
Share on other sites

  • 3 weeks later...

I have 1.4.0.17.

Got working TCPDF without errors, but printed PDFs are still missing special characters as ť or č. Do you have any idea guys? I've tried many fonts and many encodings (dejavusans/freesans with cp1250 included). Besides that, I tried all mentioned ideas/hints in this thread...

Any help appreciated :)

Link to comment
Share on other sites

below is quoted my post from the other thread...


hey people, i’m still struggling with certain symbols as ť č í ….

over the last days I’ve gathered all the available knowledge from this forum and managed to get TCPDF “working”, actually not giving me any errors, printing PDFs but still without those special characters – some fonts print out “?” instead of “č” for instance, while others keep me looking sadly on the 257th exported PDF with just space instead of the particular special character.

I’m attaching all the files I’ve modified, feel free to use them & edit them. I’d appreciate your feedback whether it works for you or not, where by “it” I mean special characters, also please state your language and special characters which are working and those, which are not.

These files were imported from PS 1.4.0.17, which I’m using right now.

Everybody interested in this problem can reach me here or at Freenode, #prestashop.

I believe we lately manage to get this tcpdf vs. utf8 tragedy working as soon as possible.

PS: Please backup all your current files (which you’re planning to overwrite) if you didn’t yet, as I don’t want to be held responsible for any committed suicides after debugging…

files.zip

Link to comment
Share on other sites

what language/characters do you need?

you know, fonts for the TCPDF have to be changed in ...classes/PDF.php, not from the webadmin...


I'm trying to get chinese to work.

Thing is, I tried the files you gave on a clean installation of Prestashop but the PDF output is still blank except for the logo. Which means even English is not 100% working on mine.
Link to comment
Share on other sites

You posted the new feature task, but there is much more in this thread : modifications to make, modified files are attached here, etc..

This is much more simple for us if we have already the solution ;)


The problem is, even with lucasss help from the modified files he provided, I still couldn't get it to work. I'll work on it a little more and will update if there are any breakthroughs.
Link to comment
Share on other sites

It seems to be working for me now regarding the chinese characters. PDF seems to be printing out OK. It must have been the proxy caching the old php files when I was at work.

I'll post a full and detailed change here Sunday morning as I'll be away tomorrow. Credit goes to lucasss.

Link to comment
Share on other sites

It seems to be working for me now regarding the chinese characters. PDF seems to be printing out OK. It must have been the proxy caching the old php files when I was at work.

I'll post a full and detailed change here Sunday morning as I'll be away tomorrow. Credit goes to lucasss.


Please do post when you get a chance. I'm also having trouble getting the Chinese characters to work with PDF. Followed the TCPDF instructions so far, but still showing the characters as '?????' I'm however using 1.3.6 at the moment but considering upgrading to 1.4
Link to comment
Share on other sites

Changes needed to make TCPDF work in Prestashop 1.4.0.17

Easy way:

1. Download the zip file provided by lucasss.
2. Backup your admin/tabs/AdminPDF.php, classes/PDF.php, classes/Tools.php, config/config.inc.php, config/defines.inc.php
3. Upload the provided files by lucasss. It should work now.

The better way, for those who have modified versions of their own files.

1. Changes in AdminPDF.php

Find

$fontFiles = scandir(_PS_FPDF_PATH_.’font’);

under /* Collect all font files and build array for combo box */ and replace with

$fontFiles = scandir(_PS_TCPDF_PATH_.’fonts’);



Find

scandir(_PS_FPDF_PATH_.’font/makefont’);

under /* Collect all encoding map files and build array for combo box */ and replace with

scandir(_PS_TCPDF_PATH_.’fonts/utils/enc’);



2. Changes in PDF.php

Find

include_once(_PS_FPDF_PATH_.’fpdf.php’);

and replace with

include_once(_PS_TCPDF_PATH_.’tcpdf.php’);



Find

class PDF_PageGroupCore extends FPDF

and replace with

class PDF_PageGroupCore extends TCPDF



Find

FPDF::FPDF($orientation, $unit, $format);

under the __construct function and replace with

parent::__construct($orientation, $unit, $format, true, ‘UTF-8′);



Find

‘encoding’ => (isset($conf['PS_PDF_ENCODING_'.$isoCode]) AND $conf['PS_PDF_ENCODING_'.$isoCode] == true) ? $conf['PS_PDF_ENCODING_'.$isoCode] : ‘iso-8859-1′,

under the _initpdffonts function and replace iso-8859-1 with utf-8

Find

‘font’ => (isset($conf['PS_PDF_FONT_'.$isoCode]) AND $conf['PS_PDF_FONT_'.$isoCode] == true) ? $conf['PS_PDF_FONT_'.$isoCode] : ‘helvetica’

and replace with

‘font’ => ‘kozminproregular’

This means kozminproregular is always embedded. Maybe that's why lucasss couldn't get his special symbols to show?

Find

$this->MultiCell($w[0], 5, Tools::iconv(’utf-8′, self::encoding(), $product['product_name']), ‘B’);

under the ProdReturnTab() function and replace with

$this->MultiCell($w[++$i], 5, Tools::iconv(’utf-8′, self::encoding(), $product['product_name']).’ – ‘.self::l(’Customized’), ‘B’, ‘L’);

But I think this is not needed.

Find

$this->MultiCell($w[++$i], 5, Tools::iconv(’utf-8′, self::encoding(), $product['product_name']).’ – ‘.self::l(’Customized’), ‘B’),

under ProdTab function and add ‘L’ after ‘B’.

Find

$arr['before'] = array(’€’, ‘£’, ‘¥’);

under the function convertSign($s) and replace with

$arr['before'] = array(’‚Ǩ’, ‘¬£’, ‘¬•’);



Find

‘iso-8859-1′

under the encoding() function and replace with

‘utf-8′



Find Arial under fontname() function and replace with kozminproregular

3. Changes in Tools.php

The changes are regarding some Currency strings, I suggest you compare it with lucasss' files and change as necessary. I don't think it is essential for tcpdf to work

4. Changes in defines.inc.php

Add define(’_PS_TCPDF_PATH_’, _PS_TOOL_DIR_.’tcpdf/’);

Link to comment
Share on other sites

alright, lately got working all special characters. The last thing why it didn't work in my case was pdf reader, I used default one in OSX, which didn't decode it properly.... adobe reader does it perfectly.

All the special characters work with freesans and dejavusans (including all subtypes of dejavusans, as for instance dejavusanscondensed)

Result: everything, but € sign works...

Link to comment
Share on other sites

Thanks lucasss & kelvinlym!

PDF is now working properly in Chinese. I decided to follow kelvinlym's steps since I've already modified some files earlier. I was afraid of theme compatibility issues with v1.4 so I decided to hold off the upgrade and apply the changes directly to v1.3.6 first to see if it worked. Everything works now.

Thanks again!!

Link to comment
Share on other sites

  • 3 weeks later...
请教一下,1.4.1版本的要怎样才能正常显示中文发票么


Maybe it's better if you write in English:D

请教一下,1.4.1版本的要怎样才能正常显示中文发票么 = Asking about 1.4.1 version, how to properly display Chinese invoice
Link to comment
Share on other sites

  • 4 weeks later...

spent the day playing with that...

still getting this error:

Strict Standards: Declaration of PDF_PageGroupCore::_beginpage() should be compatible with that of TCPDF::_beginpage() in /home/*my_user*/*my_website*/_/classes/PDF.php on line 31

Strict Standards: Declaration of PDF_PageGroupCore::StartPageGroup() should be compatible with that of TCPDF::startPageGroup() in /home/*my_user*/*my_website*/_/classes/PDF.php on line 31

TCPDF ERROR: Some data has already been output, can't send PDF file

Any help appreciated!

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

sorry I didn't answered sooner

beginpage and startpagegroup should be declared like that (according to the original PDF.php ) :

function _beginpage($orientation, $arg2)
function StartPageGroup()


You can also notice the change of line 554 :

if ($h['id_order_state'] == Configuration::get('PS_OS_SHIPPING'))



Please give me feedback about that, if this still doesn't work, I will follow your tutorial and try to see what is missing.

Regards,

Link to comment
Share on other sites

arial is not available by default as far as i know

you should use as "font" dejavusans or freesans, try to replace one or two "arial" matches in PDF.php with the fonts I mentioned, it could probably start working.

however, i'm out of home for 2 days for work. will catch ya later hopefully

Link to comment
Share on other sites

My language is chinese so i replaced all "arial" occurences by "stsongstdlight" but i have this error and can't understand why.

TCPDF ERROR: Could not include font definition file: arial

can someone give me a fix for prestashop 1.4.2.5

it would be great if prestashop could includ TCPDF instead of FPDF

Link to comment
Share on other sites

I finally fixed it yesterday.

My 1st problem was this error message :

TCPDF ERROR: Could not include font definition file: arial

this was due to the name of arial font in the archive of tcpdf I downloaded, it was named arialunicid0.php, I renamed it arial.php and it works.

The 2nd problem was with encoding, I just replaced the line

'encoding' => (isset($conf['PS_PDF_ENCODING_'.$isoCode]) AND $conf['PS_PDF_ENCODING_'.$isoCode] == true) ? $conf['PS_PDF_ENCODING_'.$isoCode] : 'utf-8',

with

'encoding' => 'utf-8',

under the _initPDFFonts() function in PDF.php

And now it works perfectly !!!

Link to comment
Share on other sites

So I went ahead and tried to do the fixes that Kevin suggested but I couldn't figure out the third step

3. Changes in Tools.php

The changes are regarding some Currency strings, I suggest you compare it with lucasss’ files and change as necessary. I don’t think it is essential for tcpdf to work

so I left it blank.

After finishing what I can, every time I click the invoice/delivery slip I just get a blank screen. Is it because I didn't do anything for the tools.php?

I'm using the newest 1.4.3.

Thank you!

Link to comment
Share on other sites

×
×
  • Create New...