Home / Archive / MemberPress: Replace Font-Family for PDF Invoice
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Replace Font-Family for PDF Invoice

To replace the font-family used for PDF invoices, font files need to be uploaded to a site, and this code needs to be added.

In the example code, the font family used is Roboto. The steps to make this work are the following:

1. Font files should be downloaded (in this case from Google Fonts) in ttf format. In the example, the files used are: Roboto-Regular.ttf, Roboto-Bold.ttf, and Roboto-Italic.ttf. (1 or more files can be used);

2. Next, font files need to be uploaded to the wp-content/themes/current-theme/fonts/ folder on the site. If this folder is not present on the site, it needs to be created;

3. The code needs to be added to replace the font family.

Code Preview
php
<?php
function mepr_custom_pdf_invoice_fonts( $fonts ) {
	return array(
		'roboto' => array(
			'R'          => 'Roboto-Regular.ttf',
          	'B'          => 'Roboto-Bold.ttf',
         	'I'          => 'Roboto-Italic.ttf',
         	'BI'         => 'Roboto-Bold.ttf',
			//'useOTL'     => 0xFF,
			'useKashida' => 75,
		),
	);
}
add_filter( 'mepr-pdf-invoice-fonts', 'mepr_custom_pdf_invoice_fonts' );
function mepr_custom_options_dynamic_attrs( $attrs ) {
	$attrs['biz_invoice_font'] = array(
		'default'     => 'roboto',
		'validations' => array(),
	);
	return $attrs;
}
add_filter( 'mepr-options-dynamic-attrs', 'mepr_custom_options_dynamic_attrs' );

Comments

Add a Comment