Accented characters do not print

Accented characters do not print

by Pauline Dumont -
Number of replies: 27

Hi,

I am using the certificate add-on on Moodle 2.4.

I have created a new certificate type, so a new config.php file in order to customize the appearance and the labels that will appear in the certif.

Everything works fine, except when I want to print strings containing accented characters (à, é, è...). Then the entire string does not appear in the certif, not only the character itself.

The pdf is defined as UTF-8:

$pdf = new TCPDF($certificate->orientation, 'mm', 'Letter', true, 'UTF-8', false);

...

$text = 'a terminé avec succès la formation';
certificate_print_text($pdf, $x, $line_y, 'C', 'Helvetica', 'B', 14, $text);

 

Would you have any idea to resolve this?

I tried to despecialize the characters using '\' (ex: 'termin\é'), but it did not work.

Thanks in advance!

Average of ratings: -
In reply to Pauline Dumont

Re: Accented characters do not print

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

HI Pauline,

This is an issue with the TCPDF library, not the certificate module. For help please see http://stackoverflow.com/questions/4141865/tcpdf-html-with-special-characters-displays-empty-pdf-file

Hope this helps,

Mark.

In reply to Mark Nelson

Re: Accented characters do not print

by Pauline Dumont -

Hi Mark!

Thanks for this!

Actually, the proposed solution works for texts that are "handwritten" in the php file. But then it alters the special characters contained in the variables, like in the course title for instance.

So I would need a solution that works for both. Maybe there exists a function to apply to the variable?

Thanks again

In reply to Pauline Dumont

Re: Accented characters do not print

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Pauline,

When you are viewing the course full name on the course page are these characters showing?

If the TCPDF library can print out hard coded strings in the php file that contain accented characters, then it should also be able to print the course full name with these characters as well as it is simply pulls this from the database.

When you print the course name are you simply doing something similar to certificate_print_text($pdf, $x, $y + 72, 'C', 'Helvetica', '', 20, $course->fullname)?

Regards,

Mark

In reply to Mark Nelson

Re: Accented characters do not print

by Pauline Dumont -

Hi Mark,

thanks for your help.

Yes, this is exactly it. Here is the statement I am using:

$text = $course->fullname;
certificate_print_text($pdf, $x, $line_y, 'C', 'Helvetica', 'BI', 24, $text);

And in the Moodle interface itself, the accented characters are correctly displayed.

In Moodle: 'Introduction à la gestion des OOS'

In the PDF certificate: 'Introduction à la gestion des OOS'

In reply to Pauline Dumont

Re: Accented characters do not print

by Pauline Dumont -

Hi there,

I'm still struggling with this issue...

Would anyone have an idea?

Could it be that the encoding in the Moodle database itself is not the appropriate one?

 

Thanks in advance for your support!

In reply to Pauline Dumont

Re: Accented characters do not print

by Pauline Dumont -

Hello,

I forgot to mention that, when the pdf was defined as UTF-8 (see below), then the Mood variables were showing the accented characters correctly, and the text strings defined within the config .php file not.

$pdf = new TCPDF($certificate->orientation, 'mm', 'Letter', true, 'UTF-8', false);

 

Now that I have changed the PDF to ISO (see below), it's the contrary; the text strings defined in the config file are correctly displayed but the Moodle variables not.

$pdf = new TCPDF($certificate->orientation, 'mm', 'Letter', false, 'ISO-8859', false);

 

I hope this helps!

Thanks in advance for any idea.

In reply to Pauline Dumont

Re: Accented characters do not print

by Jean-Michel Védrine -

Hello,

I am sorry but I don't think that changing 'UTF-8' to 'ISO-8859' was a good idea. I think it was in fact a very bad idea !

Moodle use UTF-8 encoding everywhere so you should also use UTF-8 everywhere in the certificate module !

If you have a problem with the strings contained in one of your php files this is most likely because this file was not saved as UTF-8 text file

My suggestion:

  1. revert your change and restore the line to
    $pdf = new TCPDF($certificate->orientation, 'mm', 'Letter', true, 'UTF-8', false);
  2. look at your customized certificate in mod/certificate/type and ensure that each mod/certificate/type/xxxx/certificate.php file is saved using UTF-8 encoding and that the characters in each string is correctly displayed when you open it as UTF-8 encoding. The right way to do that depends on the software you use to edit text files, I can help you more if needed but you need to tell me what software you use to edit text files
  3. don't use any HTML entity starting with the ampersand character and ending with semi colon when you write the strings in your customized certificates, write all accented characters as you would usually: é, à, ... and not é or à. For instance write $text = 'a terminé avec succès la formation'; and not $text = 'a terminé avec succès la formation';

Explanation: 1. is to ensure strings stored in the database are correctly printed and 2. and 3; are to ensure that strings defined in your customized certificate are correctly handled

