Author Topic: PDF Invoice - strange characters  (Read 24718 times)

TheHostDogs

  • Beginner
  • *
  • Posts: 17
    • The Host Dogs
PDF Invoice - strange characters
« on: March 09, 2012, 19:54:44 pm »
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

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 66
Re: PDF Invoice - strange characters
« Reply #1 on: March 13, 2012, 07:41:38 am »
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

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3447
  • using Matomo instead of Google Analytics
Re: PDF Invoice - strange characters
« Reply #2 on: March 13, 2012, 09:02:27 am »
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

  • Beginner
  • *
  • Posts: 17
    • The Host Dogs
Re: PDF Invoice - strange characters
« Reply #3 on: March 18, 2012, 19:39:46 pm »
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

  • Beginner
  • *
  • Posts: 32
  • Zusurs...
    • Animus Design Studio (coming soon)
Re: PDF Invoice - strange characters
« Reply #4 on: March 18, 2012, 19:43:26 pm »
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

  • Beginner
  • *
  • Posts: 7
    • Λέβητες Στερεών καυσίμων
Re: PDF Invoice - strange characters
« Reply #5 on: May 05, 2012, 00:19:37 am »
Thank you Sofokli!

It works great!


You are gamatos! ;)


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

tserts

  • Beginner
  • *
  • Posts: 16
Re: PDF Invoice - strange characters
« Reply #6 on: October 05, 2012, 17:26:47 pm »
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

  • Nikos
  • Global Moderator
  • Full Member
  • *
  • Posts: 2369
Re: PDF Invoice - strange characters
« Reply #7 on: October 05, 2012, 17:53:44 pm »
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

  • Beginner
  • *
  • Posts: 16
Re: PDF Invoice - strange characters
« Reply #8 on: October 05, 2012, 18:08:55 pm »
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:

Code: [Select]
$pdf->SetFont('freesans', '', 6, '', 'false');

bytelord

  • Nikos
  • Global Moderator
  • Full Member
  • *
  • Posts: 2369
Re: PDF Invoice - strange characters
« Reply #9 on: October 06, 2012, 15:28:43 pm »
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

  • Beginner
  • *
  • Posts: 16
Re: PDF Invoice - strange characters
« Reply #10 on: October 06, 2012, 15:42:22 pm »
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

  • Nikos
  • Global Moderator
  • Full Member
  • *
  • Posts: 2369
Re: PDF Invoice - strange characters
« Reply #11 on: October 07, 2012, 17:15:47 pm »
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

  • Nikos
  • Global Moderator
  • Full Member
  • *
  • Posts: 2369
Re: PDF Invoice - strange characters
« Reply #12 on: October 25, 2012, 19:32:13 pm »
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

  • Beginner
  • *
  • Posts: 16
Re: PDF Invoice - strange characters
« Reply #13 on: October 25, 2012, 21:45:23 pm »
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

  • Nikos
  • Global Moderator
  • Full Member
  • *
  • Posts: 2369
Re: PDF Invoice - strange characters
« Reply #14 on: October 25, 2012, 22:28:41 pm »
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!