From be75e0ff79d7ecbb261e7468d7f383edc9499607 Mon Sep 17 00:00:00 2001 From: E <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 22 Jul 2026 17:01:27 -0300 Subject: [PATCH 1/2] Feature: Custom fonts support --- src/DokuMpdf.php | 17 +++++++++++++++++ tpl/default/README.txt | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/DokuMpdf.php b/src/DokuMpdf.php index 2dac4812..0266cc6a 100644 --- a/src/DokuMpdf.php +++ b/src/DokuMpdf.php @@ -32,6 +32,23 @@ public function __construct(Config $config, string $lang) $initConfig = $config->getMPdfConfig(); $initConfig['mode'] = $this->lang2mode($lang); + $tplfonts = DOKU_PLUGIN . 'dw2pdf/tpl/' . $config->getTemplateName() . '/fonts'; + if (file_exists($tplfonts . '.php')) { + $defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults(); + $fontData = $initConfig['fontdata'] ?? $defaultFontConfig['fontdata']; + + $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); + $fontDirs = $initConfig['fontDir'] ?? $defaultConfig['fontDir']; + + $fontDirs[] = $tplfonts; + + $fontDefs = array($fontData, include($tplfonts . '.php')); + $fontData = array_reduce($fontDefs, 'array_merge', array()); + + $initConfig['fontDir'] = $fontDirs; + $initConfig['fontdata'] = $fontData; + } + $http = new HttpClient(); $container = new SimpleContainer([ diff --git a/tpl/default/README.txt b/tpl/default/README.txt index 60216e48..fa711bd5 100644 --- a/tpl/default/README.txt +++ b/tpl/default/README.txt @@ -67,3 +67,20 @@ Custom stylings can be provided in the following file of your dw2pdf-template fo You can use all the CSS that is understood by mpdf (See http://mpdf1.com/manual/index.php?tid=34) +===== Fonts ===== + +You can use custom fonts with your template by creating file ''fonts.php'' within your template folder. E.g.: + + + [ + 'R' => 'Frutiger-Normal.ttf', + 'I' => 'FrutigerObl-Normal.ttf', + ] +]; + + +Copy the font files to the ''fonts/'' subfolder within your template folder. + +You can use them on your template by using CSS style ''font-family: asap'', where "asap" is the name of the font on your ''fonts.php'' file. From 26352ed27c7e0e182d125eb8b9bade4cd3ca6439 Mon Sep 17 00:00:00 2001 From: Eduardo Mozart de Oliveira <2974895+eduardomozart@users.noreply.github.com> Date: Wed, 22 Jul 2026 17:18:19 -0300 Subject: [PATCH 2/2] Update font-family reference from 'asap' to 'frutiger' --- tpl/default/README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tpl/default/README.txt b/tpl/default/README.txt index fa711bd5..58233a9f 100644 --- a/tpl/default/README.txt +++ b/tpl/default/README.txt @@ -83,4 +83,4 @@ return [ Copy the font files to the ''fonts/'' subfolder within your template folder. -You can use them on your template by using CSS style ''font-family: asap'', where "asap" is the name of the font on your ''fonts.php'' file. +You can use them on your template by using CSS style ''font-family: frutiger'', where "frutiger" is the name of the font on your ''fonts.php'' file.