Jump to content

Migrate from FPDF to TCPDF


Recommended Posts

I didn't change anything in tools.php and it works.
Your problem might be with PDF.php.

Did you modified the line concerning encoding as I said in a post yesterday ? if you did it, just verify you didn't forget the comma at the end of the lane.

And for japanese it works with kozminproregular font.

Just look at the files I attached with this post maybe it can help.

myfiles.zip

  • Like 1
Link to comment
Share on other sites

Hi Senjaman, I kinda got frustrated and just tried and inserted your files into my folders and I actually got an error message this time around

TCPDF ERROR: Could not include font definition file: simhei

was the outcome. At least its not an blank screen? I guess I have to keep trying.

Link to comment
Share on other sites

  • 2 months later...

I don't know the reason for you to migrate to TCPDF, but I have found a WORKING solution how to fix the fonts for the default PDF engine that comes with Prestashop - Czech/Slovak symbols work properly on pdf invoices and the thread is located here: http://www.prestasho...-classespdfphp/

 

The solution follows:

Download the zip file or generate your own fonts via the guide in that thread.

Copy ALL of the language files to /prestashop/tools/fpdf/font

Change permissions of all new files (add execute rights to all of them) -- chmod u+x,g+x,o+x *

Change the font to one of the new ones and enjoy!

Link to comment
Share on other sites

Reason? It's fancy, that's why we are all after it ;)

Oh well, never mind me then, I'm not enough fancy for you to be hanging oround with the cool kids :)

But frankly, I don't understand why this functionality isn't present in the base install of Prestashop and has to be fixed by googling the forums.

Link to comment
Share on other sites

I made it using Lucass files and now it is showing my language symbols. But i have one problem, so i need HELP. All data that is written under Description is stretched, however it should be on the Left side... So where i should go to fix this problem? All other data is showing right..

 

Here is the image of what is look like and how it should be.

94713515.jpg

 

Any ideas?

==========================

 

 

Thanx to ezakimak for post #43. I solved it.

Link to comment
Share on other sites

  • 2 weeks later...

Hello Can anybody help?

 

I get this error

 

Warning: scandir(C:\wamp\www\prestashop/tools/tcpdf/fonts/utils/enc,C:\wamp\www\prestashop/tools/tcpdf/fonts/utils/enc) [function.scandir]: The system cannot find the path specified. (code: 3) in C:\wamp\www\prestashop\powerhouse\tabs\AdminPDF.php on line 54

 

When I try to change the pdf settings.

 

I dont think I have the utils folder in the tcpdf folder.

 

Please assist

Link to comment
Share on other sites

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

how to change € sign to EUR, at the moment there's just ?

I just found how to fix the € sign in the PDF. The problem is that function displayPrice in classes/Tools.php when called with true argument is trying to convert in to non-unicode char and this ends up messing up the char code. So either replace the first argument in displayPrice($somevariable, $somevariable, true) with false, or just edit the function displayPrice in classes/Tools.php, and delete this piece of code:

if ($no_utf8)

return str_replace('€', chr(128), $ret);

Link to comment
Share on other sites

  • 2 weeks later...

In PDF.php , in method Footer()

Replace this line of code

$this->Cell(190, 5, ' '."\n".Tools::iconv('utf-8', self::encoding(), 'P. ').$this->GroupPageNo().' / '.$this->PageGroupAlias(), 'T', 1, 'R');

With this one

$this->Cell(190, 5, ' '."\n".Tools::iconv('utf-8', self::encoding(), 'P. ').$this->getAliasNumPage().' / '.$this->getAliasNbPages(), 'T', 1, 'R');

 

This solved that problem in my installation (ps1.4.0.17), perhaps it could help you too

 

Regards

 

Hugo Takada

 

 

j'ai pu faire marcher TCPDF avec 1.4.3 mais j'ai encore un problème avec l'affichage du nombre de page dans la facture j'ai quelque chose qui ressemble a ça "P.1 /{nb1}", le reste fonctionne parfaitement,

