How to Load Additional or Custom Fonts in the mPDF Library

If you want your PDF documents to match your website’s branding or use your own fonts, you can easily add custom fonts to the MPDF library used by the PDF & Print Pro plugin.

Follow the steps below.


1. Make sure you’re using the latest version

Download and install the latest version of the PDF & Print Pro plugin on your WordPress site.


2. Enable custom PHP code

Go to the PDF & Print Pro → Settings → Custom Code tab.
Turn on the option to activate custom PHP code.


3. Add the PHP code for your font

Copy and paste the following code into the PHP editor.
Replace font-name.ttf, font-name-italic.ttf, and font-name with the actual names of your font files.
Use "R" for regular and "I" for italic styles.

add_filter( 'pdfprnt_mpdf_config', 'pdfprnt_custom_fonts' );

function pdfprnt_custom_fonts( $config ){

  $config['fontdata'] = $config['fontdata'] + array(

 'font-name' => array(

     'R' => 'font-name.ttf',

     'I' => 'font-name-italic.ttf'

   ),
);
 return $config;
}

Click Save Changes.


4. Set your font in Custom CSS

Go to the Output tab and enable the Custom CSS option.
Here you can define styles for your elements.
Example:

h2 { 
font-family: 'font-name';
color: #4c5c68;
font-style: italic;
}
p {
font-family: 'font-name';
color: red;
}
h3 {
font-family: 'font-name';
color: green;
font-style: italic;
}

Click Save Changes again.


5. Upload your font files

Connect to your site via FTP and open the folder:
/wp-content/uploads/pdf-print-fonts/

If the folder doesn’t exist, create it and set permissions to 755.
Then upload your font files directly into this folder (not in subfolders).
Supported formats: .ttf (TrueType) and .otf (OpenType).

Screenshot_1.jpg


6. Check your PDF output

Generate a PDF document using the plugin and confirm that your custom font is displayed correctly.


7. (Optional) Use Full Page Capture

If you’d like the PDF to look exactly like the page on your screen, you can also try the Full Page Capture to PDF option.


Note

Some fonts may not be fully compatible with the MPDF library.
If your custom font doesn’t appear or the style doesn’t change in the generated PDF, try using another font file.


This article related to PDF & Print by BestWebSoft plugin

Additional resources: PDF & Print - User Guide

Still need help? Feel free to contact our friendly support team. Create a private ticket 

Have more questions? Submit a request