我正在使用PHP的mpdf库来创建动态PDF。 PDF正在使用英文字符创建,但是当我尝试使用印地文语言的字符时,它会打印??????。请建议我该怎么办。我将非常感谢所有人。
<?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();
答案 0 :(得分:1)
<?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;
?>
在根目录上创建一个CSS文件,并在CSS中添加以下代码:
p, td { font-family: freeserif; }
对我来说很好,请检查下面的链接...
答案 1 :(得分:0)
您必须设置支持印地语字符的字体,在这种情况下,尤其是对于td
元素。 Freeserif为我工作。
<style>
p, td { font-family: freeserif; }
</style>
顺便说一句,您的mPDF构造函数已关闭,配置数组必须具有键(mode
,format
)。也。 A4-C
是无效格式,连字符后面的字母必须为P
(竖排)或L
(横排)。
答案 2 :(得分:0)
<style>
body, p, td, div { font-family: freesans; }
</style>