Hi. How can we help?

How add fonts to pdf

Please add this code inside the file functions.php of the theme.

if ( ! function_exists( 'ywraq_mpdf_args' ) ) {
function ywraq_mpdf_args( $args ) {
$defaultConfig = ( new Mpdf\Config\ConfigVariables() )->getDefaults();
$fontDirs = $defaultConfig['fontDir'];

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

$args = array(

'fontDir' => array_merge(
$fontDirs,
array(
__DIR__ . '/woocommerce/mpdf_fonts/',
)
),
'fontdata' => $fontData + array(
'opensans' => array(
'R' => 'OpenSans-Regular.ttf',
'B' => 'OpenSans-Bold.ttf',
'I' => 'OpenSans-Italic.ttf',
'BI' => 'OpenSans-BoldItalic.ttf',

),
'cookie' => array(
'R' => 'Cookie-Regular.ttf',
'B' => 'Cookie-Regular.ttf',
'I' => 'Cookie-Regular.ttf',
'BI' => 'Cookie-Regular.ttf',
),
),
'default_font' => 'opensans',
'default_font_size' => '12',
);

return $args;
}

add_filter( 'ywraq_mpdf_args', 'ywraq_mpdf_args' );
}

The fonts file should be uploaded inside the folder /woocommerce/mpdf_fonts/ of the theme

Use the array key of the font (i.e ‘cookie’ or ‘opensans’) to set the default font.

Was this article helpful?
0 out of 0 found this helpful

Back to Help Center >