2

I have a MySQL table named as "revenue" that is included data in Unicode Sinhala fonts. Now I want to create a PDF output from that data using DOMPDF. I used the following code.

include_once '../dompdf_config.inc.php';

mysql_connect('localhost',"iacc","123");
mysql_select_db("iacc");

$result=mysql_fetch_array(mysql_query("SELECT * FROM revenue"));

$value=  mysql_fetch_assoc($result);

$date=date("Y/m/d");

$html = '
  <html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style>
    @font-face {
      font-family: FM-Malithi;
      font-style: normal;
      font-weight: 400;
      src: url(../font/FM-Malithi.ttf) format("true-type");
    }
    </style>
  </head>

<body>

  <table  border = "3" >
  <tr>
    <td bgcolor="#FFCCFF" width="8%" class="fs" scope="col">කාර්යාලය</td>
<td bgcolor="#FFCCFF" width="8%" class="fs" scope="col">මුදල</td>

  </tr>

    <tr>


  <td><input type="text" name="office" value="'.$value['office'].'" style="font-family: FM-Malithi, sans-serif;" /></td>
 <td><input type="text" name="amount" value="'.$value['amount'].'" style="font-family: FM-Malithi, sans-serif;" /></td>  
      </tr>



      </table>
  </body>
  </html>
';
$dompdf = new DOMPDF();
$dompdf->load_html($html,'UTF-8');
$dompdf->render();
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
  1. But it returns ?????? for Unicode sinhala fields. I can not understand what I am going wrong. Can anyone help me. Tnx.
Xtern
  • 165
  • 2
  • 2
  • 13

1 Answers1

1

utf8 turning into '?????'

What probably happened:

  • you had utf8-encoded data (good)
  • SET NAMES latin1 was in effect (default, but wrong)
  • the column was declared CHARACTER SET latin1 (default, but wrong)

utf8 needs to be established in about 4 places.

  • The column(s) in the database -- Use SHOW CREATE TABLE to verify that they are explicitly set to utf8, or defaulted from the table definition. (It is not enough to change the database default.)
  • The connection between the client and the server. See SET NAMES utf8.
  • The bytes you have. (This is probably the case.)
  • If you are displaying the text in a web page, check the <meta> tag.

Do not use the mysql_ interface; use mysqli_.

(I don't know DOMPDF; there may be settings there.)

If මුදල shows as මුදල, then you will have "Mojibake".
The HEX in the table should be E0B6B8E0B794E0B6AFE0B6BD.

Rick James
  • 135,179
  • 13
  • 127
  • 222