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

    (@dkjensen)

    Hi!

    This will take custom programming but it can be accomplished. In your child theme functions.php file, you will do something like the following:

    
    add_filter( 'wc_cart_pdf_mpdf', function( $mpdf ) {
    	$mpdf->AddFontDirectory( get_stylesheet_directory() . '/assets/fonts/rubik' );
    
    	$mpdf->fontdata['rubik'] = [
                'R' => 'Rubik-Regular.ttf',
                'I' => 'Rubik-Italic.ttf',
    	];
    
    	$mpdf->SetDefaultFont( 'rubik' );
    	$mpdf->AddFont( 'rubik' );
    	$mpdf->SetFont( 'rubik' );
    	$mpdf->autoLangToFont = false;
    	$mpdf->percentSubset = 100;
    
    	return $mpdf;
    } );
    
    • This reply was modified 3 years, 11 months ago by David Jensen.
    Thread Starter nadaaboelenin

    (@nadaaboelenin)

    hi,
    thank you so much. I am new to PHP code so pleas in need more help how to use this code I want to use Cairo google font in the pdf, so what to edit to achieve that

    also is it possible to add a unique code or etch generated pdf

    thank you

    Plugin Author David Jensen

    (@dkjensen)

    Sure so you will do something like this in your child theme functions.php file.

    Download the Cairo font .ttf file and then add them to your child theme folder inside assets/fonts/cairo. Then replace the font file names with what you have downloaded below, for example replace below Cairo-Regular.ttf with the actual name of the regular Cairo font.

    
    add_filter( 'wc_cart_pdf_mpdf', function( $mpdf ) {
    	$mpdf->AddFontDirectory( get_stylesheet_directory() . '/assets/fonts/cairo' );
    
    	$mpdf->fontdata['cairo'] = [
                'R' => 'Cairo-Regular.ttf', // Normal font weight
                'I' => 'Cairo-Italic.ttf', // Italic font weight
                'B' => 'Cairo-Bold.ttf', // Bold font weight
                'BI' => 'Cairo-BoldIt.ttf' // Bold italic font weight
    	];
    
    	$mpdf->SetDefaultFont( 'cairo' );
    	$mpdf->AddFont( 'cairo' );
    	$mpdf->SetFont( 'cairo' );
    	$mpdf->autoLangToFont = false;
    	$mpdf->percentSubset = 100;
    
    	return $mpdf;
    } );
    

    You then might need to change the CSS font-family, so to do that copy the PDF CSS from the plugin folder wc-cart-pdf/templates/pdf-styles.php into your child theme folder child-theme/woocommerce/wc-cart-pdf/pdf-styles.php. Then in that copied pdf-styles.php in your child theme replace the body {} font-family like this:

    font-family: "cairo", sans-serif;

    To add a unique code to each PDF that will take further custom programming, but I will see about adding this to the next release.

    Thread Starter nadaaboelenin

    (@nadaaboelenin)

    hello,
    thank you so much for your help
    but I did exactly as you expain still no changes in the font

    Plugin Author David Jensen

    (@dkjensen)

    For others wanting to change the font as well, this is the code that ended up working, and change the font name in the pdf-styles.php body {} block as well

    
    add_filter( 'wc_cart_pdf_mpdf', function( $mpdf ) {
    	$mpdf->AddFontDirectory( get_stylesheet_directory() . '/assets/fonts/rubik' );
    
    	$mpdf->fontdata['rubik'] = [
                'R' => 'Rubik-Regular.ttf',
                'I' => 'Rubik-Italic.ttf',
    	];
    
    	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( 'rubik' );
    	$mpdf->AddFont( 'rubik' );
    	$mpdf->SetFont( 'rubik' );
    	$mpdf->autoLangToFont = false;
    	$mpdf->percentSubset = 100;
    
    	return $mpdf;
    } );
    
    • This reply was modified 3 years, 11 months ago by David Jensen.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘chang font, add pdf name in the header’ is closed to new replies.