dou1908 2017-10-31 13:44
浏览 171
已采纳

如何将mPDF用于汉语

I am using mPDF to save form input data to PDF. For English, it is working fine. Anyone can use this code to save HTML Form data to PDF.

Issue: In order to fulfill my project requirement I need to use the Chinese Language. My current code is not working for that.

Form.html

<form action='processPDF.php' method='post'>
    <label for="name">Name</label>
    <input name="name" type="text" id="name">
    <input type='submit' name='submit' value='Download PDF'>
</form>

processPDF.php

<?php
header('Content-Type: text/html; charset=UTF-8');
if (isset($_POST['submit'])) {
    if (isset($_POST['name'])) {
        $name = $_POST['name'];
    } else {
        $Larmtid = '';
    }
    if (!isset($error)) {
        ob_start();
?>        
<div style="padding:20px;">
            <p>Name: <?php
        echo $name;
?></p>
        </div>
        <?php
        $body = ob_get_clean();
        $body = iconv('UTF-8', 'UTF-8//IGNORE', $body);
        $body = iconv('UTF-8', 'UTF-8//TRANSLIT', $body);
        include("mpdf/mpdf.php");
        $mpdf = new \mPDF('c', 'A4', '', '', 0, 0, 0, 0, 0, 0);
        $mpdf->SetAutoFont();
        $mpdf->autoScriptToLang = true;
        $mpdf->autoLangToFont   = true;
        $mpdf->WriteHTML($body);
        $mpdf->Output('SavePDF.pdf', 'D');
    }

}
?>

The problem I am having is: In the input field, I typed 怎么用中文说话 and it prints ��������.

If you want to download the source code here is the link to the code

  • 写回答

2条回答 默认 最新

  • dpiw16824 2017-11-01 07:49
    关注

    Do not use 'c' as a $mode parameter, that means PDF core fonts only and they do not support chinese characters.

    Try '+aCJK' or '-aCJK' instead.

    See examplefiles using chinese font.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口