- Я скопировал папку для библиотеки dompdf в / dompdf
- a / fonts папка с Roboto-Black.ttf внутри
- Я создал php файл index. php
<?php
// Include autoloader
require_once 'dompdf/autoload.inc.php';
// Reference the Dompdf namespace
use Dompdf\Dompdf;
// Instantiate and use the dompdf class
$dompdf = new Dompdf();
// Load content from html file
$html = file_get_contents("template.php");
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF (1 = download and 0 = preview)
$dompdf->stream("examplepdf", array("Attachment" => 0));
настоящий базовый c
шаблон. php файл
<style>
.customfont {
color: #35aa45;
}
</style>
<div class="customfont">
this is my text
</div>
Теперь, когда я открываю файл индекса. php, он создает PDF-файл с зеленый текст шрифтом по умолчанию. Все хорошо!
Теперь я хочу включить в шаблон собственный шрифт.
<style>
@font-face {
font-family: 'Roboto';
src: url('fonts/Roboto-Black.ttf') format('truetype');
}
.customfont {
font-family: 'Roboto';
color: #35aa45;
}
</style>
<div class="customfont">
this is my text
</div>
А теперь ... пустой экран, без PDF! Если я изменю путь для шрифта на неправильную папку ... зеленый текст появится в pdf, как раньше. Я уже пробовал различные варианты, чтобы включить шрифт, но по какой-то причине он не включен! Вся остальная помощь здесь не решила эту проблему. у кого-нибудь есть идея?