Being french (and many french words have accented characters like é, è, à, ù) I can testify that Moodle, certificat and TCPDF library are all perfectly able to handle UTF-8 encoded strings as long as it is used everywhere but that you will most likely get missing strings if you mix encoding or use an encoding different in the "new TCPDF" instruction and in your strings

If you are in doubt if your customized certificate is a correct UTF-8 encoded text file, you can post it and I will verify it.

Average of ratings: Useful (1)
In reply to Jean-Michel Védrine

Re: Accented characters do not print

by Pauline Dumont -

Hi Jean-Michel, and thanks a lot for the proposed solution, which sounds perfectly logical... and that I had already tried actually.

And I received another type of error, linked to TCPDF. The certificate was not generated at all, I only got a blank page in Moodle, instead of the one with the "download certificate" button.

After some research on the Internet, I found out that it was due to the fact that TCPDF does not support config files in any other encoding than ANSI.

See this link

When I switched back to UTF-8, it worked again... but still my problem remained. Maybe there is a solution to the TCPDF issue?

In reply to Pauline Dumont

Re: Accented characters do not print

by Jean-Michel Védrine -

Hello Pauline,
Believe me, I use TCPDF not only in Moodle but in other programs that I developed and all of them have to print french texts with accented characters like éçàù and I use UTF-8 everywhere.
You say : "I found out that it was due to the fact that TCPDF does not support config files in any other encoding than ANSI". I think you are misinterpreting this information: it is true that TCPDF config files must be ANSI encoded but theses files are in lib/tcpdf/config.
Your own customized certificates files in mod/certificate/type can be UTF-8 encoded with absolutely no problem !
Also the link given in your message is about quite a different problem : if any character is output (either by Moodle, TCPDF, your own scripts or anything) before the pdf file is send, you will get the "Some data has already been output, can't send PDF file".
But this remind me of a very important thing: when you save your UTF-8 customized certificate php file, it is very important that you save it as "UTF-8 encoded without BOM" (BOM means Byte Order Mark see wikipedia).
Because if you save it as UTF-8 with BOM (some microsoft editors are prone to do that, I use notepad ++ and have no problem as it offers me the choice with/without BOM) there will be some extra characters at the beginning of the file before the "<?php" and they will create big problems, including the "some data has already been output, can't send..." problem.
I am quite sure of all the informations above so if something is not working (for instance if you get a blank page) set debugging level to DEVELOPER in site administration, and redo the things that were causing the blank page to see if any error message is displayed.
If there is any error message, post it here so that I can help you.
Also if you want to send me your customized certificate file so that I can verify it is correctly encoded, no problem. If you can't find my mail, send me a PM.

Average of ratings: Useful (2)
In reply to Jean-Michel Védrine

[RESOLVED] Accented characters do not print

by Pauline Dumont -

Hi Jean-Michel,

This is it!!! How great, my problem is now solved! I was missing the 'without BOM' detail.

Thanks a million Jean-Michel, you definitely made my day!

In reply to Pauline Dumont

Re: [RESOLVED] Accented characters do not print

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Jean-Michel to the rescue yet again, thanks!

In reply to Jean-Michel Védrine

Re: Accented characters do not print

by Dolly Miglani -

Hello Pauline,

My Unicode characters for moodle certificate pdf are not working. I followed all the instructions above but not getting any result. Please help me , i want to print unicode characters(çÇğĞüÜöÖıIşŞ) in certificate.

 

Thanks in advance!

In reply to Dolly Miglani

Re: Accented characters do not print

by Pauline Dumont -

Hi Dolly,

personally, saving the UTF-8 customized certificate php file as "UTF-8 encoded without BOM" using Notepad++ really was the solution to my problem.
Are you sure you did this? Pay attention that, when you change the encoding of your file, the special characters may change in it. You will have to rewrite them correctly within the file before saving and uploading your config file.

 

In reply to Pauline Dumont

Re: Accented characters do not print

by Dolly Miglani -

Hello Pauline,

 

I have already tried to save the UTF-8 customized certificate.php file as "UTF-8 encoded without BOM" using Notepad++. Because My notepad is taking this format "UTF-8 encoded without BOM" by default .

 

Thanks,

In reply to Dolly Miglani

Re: Accented characters do not print

by Jean-Michel Védrine -

Hello Dolly,

What is your Moodle version ?

In reply to Jean-Michel Védrine

Re: Accented characters do not print

by Dolly Miglani -

Hi Jean-Michel Védrine,

My moodle version is 2.4. if you know how can i resolve the issue, please let me know asap.

Thanks in advance.

In reply to Dolly Miglani

Re: Accented characters do not print

by Jean-Michel Védrine -

