Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2446 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  [PHP] tcpdf / script bookmark et utf8

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[PHP] tcpdf / script bookmark et utf8

n°1587769
simogeo
j'ai jamais tué de chats, ...
Posté le 17-07-2007 à 17:11:26  profilanswer
 

hello,
 
je viens de migrer une application sous utf8.
Pour générer du pdf, j'ai donc passer mon script depuis fpdf (pas de support utf8) vers tcpdf (qui lui,le supporte).
 
J'utilise le script Signets pour générer mes bookmarks.
http://www.fpdf.org/fr/script/script1.php
 
Toutefois, j'ai un bug sur les caractères accentués extraits de ma DB (mysql/pgsql). Ok sur les mots accentués issus d'un fichier texte.
 
Une idée du problème?
merci [:john keats]


---------------
from here and there -- \o__________________________________ -- la révolution de la terre, en silence
mood
Publicité
Posté le 17-07-2007 à 17:11:26  profilanswer
 

n°1587817
simogeo
j'ai jamais tué de chats, ...
Posté le 17-07-2007 à 18:46:44  profilanswer
 

ouhouhhhhhh [:itm]


---------------
from here and there -- \o__________________________________ -- la révolution de la terre, en silence
n°1587843
bixibu
Ca ... c'est fait!
Posté le 17-07-2007 à 20:12:02  profilanswer
 

utf8_decode ou utf8_encode
 
vive la doc PHP et google

n°1587898
simogeo
j'ai jamais tué de chats, ...
Posté le 18-07-2007 à 01:07:07  profilanswer
 

n'importe quoi ......


---------------
from here and there -- \o__________________________________ -- la révolution de la terre, en silence
n°1587933
Koyomi
www.sebastiengilles.com
Posté le 18-07-2007 à 09:06:30  profilanswer
 

bixibu a écrit :

utf8_decode ou utf8_encode
 
vive la doc PHP et google


Réponse a coté de la plaque  :sarcastic:  
 
simogeo, je ne connais pas tcpdf mais quel est l'encodage de tes tables ?

n°1587934
bixibu
Ca ... c'est fait!
Posté le 18-07-2007 à 09:09:18  profilanswer
 

n'importe quoi?
 
a part ut8_decode/encode et htmlentities je vois pas de quoi tu pourrait avoir besoin d'autre... j'ai fais exactement la meme chose avec ezPDF ...

n°1587946
Koyomi
www.sebastiengilles.com
Posté le 18-07-2007 à 09:30:21  profilanswer
 

bixibu a écrit :

n'importe quoi?
 
a part ut8_decode/encode et htmlentities je vois pas de quoi tu pourrait avoir besoin d'autre... j'ai fais exactement la meme chose avec ezPDF ...


Citation :

Toutefois, j'ai un bug sur les caractères accentués extraits de ma DB(mysql/pgsql). Ok sur les mots accentués issus d'un fichier texte.
 


Le problème est probablement plus du coté DB

n°1587963
rufo
Pas me confondre avec Lycos!
Posté le 18-07-2007 à 09:50:02  profilanswer
 

on peut imaginer que sa bd est en latin1...et pas utf8

n°1587967
simogeo
j'ai jamais tué de chats, ...
Posté le 18-07-2007 à 09:54:49  profilanswer
 

Koyomi a écrit :


Réponse a coté de la plaque  :sarcastic:  
 
simogeo, je ne connais pas tcpdf mais quel est l'encodage de tes tables ?


 
utf-8! Et je n'ai pas de problème pour afficher ces variables au coeur du pdf.
Le problème est se trouve sur le bookmark et l'index...
j'ai checké rapidement le code mais je ne vois pas d'ou cela peut venir.


---------------
from here and there -- \o__________________________________ -- la révolution de la terre, en silence
n°1587981
Koyomi
www.sebastiengilles.com
Posté le 18-07-2007 à 10:19:57  profilanswer
 

le seul endroit ou il pourrais y avoir un problème c'est la :

 
Citation :

