Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/DokuMpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
17 changes: 17 additions & 0 deletions tpl/default/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.:

<code>
<?php
return [
'frutiger' => [
'R' => 'Frutiger-Normal.ttf',
'I' => 'FrutigerObl-Normal.ttf',
]
];
</code>

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: frutiger'', where "frutiger" is the name of the font on your ''fonts.php'' file.