News:

Looking for documentation? Take a look on our wiki

Main Menu

PDF Invoice - strange characters

Started by TheHostDogs, March 09, 2012, 19:54:44 PM

Previous topic - Next topic

TheHostDogs

When the invoice is created the characters that are included are questionmarks
It is supposed to be in greek language.

Can anyone help?
Sofoklis Pantikidis
The Host Dogs
Internet Services
Thessaloniki, Greece
info@thehostdogs.gr
www.thehostdogs.gr

osp

Hi,

unfortunatelly this is problem of TCPDF and fonts it uses by default.
Good discussion is on stack overflow, other usefull links:
http://stackoverflow.com/questions/5333702/tcpdf-utf-8-problem
http://www.tcpdf.org/fonts.php

I had similar problem with czech characters, the only solution now is to modify \libraries\joomla\document\pdf\pdf.php and add some UTF8 font to embed him in pdf.

      $pdf->SetFont('freesans');

You also need to download tcpdf from sourceforge, unpack current version and copy fonts directory from archive to joomla.
freesans should be unicode, but your PDF documents will grow by approx 700kb :(
But you can play with fonts or make your own subset...

Hope this helps, at least it clarifies some tricky pages of tcpdf...

Ondra

jjk

#2
just thought it might also be useful to have a look at the mbstring settings with phpinfo and eventually try to adjust them.
See here: http://php.net/manual/en/mbstring.configuration.php

The next link is pretty old, but it might contain a few hints on how to solve your problem, escpecially in the comments below that article.
http://developer.loftdigital.com/blog/php-utf-8-cheatsheet
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

TheHostDogs

Thanks guys for you replies..
I achieved to resolve my problem following ondrejspilka instructions..
I will write the steps that I followed in a more clear way so that everyone can do the changes..

1. Download tcpdf from this link http://sourceforge.net/projects/tcpdf/
2. Take the fonts files included in the Fonts folder of the downloaded file and I copy them to the /libraries/tcpdf/fonts
3. Open /libraries/joomla/document/pdf/fonts.php and find the line where $pdf->SetFont is written (about line 221)
4. Replace the line with something like that $pdf->SetFont('freesans', '', 6, '', 'false');
5. Find "var $_header_font" and "var $_footer_font" (about lines 32 and 33) and replace the fonts there with freesans font:
   var $_header_font = 'freesans';
   var $_footer_font = 'freesans';

Everything is OK now...

Sofoklis
Sofoklis Pantikidis
The Host Dogs
Internet Services
Thessaloniki, Greece
info@thehostdogs.gr
www.thehostdogs.gr

Artanis

Hi! Just solved my problem in the same way - wanted to post solution, but saw that You've already cracked it. :) So - simply must agree. Solution above works!
Animus Project - Design Studio
Running Joomla 2.5.6, Virtuemart 2.0.6a, PHP 5.3.10

Fonias

Thank you Sofokli!

It works great!


You are gamatos! ;)


Fotis.
Λέβητες Στερεών καυσίμων
http://levites.gr/

tserts

Guys, I'm stuck here..

I made all the above changes, my pdfs generated in the back end look fine, but the attached to the order invoices are still messed up.

What gives?

Thanx in advance.

Joomla: 2.5.7
Virtuemart 2: 2.0.12
PHP: v5.3.3

bytelord

Hi,

What exactly is messed up? The utf8 characters or someting else? What's the language your are using for your pdf's?

The same library generates ALL the pdf, so it should be a utf issue.

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

tserts

I am encoding greek fonts.

Upon investigation, I noticed that the attached to mails pdf DOES NOT have embedded the fonts, whereas the popped up from the back end invoice does. They do have about 70K difference in size so that confirms it. Have a look at the two generated files.

Non-embedded


Embedded


My option is set to false, meaning embedding should be active.

pdf.php:

$pdf->SetFont('freesans', '', 6, '', 'false');

bytelord

hello,

did you download the fonts from tcpdf?
Is working for me with greek enabled also.

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

tserts

Yes, I followed the instructions carefully,  before the fix both generated pdfs were rubbish, now the backend ones are fine but the attached to mails are as they used to be, full of question marks.

bytelord

Hi,

You could examine the core code to see how is calling the tcpdf function for creating the attached pdf's. may be change's the font.

i will give a try also

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

bytelord

#12
ok, a little bit delay but is resolved.

When order status updated from the backend or pdf invoice saved in safepath, controller runs a function that set the fonts again. So edit the file joomla_folder\components\com_virtuemart\controller\invoice.php

around lines 151, 152 change the font

$pdf->setHeaderFont(Array('freesans', '', 8 ));
$pdf->setFooterFont(Array('freesans', '', 10 ));

also around line 179, change also the font

$pdf->SetFont('freesans', '', 8, '', true);


Sorry for taking to long to respond but i was thinking that this was working, find it today while upgrading a live site. So each time you upgrade vm2 you have to change also that lines!

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

tserts

Thanks a lot mate, I had given up to be honest...

I will make the changes and report results, although I'm positive you nailed it...

Cheers!

PS: How long before text verification for every single post stops in this forum?  :P

bytelord

Hi,

Yes, test it and post the results. The difference is that view\pdf\view.pdf.php that produces the PDF in the front-end does not set fonts, so default fonts from tcpdf library are used. In the backend the font are been reset so was using the default one ...
Btw, the default fonts for tcpdf are  dejavusans, the vm developers have change them, probably to reduce the pdf file size.

PS: Not sure, i think after 7-15 posts ... something like that ...

Regards
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!