$this->_out('<</Title '.$this->_textstring($o['t']));

 

et vu le source de cette fonction :

 
Citation :


3158          /**
3159          * Format a text string
3160          * @access protected
3161          */
3162          function _textstring($s) {
3163              if($this->isunicode) {
3164                  //Convert string to UTF-16BE
3165                  $s = $this->UTF8ToUTF16BE($s, true);
3166              }
3167              return '('. $this->_escape($s).')';
3168          }

 

cf : http://xref.moodle.org/nav.html?_functions/index.html

 

c'est peut etre la conversion UTF8ToUTF16BE qui pose soucis.

 

Voici la definition de cette fonction :

 
Citation :


3394           /**
3395           * Converts UTF-8 strings to UTF16-BE.<br>
3396           * Based on: http://www.faqs.org/rfcs/rfc2781.html
3397           * <pre>
3398           *   Encoding UTF-16:
3399           *
3400           *   Encoding of a single character from an ISO 10646 character value to
3401           *    UTF-16 proceeds as follows. Let U be the character number, no greater
3402           *    than 0x10FFFF.
3403           *
3404           *    1) If U < 0x10000, encode U as a 16-bit unsigned integer and
3405           *       terminate.
3406           *
3407           *    2) Let U' = U - 0x10000. Because U is less than or equal to 0x10FFFF,
3408           *       U' must be less than or equal to 0xFFFFF. That is, U' can be
3409           *       represented in 20 bits.
3410           *
3411           *    3) Initialize two 16-bit unsigned integers, W1 and W2, to 0xD800 and
3412           *       0xDC00, respectively. These integers each have 10 bits free to
3413           *       encode the character value, for a total of 20 bits.
3414           *
3415           *    4) Assign the 10 high-order bits of the 20-bit U' to the 10 low-order
3416           *       bits of W1 and the 10 low-order bits of U' to the 10 low-order
3417           *       bits of W2. Terminate.
3418           *
3419           *    Graphically, steps 2 through 4 look like:
3420           *    U' = yyyyyyyyyyxxxxxxxxxx
3421           *    W1 = 110110yyyyyyyyyy
3422           *    W2 = 110111xxxxxxxxxx
3423           * </pre>
3424           * @param string $str string to process.
3425           * @param boolean $setbom if true set the Byte Order Mark (BOM = 0xFEFF)
3426           * @return string
3427           * @access protected
3428           * @author Nicola Asuni
3429           * @since 1.53.0.TC005 (2005-01-05)
3430           * @uses UTF8StringToArray
3431           */
3432          function UTF8ToUTF16BE($str, $setbom=true) {
3433              if(!$this->isunicode) {
3434                  return $str; // string is not in unicode
3435              }
3436              $outstr = ""; // string to be returned
3437              $unicode = $this->UTF8StringToArray($str); // array containing UTF-8 unicode values
3438              $numitems = count($unicode);
3439              
3440              if ($setbom) {
3441                  $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM)
3442              }
3443              foreach($unicode as $char) {
3444                  if($char == 0xFFFD) {
3445                      $outstr .= "\xFF\xFD"; // replacement character
3446                  } elseif ($char < 0x10000) {
3447                      $outstr .= chr($char >> 0x08);
3448                      $outstr .= chr($char & 0xFF);
3449                  } else {
3450                      $char -= 0x10000;
3451                      $w1 = 0xD800 | ($char >> 0x10);
3452                      $w2 = 0xDC00 | ($char & 0x3FF);
3453                      $outstr .= chr($w1 >> 0x08);
3454                      $outstr .= chr($w1 & 0xFF);
3455                      $outstr .= chr($w2 >> 0x08);
3456                      $outstr .= chr($w2 & 0xFF);
3457                  }
3458              }
3459              return $outstr;
3460          }

 

sinon je ne voit pas :S


Message édité par Koyomi le 18-07-2007 à 10:21:58
mood
Publicité
Posté le 18-07-2007 à 10:19:57  profilanswer
 