si quelque a une idée d’où ça peu venir?

merci.

Link to comment
Share on other sites

  • 4 weeks later...

Hello everyone,

 

I'm using Prestashop version 1.4.4.1, can you help to instruct me step by step to make Traditional Chinese work well for Invoice PDF? Seems that Prestashop has changed a lot compared to the modifications in the early posts. Additionally, I'm using latest TCPDF (Jan 12, 2012).

 

Appreciate your help and happy new year!

Link to comment
Share on other sites

Hello everyone,

 

I'm using Prestashop version 1.4.4.1, can you help to instruct me step by step to make Traditional Chinese work well for Invoice PDF? Seems that Prestashop has changed a lot compared to the modifications in the early posts. Additionally, I'm using latest TCPDF (Jan 12, 2012).

 

Appreciate your help and happy new year!

 

desolé pour le retard: regarde et suit les etapes une par une: http://www.prestashop.com/forums/topic/142673-migrer-de-fpdf-vers-tcpdf/page__hl__tcpdf__fromsearch__1

Link to comment
Share on other sites

Thanks a lot for your information, Hichamino!

 

After made a bunch of changes (please refer to my attachments including the original and updated files base don Prestashop 1.4.4.1final) per many people's suggesiton in this thread, I got a error like this when clicking PDF, "TCPDF ERROR: Could not include font definition file: arial".

 

I do notice that Senjaman's post on 07 July 2011 , saying that "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.". But in my case where the latest TCPDF version (Jan 12, 2012) is being used, meaning there is no arial related php files under fonts folder. So how could we solve this issue?

Can anybody help? Thanks!

Prestashop_forum_post_Jan21.zip

Link to comment
Share on other sites

  • 2 months later...

Great topic as i am in dire need to fix this as well!

 

Have downloaded TCPDF and followed most of the instructions on this topic, but i cant help but see problems still

 

I am trying to have 3 languages printable in PDF:

English, Chinese Simplified, Chinese Traditional

 

I am using Prestashop 1.4.7

 

Would anyone have this setup working already and willing to provide the edited files in 1 zip file?

 

Thank you very very much!

Link to comment
Share on other sites

I tried every steps for 1.4.7.0 and I got blank page when I finish the ordering process. When I click on PDF file, I got Server Error as below. Does anyone meet the same issue? Please help!

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

Link to comment
Share on other sites

Thanks ezakimak for your reply

 

I am using 1.4.7.0 and would like to be able to have Simplified Chinese (and Traditional Chinese) in the invoices as some clients input Chinese in their details.

 

Have tried the options that people provided, for example:

- download TCPDF and change necessary files, change font to "stsongstdlight"

 

I would still get the following problems:

- No currency sign like "£, €, ¥"

- Weird spacing of the table (the description of products)

 

So am asking how to make it work for 1.4.7 and if Chinese Simplified and Traditional is possible

 

Thanks in advance

Link to comment
Share on other sites

Thanks for the files ezakimak!

 

Have checked it and the files are different then version 1.4.7

I went ahead and made the changes again as mentioned in previous posts and it seems to be working ok... but with some strange problems still

- page number underneath appears as P. 1 / {nb1}

how to fix this?

Link to comment
Share on other sites

This is a bug in PDF class, find this piece of code in this class/method PDF::Footer() and replace, I think I have addressed this in previous post too.

Regards

Hugo

 /*pe modification , resolves page number issue
  *	 before it printed like this 1/nb1, 1/nb2 */
  //original line commented
  //$this->Cell(190, 5, ' '."\n".Tools::iconv('utf-8', self::encoding(), 'P. ').$this->GroupPageNo().' / '.$this->PageGroupAlias(), 'T', 1, 'R');
 //new line
 $this->Cell(190, 5, ' '."\n".Tools::iconv('utf-8', self::encoding(), 'P. ').$this->getAliasNumPage().' / '.$this->getAliasNbPages(), 'T', 1, 'R');
 /* pe extention */

 

 

