问题
For report generation in PHP I am using HTML2PDF.
It works fine with English language but not giving proper output for Japanese language.
How can I set utg8 character in hHTML2PDF library.
Is there a way to achieve this in HTML2PDF library. I am gettign output like "???????????????" instead of Japanese text
In /var/www/html/html2pdf/locale folder following files I found en.csv, fr.cvs, cs.csv, da.csv
Can we get such file for Japanese too.
Below is my code
<?php
$content = ob_get_clean();
// convert to PDF
require_once('Classes/library/html2pdf.class.php');
try {
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->pdf->SetDisplayMode('fullpage');
// $html2pdf->pdf->SetProtection(array('print'), 'spipu');
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$filename = $filename .'_'.date('Ymd');
$html2pdf->Output($filename.'.pdf','D');//,'D'
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
回答1:
Try to use a specify fonts instead of the default, try this
<?php
$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8');
$html2pdf->setDefaultFont('arialunicid0'); //add this line
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content, false);
$html2pdf->Output('japan.pdf');
?>
Reference: http://community.impresscms.org/modules/newbb/viewtopic.php?post_id=43474#forumpost43474
回答2:
For polish signs helped this line:
$html2pdf->setDefaultFont('arialunicid0'); //add this line
Look it in Word, for me Helvetica showed squares. After font change problem disapered.
回答3:
I solved this issue with this function:
$tpl_data = array_map('utf8_decode',$datas);
回答4:
Set encoding to UTF-8
$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8');
回答5:
$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', []);
$html2pdf->setDefaultFont('cid0jp'); //using this line
$html2pdf->writeHTML($html);
$html2pdf->pdf->SetTitle('PDFダウンロード');
$html2pdf->output('download.pdf');
I'm using this code and it working!
来源:https://stackoverflow.com/questions/21673676/html2pdf-support-for-japanese-languageutf8-is-not-working