VirtueMart Forum

VirtueMart 2 + 3 => General Questions => Topic started by: TheHostDogs on March 09, 2012, 19:54:44 pm

Title: PDF Invoice - strange characters
Post by: TheHostDogs 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.
(http://www.trazeras.gr/pdf.png)
Can anyone help?
Title: Re: PDF Invoice - strange characters
Post by: osp 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
Title: Re: PDF Invoice - strange characters
Post by: jjk 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 (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 (http://developer.loftdigital.com/blog/php-utf-8-cheatsheet)
Title: Re: PDF Invoice - strange characters
Post by: TheHostDogs 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
Title: Re: PDF Invoice - strange characters
Post by: Artanis 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!
Title: Re: PDF Invoice - strange characters
Post by: Fonias on May 05, 2012, 00:19:37 am
Thank you Sofokli!

It works great!


You are gamatos! ;)


Fotis.
Title: Re: PDF Invoice - strange characters
Post by: tserts 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
Title: Re: PDF Invoice - strange characters
Post by: bytelord 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
Title: Re: PDF Invoice - strange characters
Post by: tserts 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
(http://i.imgur.com/Yp2Nd.jpg)

Embedded
(http://i.imgur.com/qkQom.jpg)

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

pdf.php:

Code: [Select]
$pdf->SetFont('freesans', '', 6, '', 'false');
Title: Re: PDF Invoice - strange characters
Post by: bytelord 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
Title: Re: PDF Invoice - strange characters
Post by: tserts 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.
Title: Re: PDF Invoice - strange characters
Post by: bytelord 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
Title: Re: PDF Invoice - strange characters
Post by: bytelord 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
Title: Re: PDF Invoice - strange characters
Post by: tserts 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
Title: Re: PDF Invoice - strange characters
Post by: bytelord 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
Title: Re: PDF Invoice - strange characters
Post by: tserts on October 25, 2012, 22:45:36 pm
Thanks again, tonight for some reason my net speeds are very slow and it's a pain to perform more tests, I did two test orders and I got NO pdf attached to mails and, to add insult to injury, my backend generated pdfs from the order list are now messed up as well (the usual question marks). I will look into that tomorrow, I have to clean caches, chown some files (I edit as root sometimes for speed along many sites and some folders are sensitive to ownership) and re-run the tests, on top of all that I have upgraded vm versions since posting the first post and I can't know if something else is causing this..

I will update tomorrow after making everything is as it should..
Title: Re: PDF Invoice - strange characters
Post by: bytelord on October 26, 2012, 00:46:30 am
Try with dejavusans both in vm admin and tcpdf

joomla_folder\components\com_virtuemart\controller\invoice.php around lines 151, 152 change the font

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

also around line 179, change also the font

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

------


libraries\joomla\document\pdf\pdf.php around lines 32 and 33

var $_header_font = 'dejavusans';
var $_footer_font = 'dejavusans';

around line 222
   $pdf->SetFont('dejavusans', '', 8, '', 'false');

Regards
Title: Re: PDF Invoice - strange characters
Post by: tserts on October 28, 2012, 21:42:22 pm
Ok, I made all the above changes and my backend generated pdfs are once again OK, I still don't get attached pdfs Ι'm afraid during the last update some root-owned files (my bad) were not updated, I will wait for the next update which will happen after a chown -R and try again. I don't think there are other places to look into, those two files are where the problem is (one for the email attachments and one for the back end), but I will post as soon as I have a solid set of files by version.
Title: Re: PDF Invoice - strange characters
Post by: tserts on October 28, 2012, 21:59:35 pm
Ok FIXED.

I had to change the "statuses to send  invoice" in configuration they were empty for some reason.

The attached pdf was as it should, perfectly readable.

Thanks a lot for your help Bytelord!!
Title: Re: PDF Invoice - strange characters
Post by: autarh on August 25, 2013, 22:23:08 pm
problem after update to 2.0.22b

before update everything worked fine, after update same situation instead UTF8 characters i have "?" ... any solution ?
Title: Re: PDF Invoice - strange characters
Post by: tserts on September 27, 2013, 13:50:59 pm
Same here with a new site for a client, the documents have changed, I can't even find the same fields...

Shop>invoices now has a default font selection menu but I have no available fonts to choose...

Title: Re: PDF Invoice - strange characters
Post by: tserts on September 27, 2013, 13:57:25 pm
Must be here, in vmpdf.php, so if I could set it in the front end it should work..

Code: [Select]
$vmFont=$this->vendor->vendor_letter_font;
$this->SetFont($vmFont, '', $this->vendor->vendor_letter_font_size, '', 'false');                 
$this->setHeaderFont(Array($vmFont, '', $this->vendor->vendor_letter_header_font_size ));
$this->setFooterFont(Array($vmFont, '', $this->vendor->vendor_letter_footer_font_size ));
Title: Re: PDF Invoice - strange characters
Post by: tserts on September 27, 2013, 17:32:00 pm
OK, fixed it.

After I messed it up beyond hope, I re-installed the newest component, then aio, then updated the tables. Magically, after all that, I had a UTF-8 font on the drop down menu on the backend, which, when selected, worked as it should, both front and back end.
Title: Re: PDF Invoice - strange characters
Post by: BaidareW on October 15, 2013, 21:45:38 pm
Hello,

 downloaded fonts, changed pdf.php as described but my Lithuanian text in PDF is still with ?? characters when pressing in back end.

And I can't find fonts line in file \components\com_virtuemart\controller\invoice.php so maybe this is the problem ?

Using 2.0.22x version of virtuemart.
Title: Re: PDF Invoice - strange characters
Post by: BaidareW on October 22, 2013, 13:57:59 pm
Any one :) ?
Title: Re: PDF Invoice - strange characters
Post by: WebWorx on November 19, 2013, 08:12:10 am
Did anyone get this method to work on the newer version of VM? I am having problems with the PDF invoice and Hebrew... getting question marks to come up where it should say (in Hebrew) Name, Address, Date, City, State, etc. the data for the customer - ie. the actual name, address is in there but just the labels show up as ????.... I posted my issue here... and I tried the suggestions I have found on these threads with no success.... Here is the thread with more info - http://forum.virtuemart.net/index.php?topic=120243.msg409539#msg409539
Title: Re: PDF Invoice - strange characters
Post by: dbcig2013 on December 22, 2013, 14:16:12 pm

hi,

in my case ( japanese character) , this workaround does not work.

i correctly loaded the freesans font in joomla library, but it seems the modification of pdf.php ( /libraries/joomla/document/pdf/)   and invoice.php (components\com_virtuemart\controller\invoice.php) do not change the font in generated pdf file

if i have a look in the properties of generated invoice, the default font is not freesans as it should

nb: fonts.php does not exist. instead i have pdf.php
Title: Re: PDF Invoice - strange characters
Post by: dbcig2013 on December 22, 2013, 14:50:28 pm

hi,

in my case ( japanese character) , this workaround does not work.

i correctly loaded the freesans font in joomla library, but it seems the modification of pdf.php ( /libraries/joomla/document/pdf/)   and invoice.php (components\com_virtuemart\controller\invoice.php) do not change the font in generated pdf file

if i have a look in the properties of generated invoice, the default font is not freesans as it should

nb: fonts.php does not exist. instead i have pdf.php

[attachment cleanup by admin]
Title: Re: PDF Invoice - strange characters
Post by: its4yougr on September 19, 2014, 19:48:27 pm
It works Great for me too.
Greek Characters
Joomla 2.5.24
VM 2.6.6

The only difference is that the file is pdf.php

Thanks a lot
Title: Re: PDF Invoice - strange characters
Post by: tzaris on September 23, 2014, 21:47:50 pm
i tried a lot of times with the changes but i was still getting the question marks ??
i solved it by doing the most easy step , delete the invoices in the safe path and
i finally get to see greek characters.
Joomla 2.5.25
VM 2.6.6
Title: Re: PDF Invoice - strange characters
Post by: jordanken22 on September 24, 2014, 08:25:51 am
i tried a lot of times with the changes but i was still getting the question marks ??
i solved it by doing the most easy step , delete the invoices in the safe path and
i finally get to see greek characters.
Joomla 2.5.25
VM 2.6.6

Good for you.  I've been having this issue for a long time now and tried getting a solution for it awhile back but failed.  Tried following every fix in this thread including deleting the invoices (though I was a bit hesitant at first but decided to since i had no other options left) but still not seeing any results.  Do you guys have any other links to help me out on this? Much appreciate any help.
Title: Re: PDF Invoice - strange characters
Post by: rage76 on February 13, 2015, 20:20:27 pm
I have tried everything in this thread. after changing invoice font frmo VM backend to UTF-8, it now shows a "square box" instead of the earlier "?"

font changed to "dejavusans"

where am I wrong?

Joomla 2.5.22
VM: 2.6
Title: Re: PDF Invoice - strange characters
Post by: Garyk01 on March 28, 2015, 18:15:41 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
Hi!
To Russian and Ukrainian languages picked fonts:
Open file \libraries\joomla\document\pdf\pdf.php
find and change to
Code: [Select]
var $_header_font = 'dejavusans';
var $_footer_font = 'dejavusans';
Code: [Select]
$pdf->SetFont('dejavusanscondensed', '', 8, '', 'false');
Joomla 3.4.1 + VM 3.0.6.4
Title: Re: PDF Invoice - strange characters
Post by: Milbo on March 30, 2015, 02:47:52 am
Actually I wonder why this hack is still necessary. There is an option in vendor pdf tab for the font, which affects also the header and footer font

Code: [Select]
$vmFont=$this->vendor->vendor_letter_font;
$this->SetFont($vmFont, '', $this->vendor->vendor_letter_font_size, '', 'false');                 
$this->setHeaderFont(Array($vmFont, '', $this->vendor->vendor_letter_header_font_size ));
$this->setFooterFont(Array($vmFont, '', $this->vendor->vendor_letter_footer_font_size ));

So maybe you hunt ghosts?
Title: Re: PDF Invoice - strange characters
Post by: Garyk01 on March 30, 2015, 23:05:48 pm
Help me please!
In which file or in which tabs "Configuration" I should write this code?
Title: Re: PDF Invoice - strange characters
Post by: Milbo on March 31, 2015, 01:28:31 am
You dont need to write any code. Open your shop config (not vm config) and edit the invoice settings there.
Title: Re: PDF Invoice - strange characters
Post by: Garyk01 on March 31, 2015, 21:53:14 pm
 Okay! For invoices - select the font: Virtuemart->Shop->tab Invoices/Emails -> Default Font = Free Mono (UTF-8 Unicode)

But only this hack (written above) helps when you export the item description in pdf. 
May be you have other variant for export in pdf?
Title: Re: PDF Invoice - strange characters
Post by: rage76 on April 16, 2015, 18:35:04 pm
Again, I am on Joomla 2.5.28 & VM 2.6 and I am clueless what I am doing wrong !!
Tried everything. Seems there is no solution to this? :(
Title: Re: PDF Invoice - strange characters
Post by: Milbo on April 17, 2015, 08:44:47 am
What you do wrong is to read an old thread

"March 09, 2012" , this means that almost anything here is outdated. The problem is solved in vm2.6 and vm3. It is very likely that you have another problem.
Title: Re: PDF Invoice - strange characters
Post by: rage76 on April 23, 2015, 18:38:59 pm
any suggestions on what I can try to set this right?
Title: Re: PDF Invoice - strange characters
Post by: nick-gr on November 10, 2015, 19:32:13 pm
Actually I wonder why this hack is still necessary. There is an option in vendor pdf tab for the font, which affects also the header and footer font

Code: [Select]
$vmFont=$this->vendor->vendor_letter_font;
$this->SetFont($vmFont, '', $this->vendor->vendor_letter_font_size, '', 'false');                 
$this->setHeaderFont(Array($vmFont, '', $this->vendor->vendor_letter_header_font_size ));
$this->setFooterFont(Array($vmFont, '', $this->vendor->vendor_letter_footer_font_size ));

So maybe you hunt ghosts?
Hello, if I open shop settings->Invoice tab->appearance->default fonts there is no fonts, only Select an Option. Any idea how can I add fonts?
Title: Re: PDF Invoice - strange characters
Post by: Milbo on November 10, 2015, 20:57:00 pm
When you updated all the time, you may did not get the fonts. download the last tcpdf installer http://dev.virtuemart.net/projects/tcpdf/files
Title: Re: PDF Invoice - strange characters
Post by: WilfredP on August 05, 2016, 04:52:28 am
Hi all, does any one get solution for this?

I'm using Joomla 3x and VM3, I tried:
1. Change pdf.php setfont
2. Change default font via backend
3. Clear safe path invoice

But traditional chinese character not showing up still. Hope to get solution. Thanks!