If you are using Moodle 2.4 with a recent version of the certificate plugin and if your customized certificate is a syntactically correct and UF-8 without Byte Order Mark encoded file I am 100% sure that all accented would print.

  • Could you verify that the file used on your server is really the one you think (this seems stupid, but such a mistake has happened to me several times big grin)
  • Can you send me this file (either upload it on his forum or if this is impossible mail it to me)
In reply to Jean-Michel Védrine

Re: Accented characters do not print

by Pauline Dumont -

Hi Dolly,

sorry for the late answer.
I made a test and to me as well, all of the characters you mentioned do not print. I didn't see that before because these are not used very often in the French language.

 

So for the set 'çÇğĞüÜöÖıIşŞ', see in the screenshot what is displayed with my configuration.

 

I hope this helps.

Pauline

Attachment 2013-07-31_08h42_49.png
In reply to Pauline Dumont

Re: Accented characters do not print

by Dolly Miglani -

Hi Pauline Dumont,

Yes, the same problem is occuring at my end during print the certificate pdf.

 

 

In reply to Dolly Miglani

Re: Accented characters do not print

by Jean-Michel Védrine -

Hello Dolly,

Sorry, I missed some of your characters.

I can confirm that if I use your sample string 'çÇğĞüÜöÖıIşŞ', characters 'ğĞıIşŞ' fail to print (both if they are used in the code of the customized certificate or entered in the "custom text" field)

So that I can study the problem can you tell me in what language these characters are used and their names (unicode name would be perfect)

In reply to Jean-Michel Védrine

Re: Accented characters do not print

by Dolly Miglani -

Hi  Jean-Michel Védrine ,

I have customized the certificate.php & also done changes from language settings as well as i picked the code of these characters from google but not able to print these characters. I am using these unicode characters for Turkish langauge.

Please provide me a solution for this. I shall be very thankful to you for this.

Dolly

In reply to Dolly Miglani

Re: Accented characters do not print

by Jean-Michel Védrine -

Hello Dolly,

The problem only happen if you use fonts like Times or Helvetica, but all characters will print correctly if you use the freeserif (looks like Times) or freesans (looks like Helvetica) or dejavusans fonts.

For instance

certificate_print_text($pdf, $x+100, $y + 102, 'C', 'freeserif', '', 10, 'çÇğĞüÜöÖıIşŞ');

will print perfectly

Average of ratings: Useful (1)
In reply to Jean-Michel Védrine

Re: Accented characters do not print

by Dolly Miglani -

Hi Jean-Michel Védrine,

I have tried your solution many times but now the problem with my certificate is that  now it is displaying blank spaces instead of printing unicode characters set or my previous ? marks. here is the code of my certificate file please see what is the problem is in my file.

Please help me !!!!

 

Thanks in Advance,

Dolly

 

In reply to Dolly Miglani

Re: Accented characters do not print

by Dolly Miglani -

NOT able to get the certificate on quiz restriction to get minimum grades

In reply to Dolly Miglani

Re: Accented characters do not print

by Jean-Michel Védrine -

Hello Dolly,

Sorry, I had not looked at that thread so I didn't saw your file.

For me it's working perfectly and characters are printed as expected

See this screenshot in acrobat reader

certificate

the blue line is produced by

$textn = 'This is text hardcoded in certificate: çÇğĞüÜöÖıIşŞ';
certificate_print_text($pdf, $x, $y, 'C', 'freeserif','', 30, $textn);

And the line at the bottom is produced by

certificate_print_text($pdf, $custx, $custy, 'C', 'freeserif','' , 25, $certificate->customtext);

Of course I have typed "This is customtext: çÇğĞüÜöÖıIşŞ" when I created the certificate.

So no problem for me. I don't understand why it is not working for you.

In reply to Jean-Michel Védrine

Re: Accented characters do not print

by aditya singh -

Hello Jean- Michel,

Thanks for your detailed description for understanding this issue, so far your solution works for me now I am using "freeserif" font instead of "Helvetica", also I would like to know more about these font types and their effect on moodle application so if you have any reference then please share with us.

Once again a big thanks smile

In reply to Pauline Dumont

Re: Accented characters do not print

by John Sims -

I have run into this problem with various language packs. The language pack has the correct translation, including the specially accented characters. When the certificate was generated, however, I found those characters were replaced by question marks ("?"). This was because those characters were not available in the font in which they were displayed.

In digging in the moodle/mod/certificate/language/en/certificate.php file, I found the following note:

The non-embedded types use the Helvetica and Times fonts.  If you feel your users will not have these fonts on their computer, or if your language uses characters or symbols that are not accommodated by the Helvetica and Times fonts, then choose an embedded type.  The embedded types use the Dejavusans and Dejavuserif fonts.  This will make the pdf files rather large; thus it is not recommended to use an embedded type unless you must.

I switched to a non-embedded type for the certificate for those languages and the characters were displayed properly.