如何为中文使用mPDF [英] How to use mPDF for Chinese Language

查看:403
本文介绍了如何为中文使用mPDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用mPDF将表单输入数据保存为PDF。对于英语来说,它工作正常。任何人都可以使用此代码将HTML表单数据保存为PDF。



问题:为了满足我的项目需求,我需要使用中文。



Form.html

 < form action ='processPDF.php'method ='post'> 
< label for =name>名称< / label>
< input name =nametype =textid =name>
< input type ='submit'name ='submit'value ='下载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>名称:<?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->输出('SavePDF.pdf','D');
}

}
?>

我遇到的问题是:在输入字段中,我输入怎么用中文说话, 。



如果你想在这里下载源代码就是代码的链接

解决方案

不要使用'c'作为 $ mode 参数,仅表示PDF核心字体,并且不支持中文字符。



尝试'+ aCJK'' - aCJK'。 / p>

请参阅示例 - 文件使用中文字体。


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

解决方案

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.

这篇关于如何为中文使用mPDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