Thanks for the files ezakimak!

 

Have checked it and the files are different then version 1.4.7

I went ahead and made the changes again as mentioned in previous posts and it seems to be working ok... but with some strange problems still

- page number underneath appears as P. 1 / {nb1}

how to fix this?

Link to comment
Share on other sites

Awesome!

Everything works now and it seems to do Chinese Simplified and Traditional as well

Did change all the currencies to normal text form, like EUR, USD, RMB etc because the normal currency signs didnt work.

The rest seem to be working well!

 

Thanks again ezakimak!

p.s. nice shop!

Link to comment
Share on other sites

John,

As far as I recall this I solved changing this method in class Tools, look at the commented out line of code.

Regards

Hugo

 

ps. I'm glad you liked the shop

 

public static function iconv($from, $to, $string)
{
 if (function_exists('iconv'))
  //return iconv($from, $to.'//TRANSLIT', str_replace('ツ・', '¥', str_replace('ツ」', '£', str_replace('竄ャ', '€', $string))));
  return $string;
 return html_entity_decode(htmlentities($string, ENT_NOQUOTES, $from), ENT_NOQUOTES, $to);
}

 

Awesome!

Everything works now and it seems to do Chinese Simplified and Traditional as well

Did change all the currencies to normal text form, like EUR, USD, RMB etc because the normal currency signs didnt work.

The rest seem to be working well!

 

Thanks again ezakimak!

p.s. nice shop!

Link to comment
Share on other sites

  • 1 month later...

Hi,

Could you give more details on your issues, I have 1.4.7.3 working(following the advises in this thread) with Japanese.

Regards

 

Can you help me, I got the same problem, blank page

Link to comment
Share on other sites

  • 4 weeks later...

Did you get it to work ?

 

the key is add the font, i can't get it , when i add you files , and add the font in the PDF.php under the _initPDFFonts() function

$this->AddFont('simhei', '', 'font/simhei.php'); and 'encoding' => (isset($conf['PS_PDF_ENCODING_'.$isoCode]) AND $conf['PS_PDF_ENCODING_'.$isoCode] == true) ? $conf['PS_PDF_ENCODING_'.$isoCode] : 'UTF-8', remplace 'encoding' =>'utf-8',

 

after go to backoffice->orders->pdf, it's empty, no font, so when i click view invoice, th page is white, can't appear the pdf

 

 

how to do that?

Edited by cooro (see edit history)
Link to comment
Share on other sites

Hi,

First of all, can you tell me which prestashop version you are using and the steps you followed to try to accomplish this.

 

the key is add the font, i can't get it , when i add you files , and add the font in the PDF.php under the _initPDFFonts() function

$this->AddFont('simhei', '', 'font/simhei.php'); and 'encoding' => (isset($conf['PS_PDF_ENCODING_'.$isoCode]) AND $conf['PS_PDF_ENCODING_'.$isoCode] == true) ? $conf['PS_PDF_ENCODING_'.$isoCode] : 'UTF-8', remplace 'encoding' =>'utf-8',

 

after go to backoffice->orders->pdf, it's empty, no font, so when i click view invoice, th page is white, can't appear the pdf

 

 

how to do that?

Link to comment
Share on other sites

  • 3 months later...

I have it working on ps1.4.9.0 following steps provided here , please follow again carefully you must have missed something

 

 

Hi,

I have problem with pdf in 1.4.9 version.

I have tried all these solutions but none work.

Have anyone tried to force 1.4.9 version work with TCPDF?

Link to comment
Share on other sites

Refer to post #126

I can't send my files because I have many other customization that would break your installation.

 

Hi ezakimak! Those are great news. Biggest challlange is lining in all files i need to change. because line numbers are changed again. Ie it possible that you post again all changes i have to make? Or maybe you can post whole file and i could try to replace my files?

Edited by ezakimak (see edit history)
Link to comment
Share on other sites

