Viewing 1 replies (of 1 total)
  • Plugin Author David Jensen

    (@dkjensen)

    Hello

    Below is a code snippet to add a custom font called jaro. The font files (.ttf) would be stored in the child-theme/assets/fonts directory, but it can be customized based on your use case.

    This code would be placed in your child theme functions.php file or similar.

    Let me know if you have any trouble getting this to work.

    add_filter(
    	'wc_cart_pdf_mpdf',
    	function ( $mpdf ) {
    		$font_name = 'jaro'; // Name of the font.
    
    		$mpdf->AddFontDirectory( get_stylesheet_directory() . '/assets/fonts' ); // Directory where the .ttf files are stored.
    
    		$mpdf->fontdata[ $font_name ] = array(
    			'R'  => 'Jaro-Regular.ttf', // Regular.
    			'I'  => 'Jaro-Italic.ttf', // Italic.
    			'B'  => 'Jaro-Bold.ttf', // Bold.
    			'BI' => 'Jaro-BoldItalic.ttf', // Bold Italic.
    		);
    
    		foreach ( $mpdf->fontdata as $f => $fs ) {
    			if ( isset( $fs['R'] ) && $fs['R'] ) {
    				$mpdf->available_unifonts[] = $f;
    			}
    			if ( isset( $fs['B'] ) && $fs['B'] ) {
    				$mpdf->available_unifonts[] = $f . 'B';
    			}
    			if ( isset( $fs['I'] ) && $fs['I'] ) {
    				$mpdf->available_unifonts[] = $f . 'I';
    			}
    			if ( isset( $fs['BI'] ) && $fs['BI'] ) {
    				$mpdf->available_unifonts[] = $f . 'BI';
    			}
    		}
    
    		$mpdf->SetDefaultFont( $font_name );
    		$mpdf->AddFont( $font_name );
    		$mpdf->SetFont( $font_name );
    
    		return $mpdf;
    	}
    );
Viewing 1 replies (of 1 total)
  • The topic ‘Change of font’ is closed to new replies.