I cannot get my pdf generator to work. I’m using dompdf/dompdf library and I have a lot of trouble generating PDF I want. My issue is: every time I try to generate PDF with file that is using style with family-font: DejaVu Sans I get 500 ERROR and nothings happening.
When I delete line including "DejaVu Sans" everything works, but I need PDF file to handle extended Latin characters like "ążćłóńę". Is there any way to make this work, or any other way to use extended Latin in DomPdf?
PHP Generate:
<?php
require 'vendor/autoload.php';
use DompdfDompdf;
use DompdfOptions;
$options = new Options();
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
$php = file_get_contents("inputPdfData.php");
$dompdf->setPaper('A4', 'portrait');
$dompdf->loadHtml($php);
$dompdf->render();
$dompdf->stream();
"inputPdfData.php"
<html lang="pl">
<head>
<title>PDF GENERATOR</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta charset="UTF-8" content="text/html">
<style>
* {
font-family: "DejaVu Sans", sans-serif;
}
</style>
</head>
<body>
ążćęłóńź
ĄŻĘĆŹŁÓŃ
</body>
</html>
"composer.json"
{
"require": {
"dompdf/dompdf": "^2.0"
}
}
2
Answers
I end up not using dompdf because of multiple issues. For anyone struggling: try using other library mPDF worked like magic for me. It worked first time with no issues about font or charset. Maybe this will help someone avoid hours of searching for an answer (about dompdf)
Normally after you have installed DOMPDF, the DejaVu TrueType fonts have been pre-installed to give dompdf decent Unicode character coverage by default.
Aother way (
instead of using DejaVu
) to use extended Latin in DomPdf (or to render polish fonts, etc), you may choose usingPoltawski Nowy
font.The trick is to use google font, such as
So please find below a fully working code (modified based on your original code):
PHP (e.g. font1.php)
inputPdfData.php
See below for the result