我正在使用mPDF将表单输入数据保存为PDF.对于英语,它工作正常.任何人都可以使用此代码将HTML表单数据保存为PDF.
问题:为了满足我的项目要求,我需要使用中文.我当前的代码对此不起作用.
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');
}
}
?>
我遇到的问题是:在输入字段中,我键入了怎么用中文说话,并显示 .
If you want to download the source code here is the link to the code
解决方法:
不要将’c’用作$mode参数,这意味着仅PDF核心字体,并且它们不支持中文字符.
请尝试使用’aCJK’或’-aCJK’.