splitbrain / dokuwiki-plugin-dw2pdf

A fork of Luigi Micco's PDF export plugin for DokuWiki
http://www.dokuwiki.org/plugin:dw2pdf
55 stars 68 forks source link

Doesn't support real custom fonts #388

Closed poletaew closed 1 year ago

poletaew commented 4 years ago

I have custom font on the DokuWiki page. And there is no options to use the same font in PDF. As I see there is hardcoded DejaVu font.

Moreover, after I edited DokuPDF class with following codes, it also didn't help:

... line 50 ...
                $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
        $fontDirs = $defaultConfig['fontDir'];

        $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
        $fontData = $defaultFontConfig['fontdata'];

        // we're always UTF-8
        parent::__construct(
            array(
                'mode' => $mode,
                'format' => $format,
                'fontsize' => $fontsize,
                'ImageProcessorClass' => DokuImageProcessorDecorator::class,
                'tempDir' => _MPDF_TEMP_PATH, //$conf['tmpdir'] . '/tmp/dwpdf',
                'fontDir' => array_merge($fontDirs, [
                    __DIR__ . '/../../tpl/dnd/fonts',
                ]),
                'fontdata' => $fontData + [
                    'Nodesto' => [
                        'R' => 'Nodesto.otf'
                    ]
                ],
                'default_font' => 'Nodesto'
            )
        );

Is there a way to use custom font in dw2pdf?

demaddis commented 4 years ago

Not sure this is the best/recommended way, but I got this to work by adding my custom font to vendor/mpdf/mpdf/src/Config/Fontvariables.php:

                        'fontdata' => [
                                "roboto" => [
                                        'R' => "Roboto-Light.ttf",
                                        'B' => "Roboto-Medium.ttf",
                                        'I' => "Roboto-Italic",
                                        'BI' => "Roboto-BoldItalic.ttf",
                                ],

and then setting roboto as font-family in my style.css.

arjay54 commented 3 years ago

Perfect!

Klap-in commented 1 year ago

I would expect, that an approach like the startpost should be possible. Maybe some details needs attention there?

Proposals to add other fonts to the configuration of mpdf are welcome. Please let continue the discussion in similar issue #445.