Its little strange that in /override/classes folder i didnt have to overwrite any file.

See attachment.

PDF.php

Product.php

Tools.php

these are your provided files.

And there was no files named by this before i copied them there. So i had to replace /admin/tabs/adminpdf and /config/defines.inc.php but files in /override/classes i didnt ave to overwrite because there was no files called pdf,product and tools.

post-400851-0-13271200-1350375260_thumb.jpg

Link to comment
Share on other sites

You should enable error display in your site to see what errors you have

edit config.inc.php in /yourprestashopinstall/config/

 

 

Its little strange that in /override/classes folder i didnt have to overwrite any file.

See attachment.

PDF.php

Product.php

Tools.php

these are your provided files.

And there was no files named by this before i copied them there. So i had to replace /admin/tabs/adminpdf and /config/defines.inc.php but files in /override/classes i didnt ave to overwrite because there was no files called pdf,product and tools.

Link to comment
Share on other sites

ok, I dont that and i found out that there waas my mistake.

I left

define('_PS_TCPDF_PATH_', _PS_TOOL_DIR_.'tcpdf/');
in /config/config.inc.php.

So now everything works! :) Thanks ezakimak!

I have the same problem with that []P. 1 / 1 problem but i see you already have solution for that!

  • Like 1
Link to comment
Share on other sites

Yes you are right, that's why I overrode that method, look at override/pdf.php

 

convertSign() function breaks the utf-8 currecy symbol

 

classes/PDF.php

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

