Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter mandarins92

    (@mandarins92)

    Hello,

    Thanks for your help.

    I applied your suggested code using dkpdf_mpdf_config to set the default font to lxgwwenkai and enabled auto language detection. I also added the CSS via dkpdf_before_content.

    However, Chinese characters still don’t display correctly in the generated PDFs. The fonts are in the correct /wp-content/fonts/ folder with proper permissions. The PDF falls back to another font instead.

    useOTL is enabled as recommended, but no errors appear in logs.

    // Ajouter le dossier contenant les polices personnalisées
    add_filter('dkpdf_mpdf_font_dir', function($font_dir) {
    $font_dir[] = WP_CONTENT_DIR . '/fonts';
    return $font_dir;
    });

    add_filter('dkpdf_mpdf_font_data', function($font_data) {
    $font_data['lxgwwenkai'] = [
    'R' => 'LXGWWenKai-Regular.ttf',
    'M' => 'LXGWWenKai-Medium.ttf',
    'L' => 'LXGWWenKai-Light.ttf',
    // Supprimé: 'useOTL' => 0xFF
    ];

    $font_data['notosanssc'] = [
    'R' => 'NotoSansSC-Regular.otf',
    'useOTL' => 0xFF, // ✔️ Conservé ici car NotoSansSC est OTL compatible
    ];

    return $font_data;
    });

    // Configurer mPDF pour utiliser LXGW WenKai par défaut
    add_filter('dkpdf_mpdf_config', function($config) {
    $config['default_font'] = 'lxgwwenkai'; // Ta police perso ici
    $config['autoScriptToLang'] = true;
    $config['autoLangToFont'] = true;

    // Empêche l'utilisation de la police sun-exta en surchargeant cette valeur si existante
    if (isset($config['fontdata']['sun-exta'])) {
    unset($config['fontdata']['sun-exta']);
    }

    return $config;
    });

    add_filter('dkpdf_before_content', function($content) {
    return '<div style="font-family: lxgwwenkai, notosanssc, sans-serif;">' . $content . '</div>';
    });

    // Répertoire temporaire pour améliorer la stabilité/performance
    add_filter('dkpdf_pdf_arguments', function($args) {
    $args['tempDir'] = WP_CONTENT_DIR . '/uploads/dkpdf-tmp';
    return $args;
    });
    body {
    font-family: 'lxgwwenkai', 'notosanssc', sans-serif;
    }

    h1, h2, h3, h4 {
    font-family: 'lxgwwenkai';
    }

    pre, code {
    font-family: 'lxgwwenkai'; /* ou une police monospace si tu préfères */
    font-size: 12px;
    }

    pre, code {
    font-family: 'lxgwwenkaimono', monospace;
    font-size: 12px;
    }

    Thanks again,

Viewing 1 replies (of 1 total)