As Mentioned in the comments, dompdf/domPDF
after following the steps as mentioned above does not give the desired results, see this,
I suggest the use of TCPDF. elibyy / tcpdf-laravel provides a way to add tcpdf in laravel.
Install it using
composer require elibyy/tcpdf-laravel
.
Add this to your provider
in config/app.php
ElibyyTCPDFServiceProvider::class,
Then In your controller add the lines
use ElibyyTCPDFFacadesTCPDF;
public function generatePDF(){
$data = new stdClass(); //can be your model, I have just used empty object
$public_path = public_path();
$data->title = "<p>??????????? ???????? ??</p>";
$data->description = "<p>????? ????????????? ????? ????? ??????? ????? ????????? ??????? ??? ????? ?
?????????????? ??? ? ??, ??? ????? ??????????? ???????? ?? ???????? ??? ?
<p>??????? ?????? ????? ?????, ???? ????? ?–????? ???????? ?????? ????? ?? ? ??????? ?? ???????????? ????? ?????? ????????? ?? ??????? ?????? ? ??? ??? ?? ?
<p>??????? ????? ????? ??? ?????? ?????? ?, ???? ??? ????? ????? ?????? ????? ???????? ? ????????? ????? ???? ?????? ??????? ???? ??????????? ??????? ????? ? ?? ?
<p>????????? ??? ???? ????????? ??? ? ??????? ??????? ??????? ????? ???????? ?????? ????????????? ?????? ???????? ???, ?????? ? ?????? ?????? ???? ?????? ?????? ?
<p><strong>???????? ????? ??????? ????</strong><br />????????? ??????????? ????? ????? ????????? ??????? ??????????? ? ????????? ??????? ???? ??? ? ????? ?????? ?
<p>????? ?????? ??? ??? ??????? ?? ???? ?????? ? ? ?????? ??? ???????? ???????? ? ????????? ???????? ??? ????; ???? ??? ???????? ?????? ????? ?????? ? ???? ???? ?
<p>??? ???, ?????????? ????? ?????????? ??????? ?? ????? ??? ? ????????? ?????????? ????? ?????? ???? ???? ???? ????? ???????? ????? ?? ????? ? ???????????????? ?
<p>?? ????????? ????? ?????? ?????? ????????? ??????????? ????? ????? ? ??????, ????? ???????? ???? ???? ????? ????? ?????? ??? ??? ?????? ????? ???? ? ??????? ?
<p>???????? ???? ????? ? ????? ?????? ??Œ?????? ???? ?????? ? ?????, ??????????? ????? ??????? ???????? ?????? ???????? ????? ? ?????? ??? ?, ?????? ????? ?
<p>????????? ????????? ???????? ?????? ???, ?????? ? ??????? ???? ?????? ???????? ??????????? ????????? ???? ????????? ???? ?????? ???? ? ??? ??????? ?????? &ls ?
<p><strong>????????</strong> ??? ?????? ??????????? ??????????? ???? ???? ???? ? ??????????? ????? ?????? ???? ???????? ???? ??????? ??? ? ??????????? ????? ??? ?
<p>??????? ?? ??????????? ????? ????? ????? ?????????? ????? ?????? ? ?????, ?????? ???????? ‘???????????? ????? ???? ?????????’ ? ? ??????, ???? ?? ?
<p><strong>????????? ???????????? ????? ??????</strong><br />??? ? ? ??? ?????? ????? ??????? ????? ? ? ??????? ???????? ??????? ? ???? ????????? ? ???? ???? ?? ?
<p>??????? ????????????? ????????? ??????–? ?? ????? ? ?????? ?????? ??? ??? ???????? ???? ??? ???? ?????? ??????????? ???????? ????? ??? ???? ????????? ? ?
<p>??????????? ???? ????? ??? ?????? ????? ?????? ????? ?????? ? ??????? ??????????? ???? ??? ???? ????????? ??? ??????????? ????? ???????? ?????????? ??¥?? ?
<p><strong>???????? ???? ‘??????’</strong><br />?????? ????? ?????? ? ?????????? ?????? ?????????? ??? ???? ????? ??????? ? ???????? ???? ????? ???? ?
<p>????? ????????? ??? ?? ????????? ????????? ??????? ??? ? ??? ??? ????????? ??????? ????? ????????? ??????? ???? ??????? ??, ??÷??? ????? ?????????? ?? ?
<p>????? ??? ???????? ?????????? ???? ???????? ? ????????? ???????????? ??????? ???? ????? ?????? ????? ? ? ?????????? ??? ???????? ??????? ???? ?????? ??? ??? ?
<p>???????? ?????? ????? ???? ????? ???????? ???? ??? ???? ????????? ???????? ???? ???? ?? ? ??, ????? ????? ????? ?? ?????? ???? ??????? ?????? ????? ???? ???? ?
<p>???????; ??????? ????????? ??? ???????? ????, ????? ????? ????????? ??????? ???? ????? ? ?????— ??????–? ?? ‘???? ????, ???? ????’ ?? ?
<p>????????? ???????????? ?????? ???? ????? ????? ??????????? ???? ??? ????? ? ? ?????? ???? ????? ????? ?? ?? ? ?????? ?????? ???? ????????? ? ?????, ?????? ?? ?
<p>???????????? ?????????? ???? ???????? ??????? ???? ??????? ?????? ??? ??? ???????, ??? ??? ??????? ? ??? ??? ????????????? ?????????? ?????? ??????? ????? ?? ?
<p><strong>??????? ?????? ?????</strong><br />????? ??????, ?? ‘???? ??????’ ?? ??????? ‘??????’ ????? ???? ???????? ??????? ? ????, ??? ?
<p>????? ???????? ??????????? ?????????? ?????? ????? ???? ????? ??????????? ? ?????????? ???? ? ???????? ???? ?????????? ??? ??????? ????????? ????? ?????? ??? ?
<p>?????? ?????????????? ?????, ?????????????? ??????? ???? ? ? ?? ?????? ??Œ?????? ???? ?? ? ??????? ????????????? ??????? ????? ????? ????? ???????? ?? ?
<p>??????? ????????????? ????? ???? ???? ?????? ? ????? ????? ??? ?????? ??? ?????? ??? ???? ??????? ????? ????? ? ? ????? ??????? ????? ???? ??????????? ????? ?
<p><em><strong>??????????????? ????????? ???????? ??????</strong></em></p> ";
$html = "<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<meta charset='UTF-8'>
<title>". $data->title ."</title>
<style>
@font-face {
font-family: 'preeti';
font-style: normal;
font-weight: 400;
src:url('".$public_path."/public/PREETI.TTF' format('woff');
}
</style>
</head>
<body style='font-family: preeti;'>
". $data->description ."
</body>
</html>";
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf::setFontSubSetting(true);
$pdf::setFont('freeserif','',12);
// $pdf->SetFont('dejavusans', '', 14, '', true);
$pdf::AddPage();
$pdf::writeHTML($html, true, 0, true, true);
$output = $pdf::Output('001.pdf', 'I');
return $output;
}
Should get output like this.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…