vikaspa Posted November 15, 2022 Share Posted November 15, 2022 (edited) Dear All Code generated from https://github.com/dompdf/dompdf/issues/2481 I am using dompdf 2.0 Main program to create pdf https://prajaktasoftware.com/onlineexam/vendor-special-message.php <- input html file forms input to generated PDF https://prajaktasoftware.com/onlineexam/testfont-1.php <- program that generates pdf using above program I am using dompdf (testfont-1.php) the output generated shows ??? characters pls help <?php ob_start(); include 'vendor-special-message.php'; // pdf generatef from this file $_template = ob_get_clean(); require( 'dompdf/autoload.inc.php'); use Dompdf\Dompdf; $dompdf=new Dompdf(); //$dompdf->loadHtml($_template, "UTF-8"); $dompdf->loadHtml($_template, "UTF-8"); $dompdf->setPaper("A4", "portrait"); $dompdf->set_option('isFontSubsettingEnabled', true); $dompdf->set_option('defaultMediaType', 'all'); $dompdf->set_option('isRemoteEnabled', true); $dompdf->render(); $dompdf->stream( time() . ".pdf", array("Attachment" => false)); // $dompdf->stream(); // stream the pdf in browser exit; ?> vendor-special-message.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; UTF-8"> <style> @import url('https://fonts.googleapis.com/css2?family=Hind:wght@300&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Oswald:wght@200&display=swap'); div {font-family: 'Hind', sans-serif;} body { font-family: 'Oswald', sans-serif } </style> </head> <body> <p>Happy Birthday</p> <p>Happy Birthday</p> <p>Happy Birthday</p> <div>सभ मानव जन्मतः स्वतन्त्र अछि तथा गरिमा आʼ अधिकारमे समान अछि। सभकेँ अपन–अपन बुद्धि आʼ विवेक छैक आओर सभकेँ एक दोसराक प्रति सौहार्दपूर्ण व्यवहार करबाक चाही।</div> </body> </html> Edited November 15, 2022 by vikaspa Quote Link to comment Share on other sites More sharing options...
gizmola Posted November 16, 2022 Share Posted November 16, 2022 In the documentation about external fonts, it specifically provides an example using google fonts. Try adding this to your initialization of dompdf: $tmp = sys_get_temp_dir(); $dompdf = new Dompdf([ 'logOutputFile' => '', // authorize DomPdf to download fonts and other Internet assets 'isRemoteEnabled' => true, 'isFontSubsettingEnabled' => true, 'defaultMediaType' => 'all', // all directories must exist and not end with / 'fontDir' => $tmp, 'fontCache' => $tmp, 'tempDir' => $tmp, 'chroot' => $tmp, ]); $dompdf->setPaper("A4", "portrait"); $dompdf->loadHtml($_template, "UTF-8"); $dompdf->render(); $dompdf->stream(time() . ".pdf", array("Attachment" => false)); Quote Link to comment Share on other sites More sharing options...
vikaspa Posted November 18, 2022 Author Share Posted November 18, 2022 Dear GIZMOLA Thanks a TON for the reply. I will check this and revert Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.