Edited by ezakimak (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

For chinese user,please take a look of my attachment. The prestashop version I used is 1.4.9.0.

对简体中文用户,请下载并参考我上传的附件。里面包含了相应的修改过的文件。如想自己修改,请使用文件对比工具查看。

另,附有更新日期为2012-10-24的tcpdf_5_9_195。有文件已修改。 tcpdf_5_9_195.zip 2012-10-24

百度网盘下载地址 :http://pan.baidu.com/share/link?shareid=90170&uk=3338978994

Edited by taonylu (see edit history)
Link to comment
Share on other sites

  • 3 months later...

It appears that v1.5.3 already uses tcpdf and uses UTF-8

 

But there is still a problem with display of Chinese text.

So have played around and couldn't get "kozminproregular" to work as well.

Dug around and found out that the font was not available in the folder tools/tcpdf/fonts

So added the kozminproregular.php and finally could render the Chinese text

 

Although not 'perfect' as it can't seem to render this Chinese character "馠" but the rest does render correctly for now.

 

Who knows which font is best used for Chinese character rendering as "kozminproregular" is best for Japanese instead

Link to comment
Share on other sites

please help having error :

 

Strict Standards: Declaration of PDF_PageGroupCore::_beginpage() should be compatible with that of TCPDF::_beginpage() inC:\xampp\htdocs\israel\classes\PDF.php on line 31

 

Strict Standards: Declaration of PDF_PageGroupCore::StartPageGroup() should be compatible with that of TCPDF::startPageGroup() inC:\xampp\htdocs\israel\classes\PDF.php on line 31

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

ps 1.4.8.2

thanks

Edited by degger (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hi all!

 

I'm using Prestashop 1.5.3. and I have the same problem in tcpdf. I have uploaded tcpdf folder in "Tools" directory, then replaced files:

config/define.inc.php

override/claasse/PDF.php

Product.php

Tools.php

 

This files I have donwloaded from this forum. But unfortunately I have an fatall error: "Class name must be a valid object or a string in Classes/controller/controller.php".

 

If someone have any idea, how can fix this problem, please help.

Thanks in advance.

Link to comment
Share on other sites

Hi,

PS 1.5 does not need these tricks.

 

Hi all!

 

I'm using Prestashop 1.5.3. and I have the same problem in tcpdf. I have uploaded tcpdf folder in "Tools" directory, then replaced files:

config/define.inc.php

override/claasse/PDF.php

Product.php

Tools.php

 

This files I have donwloaded from this forum. But unfortunately I have an fatall error: "Class name must be a valid object or a string in Classes/controller/controller.php".

 

If someone have any idea, how can fix this problem, please help.

Thanks in advance.

Link to comment
Share on other sites

  • 2 months later...

Hi!

 

Here is my full solution for prestashop 1.4.11.0. I use 3 languages RU, DE, EN and 1 currency EUR. In admin tab PDF you can choice UTF-8 and font - not all fonts work properly. I use "freesans".

"-" - comment this line

"+" - add this line

 

Upload TCPDF to folder "Tools"

 

 

FPDF --> TCPDF

 

/classes/PDF.php

-27 include_once(_PS_FPDF_PATH_.'fpdf.php');
-29 class PDF_PageGroupCore extends FPDF
+31 include_once(_PS_TCPDF_PATH_.'tcpdf.php');
+32 class PDF_PageGroupCore extends TCPDF

-114 FPDF::FPDF($orientation, $unit, $format);
+115 parent::__construct($orientation, $unit, $format);

-304 $this->Cell(190, 5, Tools::iconv('utf-8', self::encoding(), self::l('P. ')).$this->GroupPageNo().' / '.$this->PageGroupAlias(), 'T', 1, 'R');
+305 $this->Cell(190, 5, Tools::iconv('utf-8', self::encoding(), self::l('P. ')).$this->getAliasNumPage().' / '.$this->getAliasNbPages(), 'T', 1, 'R');

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

-575 $pdf->AliasNbPages();
+576 $pdf->getAliasNbPages();

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

-1343 return str_replace(array('€', '£', '¥', '¢', '£', '¥', '€'), array(chr(128), chr(163), chr(165), chr(162), chr(163), chr(165), chr(128)), $s);
+1344 return $s;

 

/classes/Tools.php

-440 if ($no_utf8)
-441 return str_replace(array('€', '£', '¥'), array(chr(128), chr(163), chr(165)), $ret);
+442 return $ret;

 

/admin/tabs/AdminPDF.php

-40 $fontFiles = scandir(_PS_FPDF_PATH_.'font');
+41 $fontFiles = scandir(_PS_TCPDF_PATH_.'fonts');

+57 $arr['mode'] = 'UTF-8';
+58 $arr['name'] = 'UTF-8';
+59 array_push($encodingList, $arr);

 

/config/defines.inc.php

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

 

 

 

 

Dead Sea cosmetic

Edited by Tora (see edit history)
Link to comment
Share on other sites

  • 3 months later...

Hi!!

 

I work with 1.4.8.2 and Tora's modifications work perfectly with this version (Thanks!!).

I only have found one issue:

I have 3 languages in my store: spanish, english and russian.Information about customer appears correctly in all languages, including ciryllic russian (name, address, phone, ...) but names of fields are not translated. I translate them in Settings->Traductions->PDF (reference, description, slip #,...) but nothing changes. Always are in the default language of the store (spanish).

 

Can anybody help me with this?

 

Thanks a lot

Edited by betisimo76 (see edit history)
Link to comment
Share on other sites

Hi!!

 

I work with 1.4.8.2 and Tora's modifications work perfectly with this version (Thanks!!).

I only have found one issue:

I have 3 languages in my store: spanish, english and russian.Information about customer appears correctly in all languages, including ciryllic russian (name, address, phone, ...) but names of fields are not translated. I translate them in Settings->Traductions->PDF (reference, description, slip #,...) but nothing changes. Always are in the default language of the store (spanish).

 

Can anybody help me with this?

 

Thanks a lot

If you try to download invoice from back office - invoice will appear in your back office  language, except customer  details and ordered items. Change your back office language and try again.

Link to comment
Share on other sites

Fantastic Tora! You've helped me another time!
I have one last issue but I'm not sure if I must to write here. After Tora's modifications, I have installed pdfinvoiceplus from http://www.prestashop.com/forums/topic/154981-free-module-pdf-invoice-plus/ to add some text in my invoices. 
Now, every text I write appear in red color. I have tried with many html tags,included special tags of this module, but nothing change. This is an example:

 

<h1 style="color:#000;">Test TCPDF Methods in HTML</h1>
<h2 style="color:blue;">IMPORTANT:</h2>
<span style="color:blue;">If you are using user-generated content, the tcpdf tag can be unsafe.
 
You can disable this tag by setting to false the <b>K_TCPDF_CALLS_IN_HTML</b> constant on TCPDF configuration file.</span>
<h2>write1DBarcode method in HTML</h2>
<p style="color:#000;">Test TCPDF Methods in HTML</p>
<div style="color:#000;">Test TCPDF Methods in HTML</div>

 

 

Anybody can help me? Thanks a lot.

Edited by betisimo76 (see edit history)
Link to comment
Share on other sites

  • 2 months later...

Hello,

 

All has been working perfectly with Tora changes, but now, we have updated our server to php5.4 and last version TCPDF (2014-2-3), and we can't print invoices:

 

Strict Standards: Declaration of PDF_PageGroupCore::_beginpage() should be compatible with TCPDF::_beginpage($orientation = '', $format = '') in /home//classes/PDF.php on line 33

Strict Standards: Declaration of PDF_PageGroupCore::StartPageGroup() should be compatible with TCPDF::startPageGroup($page = '') in /home/classes/PDF.php on line 33

Warning: Cannot modify header information - headers already sent by (output started at /home//classes/PDF.php:33) in /home/tools/tcpdf/tcpdf.php on line 7631
TCPDF ERROR: Some data has already been output to browser, can't send PDF file

 

Somebody can help me?

 

We have v1.4.8.2

PHP5.4

TCPDF (last version 2014-2-3)

Link to comment
Share on other sites

  • 5 months later...

Prestashop 1.4.11 can not work fine with TCPDF.
 
Hello I use Prestashop 1.4.11.
And I try to fix the bug for many times but I failed.
Can somebody please upload php files for me to download?
 
And this is what I see
 
http://www.c-jade.com.tw/shoptest/pdf-invoice.php?id_order=56
 
 
==

Error message
Warning: iconv() expects parameter 3 to be string, array given in [/size]/home/cjadecom/public_html/shoptest/classes/Tools.php on line 1210
TCPDF ERROR: Some data has already been output, can't send PDF file
==
 
==
This is the Tools.php file line 1210

 public static function iconv($from, $to, $string)
{
if (_PS_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);
}

==

 

Please help me  :(

 

 

Attach files = my php files

dayday_php.zip

Link to comment
Share on other sites

For chinese user,please take a look of my attachment. The prestashop version I used is 1.4.9.0.

对简体中文用户,请下载并参考我上传的附件。里面包含了相应的修改过的文件。如想自己修改,请使用文件对比工具查看。

另,附有更新日期为2012-10-24的tcpdf_5_9_195。有文件已修改。 tcpdf_5_9_195.zip 2012-10-24

百度网盘下载地址 :http://pan.baidu.com/share/link?shareid=90170&uk=3338978994

您好連結不在了,您還有檔案嗎?

Link to comment
Share on other sites

==

Error message

Warning: iconv() expects parameter 3 to be string, array given in [/size]/home/cjadecom/public_html/shoptest/classes/Tools.php on line 1210

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

==

 

==

 

The problem is not in iconv() function but in code where this function is called.

 

In general, you are trying to mix several incompatible libraries. This is an extremely debilitating. I would suggest to upgrade to a later version of PrestaShop where some PDF problems are already solved.

  • Like 1
Link to comment
Share on other sites

The problem is not in iconv() function but in code where this function is called.

 

In general, you are trying to mix several incompatible libraries. This is an extremely debilitating. I would suggest to upgrade to a later version of PrestaShop where some PDF problems are already solved.

Thank you

Link to comment
Share on other sites

×
×
  • Create New...