如何在 mpdf 库中使用印地语字体?

How to use Hindi fonts in mpdf library?

我正在使用 php 的 mpdf 库来创建动态 PDF。 PDF 是用英文字符创建的,但是当我尝试使用印地语字符时,它会打印 ????????。请建议我应该做什么 do.I 将感谢所有人。

<?php

require_once('config.php');
require_once __DIR__ . '/lib/functions.php';
require_once __DIR__ . '/lib/mpdf/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf(['utf-8', 'A4-C']); // New PDF object with encoding & page size
$mpdf->text_input_as_HTML = TRUE;

$userId = $_SESSION['user_id'];

$user = getsingledataByfeild('user_id', $userId, 'registered_user');
$Id = $_SESSION['did'];
$feeDetails = getsingledataByfeild('id', $Id, 'fee_calculation');
$authname = getdataByConditions(['id' => $feeDetails['authority']], 'development_authority');

$html = '<table class="table">
    <tr>
        <td><label> अथॉरिटी का नाम: <span>*</span></label></td>
        <td>' . $authname[0]['authority_name'] . '</td>
    </tr>
    <tr>
        <td><label> आवेदक का नाम  <span>*</span></label></td>
        <td>' . $feeDetails['applicant_name'] . '</td>
    </tr>
    <tr>
        <td><label> आवदेक का पता  : <span>*</span></label></td>
        <td>' . $feeDetails['applicant_address'] . '</td>
    </tr>
    <tr>
        <td><label> भूखण्ड संख्या : <span>*</span></label></td>
        <td>' . $feeDetails['land_no'] . '</td>
    </tr>
    <tr>
        <td><label> योजना का नाम : <span>*</span></label></td>
        <td>' . $feeDetails['plan_name'] . '</td>
    </tr>
    </table>'; 

$mpdf->setAutoTopMargin = 'stretch'; // Set pdf top margin to stretch to avoid content overlapping
$mpdf->setAutoBottomMargin = 'stretch'; // Set pdf bottom margin to stretch to avoid content overlapping

$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($html);
$mpdf->Output();

您必须设置支持印地语字符的字体,在您的情况下尤其是 td 元素。 Freeserif 适合我。

<style>
    p, td { font-family: freeserif; }
</style>

顺便说一句,您的 mPDF 构造函数已关闭,配置数组必须具有键(modeformat)。还。 A4-C 不是有效格式,连字符后的字母必须是 P(ortrait) 或 L(andscape)。

<?php

require_once( 'mpdf/mpdf.php');
$stylesheet = file_get_contents('css/style.css');

$html = '<table class="table">
    <tr>
        <td><label> अथॉरिटी का नाम: <span>*</span></label></td>
        <td>' . $authname[0]['authority_name'] . '</td>
    </tr>
    <tr>
        <td><label> आवेदक का नाम  <span>*</span></label></td>
        <td>' . $feeDetails['applicant_name'] . '</td>
    </tr>
    <tr>
        <td><label> आवदेक का पता  : <span>*</span></label></td>
        <td>' . $feeDetails['applicant_address'] . '</td>
    </tr>
    <tr>
        <td><label> भूखण्ड संख्या : <span>*</span></label></td>
        <td>' . $feeDetails['land_no'] . '</td>
    </tr>
    <tr>
        <td><label> योजना का नाम : <span>*</span></label></td>
        <td>' . $feeDetails['plan_name'] . '</td>
    </tr>
    </table>';


$mpdf = new mPDF('utf-8', 'A4-C');
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($html);

//call watermark content aand image
$mpdf->SetWatermarkText('phpflow.COM');
$mpdf->showWatermarkText = true;
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->Output("phpflow.pdf", 'F');

$mpdf->Output();

exit;
?>  

在 root 上创建一个 CSS 文件并在 CSS 中添加以下代码:

p, td { font-family: freeserif; }

对我来说工作正常,请检查以下内容 link...

Click here

<style>
   body, p, td, div { font-family: freesans; }
</style>

我添加了这些代码:

$mpdf = new \Mpdf\Mpdf(['tempDir' => sys_get_temp_dir().DIRECTORY_SEPARATOR.'mpdf','default_font' => 'serif', 'format' => 'A4-L']);
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;

适合我。