How can I display Chinese (and Russian and any character) in a PDF or PNG created by PHP. The example code below display two blocks, not 测试. If I try Arabian, I see text, but it looks different from the input.
<?php
// Set the content-type
header('Content-Type: image/png');
$text = '测试';
// Create the image
$im = imagecreatetruecolor(400, 200);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 1400, 600, $white);
// Replace path by your own font path
$font = 'fonts/DejaVuSans.ttf';
// Add the text
imagettftext($im, 40, 0, 10, 100, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
The font file is copied from my Ubuntu desktop.
I've tried the same creating a PDF using dompdf (with font DejaVuSans), which should be the end result, but that failed too. I guess it's the same problem. I tried tcpdf, which displays Russian and Arabian, so that is an improvement.
If I can create a PNG or something that can be used inside the PDF, that will do as well.