问题
i am working with mpdf library with php to create dynamic PDF. PDF is creating with English characters but when i try to use hindi language's character, it prints ??????. Please suggest me that what should i do.I will be thank full to all.
<?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();
回答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;
?>
Create a CSS file on root and add following code in CSS:
p, td { font-family: freeserif; }
Working fine for me, check the below link...
Click here
回答2:
You have to set a font supporting hindi characters, in your case especially for td
elements. Freeserif works for me.
<style>
p, td { font-family: freeserif; }
</style>
BTW, your mPDF constructor is off, the config array has to have keys (mode
, format
). Also. A4-C
is not a valid format, the letter after the hyphen must be a P
(ortrait) or a L
(andscape).
回答3:
<style>
body, p, td, div { font-family: freesans; }
</style>
来源:https://stackoverflow.com/questions/51038440/how-to-use-hindi-fonts-in-mpdf-library