The SetaPDF Core library allows quite a bit of font customization to be done. Check out the official documentation on SetaPDF and fonts & encoding.
For the meantime, a quick tutorial on how to get other fonts beyond the three packaged with the plugin (Times, Courier, and Helvetica).
Start by finding a TrueType font (.ttf) file which suits your needs. Try to keep the file size small, sub-setting if necessary so that your server isn’t bogged down managing a large font file while trying to manipulate your PDF.
Upload the file to your wp-content/uploads directory, somewhere it won’t get overwritten. It makes sense to use the pdf-ink folder, so we’ve gone ahead and done that below. Arimo is a TrueType font which works for our purposes, so we have uploaded it to a folder “arimo.” Look at the function below and see how we have set up the $path varible. You will need to customize that to suit your file path; otherwise the function should work as-is.
function my_custom_font( $font, $document ) {
// Path to a working TTF font somewhere in your WP directory
$path = WP_CONTENT_DIR . '/uploads/pdf-ink/fonts/arimo/Arimo-Regular.ttf';
if ( is_file( $path ) ) { // quick check to make sure path is correct
try {
/**
* create() method parameters:
* @param SetaPDF_Core_Document $document The document instance in which the font will be used
* @param string $fontFile A path to the TTF font file
* @param string $baseEncoding The base encoding
* @param array|string $diffEncoding A translation table to adjust individual char codes to different glyphs or
* "auto" to build this table dynamically.
* @param boolean $embedded Defines if the font program will be embedded in the document or not.
* Default true. Ensures PDF looks as intended but means larger file size.
* @param bool $ignoreLicenseRestrictions Can be used to disable the font license check. Default false.
*/
$newfont = \SetaPDF_Core_Font_TrueType::create( $document, $path, 'WinAnsiEncoding', 'auto' );
return $newfont;
} catch( Exception $e ) {
error_log( 'An error occurred while trying to add a custom font. ' . $e->getMessage() );
}
} else {
error_log( 'The path to your font file doesn't seem correct. It is: ' . $path );
}
return $font;
}
add_filter ( 'pdfink_filter_setapdf_core_font', 'my_custom_font', 10, 2 );
This piece of code can be added to your child theme functions.php file. If you aren’t comfortable doing that, you can use the free Code Snippets WordPress plugin instead.
Your font selection will not show up in the back end settings because this filter hook is only run during stamping. Test your stamping to see your new font in action! If you aren’t having luck, check your WordPress debugging log for more information about what might have gone wrong.
We cannot provide support to you for managing font files, sourcing, subsetting, licensing, etc. Using action and filter hooks PDF Ink comes with, you should be able to get what you need while geeking out on fonts. If you see room for improvement in PDF Ink or its hooks, please get in touch!