From 5ead3e0c68eb9f97068399adcac83dec4c0e8261 Mon Sep 17 00:00:00 2001 From: Martin Kluska Date: Tue, 13 Jul 2021 10:27:47 +0200 Subject: [PATCH] Add ability to turn off converting entities + fix rendering DejavuSans with footer text (#570) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add ability to turn off converting entities Dejavu Sans font is missing glyphs for converted entities, turn it off if you need to show € and £ via dompdf.convert_entities option * Make render function public When using custom font (like Dejavu Sans) and getCanvas we need to render the content first (without using output method) to be able to write text (for footer, etc) without corrupting font in PDF (output will corrupt rendered font, helvetica is OK). Co-authored-by: Barry vd. Heuvel --- config/dompdf.php | 4 ++++ src/PDF.php | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/dompdf.php b/config/dompdf.php index 9a99305..c8645d3 100644 --- a/config/dompdf.php +++ b/config/dompdf.php @@ -13,6 +13,10 @@ */ 'show_warnings' => false, // Throw an Exception on warnings from dompdf 'orientation' => 'portrait', + /* + * Dejavu Sans font is missing glyphs for converted entities, turn it off if you need to show € and £. + */ + 'convert_entities' => true, 'defines' => array( /** * The location of the DOMPDF font directory diff --git a/src/PDF.php b/src/PDF.php index f31b421..04fc8e7 100644 --- a/src/PDF.php +++ b/src/PDF.php @@ -255,8 +255,11 @@ public function setEncryption($password, $ownerpassword = '', $pc = []) return $this->dompdf->getCanvas()->get_cpdf()->setEncryption($password, $ownerpassword, $pc); } - protected function convertEntities($subject) + protected function convertEntities($subject) { + if (false === $this->config->get('dompdf.convert_entities', true)) { + return $subject; + } $entities = array( '€' => '€',