n°1588198
vanadium
N° Atomique : 23
Posté le 18-07-2007 à 13:39:39  profilanswer
 

simogeo a écrit :

hello,
 
je viens de migrer une application sous utf8.
Pour générer du pdf, j'ai donc passer mon script depuis fpdf (pas de support utf8) vers tcpdf (qui lui,le supporte).
 
J'utilise le script Signets pour générer mes bookmarks.
http://www.fpdf.org/fr/script/script1.php
 
Toutefois, j'ai un bug sur les caractères accentués extraits de ma DB (mysql/pgsql). Ok sur les mots accentués issus d'un fichier texte.
 
Une idée du problème?
merci [:john keats]


 
Essaie après la connexion Sql d'initialiser le charset de la connexion SQL :

Code :
  1. if (version_compare($this->db_version(),'4.1','>='))
  2. {
  3. $this->execute('SET NAMES utf8',false);
  4. $this->execute('SET CHARACTER SET utf8',false);
  5. $this->execute("SET COLLATION_CONNECTION = 'utf8_general_ci'",false);
  6. $this->execute("SET COLLATION_SERVER = 'utf8_general_ci'",false);
  7. $this->execute("SET CHARACTER_SET_SERVER = 'utf8'",false);
  8. $this->execute("SET CHARACTER_SET_DATABASE = 'utf8'",false);
  9. }


(Exemple utilisant ma propre fonction "execute()" )

n°1588271
simogeo
j'ai jamais tué de chats, ...
Posté le 18-07-2007 à 15:04:27  profilanswer
 

vanadium a écrit :


 
Essaie après la connexion Sql d'initialiser le charset de la connexion SQL :

Code :
  1. if (version_compare($this->db_version(),'4.1','>='))
  2. {
  3. $this->execute('SET NAMES utf8',false);
  4. $this->execute('SET CHARACTER SET utf8',false);
  5. $this->execute("SET COLLATION_CONNECTION = 'utf8_general_ci'",false);
  6. $this->execute("SET COLLATION_SERVER = 'utf8_general_ci'",false);
  7. $this->execute("SET CHARACTER_SET_SERVER = 'utf8'",false);
  8. $this->execute("SET CHARACTER_SET_DATABASE = 'utf8'",false);
  9. }


(Exemple utilisant ma propre fonction "execute()" )


 
nop, ca ne change rien. Et comme je le dis précédemment. Les accents s'affichent correctement dans le corps du pdf!
Donc, je ne pense pas que ca vienne de la DB mais du traitement réalisé dans la fonction de bookmark.
 
Pourtant, comme le mentionne Koyomi, le code de la fonction fait appel à "UTF8ToUTF16BE($s, true);", la même fonction que depuis Cell() par exemple, qui lui m'affiche les caractères correctement!....
 


---------------
from here and there -- \o__________________________________ -- la révolution de la terre, en silence
n°1588489
vanadium
N° Atomique : 23
Posté le 18-07-2007 à 21:49:43  profilanswer
 

Lorsque tu codes dans tes fichiers, tu mets bien l'encodage en utf-8 ?

n°1588662
simogeo
j'ai jamais tué de chats, ...
Posté le 19-07-2007 à 11:26:17  profilanswer
 

of course!  [:john keats]


---------------
from here and there -- \o__________________________________ -- la révolution de la terre, en silence

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  [PHP] tcpdf / script bookmark et utf8

 

Sujets relatifs
[Projet] RTS/RPG : Recherche codeur PHPPasser un paramètre Js dans un <script src="">
Forum PHP : Neteco & ClubicInterpréteur PHP sans le réseau
[PHP] Probleme [RESOLU] :Form ne partant pas ...(Petit) problème avec un script !
Recherche Script Editeur WYSIWYG + Gestionnaire Media ![VBS] passer une variable d'un script à un autre
[script] Recuperer des infos sur le webScript wsh, Focus sur application avec session vérouillée (mi-résolu)
Plus de sujets relatifs à : [PHP] tcpdf / script bookmark et utf8


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR