View Categories

Add custom PDF fonts

Available in EntryFoundry Free 0.1.6 and later. Pro is not required.

EntryFoundry includes DejaVu Sans and DejaVu Serif. Developers can register additional font files already stored on the WordPress server with the entryfoundry_pdf_fonts filter. Registered fonts appear in the builder’s Font selector and are passed to the PDF renderer.

Set up a font #

  1. Use font files you are licensed to embed in PDFs; the example does not include or download them. Place the font files in wp-content/uploads/entryfoundry-fonts/. The example uses NotoSans-Regular.ttf, NotoSans-Bold.ttf, NotoSans-Italic.ttf and NotoSans-BoldItalic.ttf. Adjust the filenames to your files. Regular is required; the other variants are optional.
  2. Save this complete PHP snippet as wp-content/mu-plugins/entryfoundry-custom-fonts.php. Create the mu-plugins directory if needed. It registers the filter when WordPress loads; do not paste it into a page, shortcode, or PDF text element.
<?php
/**
 * Plugin Name: EntryFoundry Custom PDF Fonts
 * Description: Adds a local font to EntryFoundry's font selector and PDF renderer.
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

add_filter( 'entryfoundry_pdf_fonts', function ( $fonts ) {
    $dir = WP_CONTENT_DIR . '/uploads/entryfoundry-fonts/';

    $fonts['notosans'] = array(
        'label' => 'Noto Sans',
        'files' => array(
            'R'  => $dir . 'NotoSans-Regular.ttf',
            'B'  => $dir . 'NotoSans-Bold.ttf',
            'I'  => $dir . 'NotoSans-Italic.ttf',
            'BI' => $dir . 'NotoSans-BoldItalic.ttf',
        ),
        'fallback' => false,
    );

    return $fonts;
} );
  1. Reload the EntryFoundry builder. Select a text, field, or table element, then choose the font under Typography > Font.
  2. Save the template and use Preview PDF, or Generate / Test PDF, to check the typeface and required characters in the actual PDF.

Filter reference #

The filter receives an array of registered fonts. Add your entry and return the array to preserve other registrations.

Setting Accepted value
Font key A unique 2–40 character identifier using lowercase letters and digits, starting with a letter, such as notosans. Spaces, hyphens and underscores are not accepted.
label The name shown in the Font selector. If omitted or blank, the font key is used.
files Server filesystem paths to readable .ttf or .otf files. Use absolute paths such as the WP_CONTENT_DIR path above, rather than website URLs. R is required regular; B, I and BI are optional bold, italic and bold italic.
fallback Optional; false by default. Set true to add the font to the PDF renderer’s fallback list for missing characters. Fonts are passed in registration order and must contain the characters you need.

The built-in keys dejavusans, dejavuserif, dejavusanscondensed, dejavuserifcondensed and dejavusansmono cannot be replaced. Unreadable optional variants are skipped. A font without a readable regular variant is omitted entirely. The font must be compatible with the PDF renderer; a filename extension alone does not validate font data.

Preview and troubleshooting #

This hook does not add a browser @font-face rule. The editing canvas or inline HTML can use a browser fallback even when the font appears in the selector. Use Preview PDF or the downloaded PDF to check the actual PDF font, weight and character coverage.

If a font is missing from the selector, check its key, regular-file path, filename case, extension and server read permissions, then reload the builder. Keep the font files and registration available for documents that use the font.