Jump to content

[patch] classes/PDF.php


rush

Recommended Posts

Hello, guys, it's me again.  ;)

 

I realized that I have to patch file classes/PDF.php to support other encodings than the default iso-8859-1. Czech language needs cp1250 (or iso-8859-2) as we use a lot of strange characters. :-D Sadly, FPDF doesn't support UTF-8, so I made brand new cp1250 fonts and modified classes/PDF.php to use them when needed. I also attached czech translation.

 

You may review it at http://labs.logic.cz/patches/prestashop-0.9.7/invoices.patch. I hope it's now more generic solution.

 

The fonts can be downloaded here http://labs.logic.cz/patches/prestashop-0.9.7/fonts-cp1250.tar.gz.

 

Link to comment
Share on other sites

Ok, just another Quick&Dirty hack

 

Original patched file classes/PDF.php line 195

 

                self::$currency = new Currency(intval(self::$order->id_currency));

 

Patched patched :-D file classes/PDF.php line 195

 

                self::$currency = new Currency(intval(self::$order->id_currency));

                self::$currency->sign = iconv('utf-8', self::encoding(), self::$currency->sign);

 

You may download the whole damn thing at http://labs.logic.cz/patches/prestashop-0.9.7/invoices-v2.patch :-)

 

Enjoy!

Link to comment
Share on other sites

Hi,

 

I made some modifications to /classes/PDF.php and /admin/tabs/AdminTranslations.php to enable PDF translations in BackOffice

Here are the modifications:

1. PDF.php:

- Removed private variable $_translations

- Replaced protected function l($string) with a new one

2. AdminTranslations.php:

- Added pdf translations file to language export

- Modified public function postProcess() to save pdf translations in /translations/{language}/pdf.php

- Modified public function display() to display a link to PDF translations page

- Added function displayFormPDF() which displays all PDF labels to translate

 

All modifications are marked with //ZKOEV.

 

There are some outstanding issues which I'm going to work on soon:

1. Remove private static $_pdfparams from PDF.php and store PDF encoding/font settings in config file

2. Manage PDF encoding/font settings in Tools->Preferences page.

3. Copy pdf translations when copying a language

 

Please test the pdf module and share any ideas you have.

* Note that PDF.php $_pdfparams is set for BG language, encoding and font. Change it with you local language.

PDF.php

AdminTranslations.php

Link to comment
Share on other sites

Hi,

 

To manage PDF encoding/font settings I added a new tab 'PDF Invoice' (look at the screenshot) and added a pdf icon called 44.gif (44 is the id of the new tab) to /img/t folder.

Here are the new modifications to the files:

1. New file /admin/tabs/AdminPDF.php - allows encoding and font management in BackOffice -> Preferences -> PDF Invoice tab.

Encoding is set to configuration table as PS_PDF_ENCODING_{language} for the current language .

Font is set to configuration table as PS_PDF_FONT_{language} for the current language .

2. Modified /classes/PDF.php - read configuration from database

3. Modified /admin/tabs/AdminTranslations.php - copy pdf translations when copying a language.

 

All modifications are markeed with //ZKOEV v2

 

Regards,

Zhivko

377_dRIOJnQ59sCDGMMunC75_t

PDF.php

AdminPDF.php

AdminTranslations.php

Link to comment
Share on other sites

  • 2 weeks later...

Hi Zhivko,

 

I was following your instructions, copied your files to right locations, added the pdf tab, translated pdf, but I keep getting the following error:

 

"FPDF error: Could not include font definition file"

 

What am I doing wrong?

 

BTW, I am trying to translate pdf in Croatian/Bosnian/Serbian (latin script)

 

Encoding is ISO-8859-2.

 

It is all pretty greek to me, so if you could speek human I would appreciate.

 

 

Link to comment
Share on other sites

Hi,

 

Look at the third post in this topic. Rush says:

I followed this tutorial: http://www.fpdf.org/en/tutorial/tuto7.htm

 

Here you can prepare your fonts: http://fpdf.fruit-lab.de/

 

You have to prepare a definition file for your prefered font and encoding and place it in /tools/fpdf/fonts folder.

 

PS: You need definition files for regular and bold font type. PDF invoice uses both. For ex. times and timesb.

Link to comment
Share on other sites

  • 2 weeks later...

ok. In catalog fonts I have files:

879598_arial.php 4,1 k 2008-03-22 11:06 ----

879598_arial.t1a 1,1 M 2008-03-22 11:07 ----

879598_arial.z 193,2 k 2008-03-22 11:06 ----

879598_arial.afm 104,9 k 2008-03-22 11:06 ----

879598_arialb.php 4,1 k 2008-03-22 11:09 ----

879598_arialb.t1a 1,1 M 2008-03-22 11:09 ----

879598_arialb.z 193,2 k 2008-03-22 11:09 ----

879598_arialb.afm 104,9 k 2008-03-22 11:09 ----

[..]

In admin tab I choose 879598_arial and ISO-8859-2.

Now I got error 500

What's wrong ??

Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...
  • 1 year later...

ok. In catalog fonts I have files:

879598_arial.php 4,1 k 2008-03-22 11:06 ----

879598_arial.t1a 1,1 M 2008-03-22 11:07 ----

879598_arial.z 193,2 k 2008-03-22 11:06 ----

879598_arial.afm 104,9 k 2008-03-22 11:06 ----

879598_arialb.php 4,1 k 2008-03-22 11:09 ----

879598_arialb.t1a 1,1 M 2008-03-22 11:09 ----

879598_arialb.z 193,2 k 2008-03-22 11:09 ----

879598_arialb.afm 104,9 k 2008-03-22 11:09 ----

[..]

In admin tab I choose 879598_arial and ISO-8859-2.

Now I got error 500

What's wrong ??

 

I'm having the same problem :-( Did you find the solution eventually? Thank you.

 

UPDATE: Problem solved! This happened to me after update from 1.4.0.17 to 1.4.4.1. In my new shop, I used a PDF.php file from my previous version. This PDF.php from my old version contained a custom-made command for "payment due" which was defined in Tools.php. The problem was that I forgot to copy the string from my old Tool.php to the new one, so the PDF could not receive the data and so gave me this error. :-))

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...