Docs & Support

Learn about all the Formidable features and get support from our amazing customer success team.

frm_pdfs_css

Heads up!
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Use this hook to filter the CSS of the PDF entry export.

Usage

add_filter('frm_pdfs_css', 'modify_pdfs_css' , 10, 2);

Formidable Forms makes advanced site building simple. Launch forms, directories, dashboards, and custom WordPress apps faster than ever before.

Parameters

  • $css (string): The CSS code. This doesn't include the <style> tag.
  • $args (array):
    • entry (object): The entry object.

Examples

Basic example

Use this code example to add custom CSS to your PDF. The $css variable will return all the custom CSS from the PHP function into the stylesheet for the PDF using the following expression:

<style type="text/css">' . $css . '</style>

In the line where it says, Modify the CSS here, add your custom CSS.

add_filter('frm_pdfs_css', 'modify_pdfs_css' , 10, 2);
function modify_pdfs_css( $css, $args ) {
// Modify the CSS here.
return $css;
}

Note: CSS customization is fairly limited. Because the PDF libraries do not support all CSS rules, it is best to keep things simple.

Use custom font

By default, PDF files use font defined in Styles settings. If your language texts don't display correctly in the PDF file, you need to use a different font that supports your language. PDFs addon contains built-in Dejavu Sans font, which supports some languages like Hebrew, Polish, etc.... Use the following code snippet to use the Dejavu Sans font.

add_filter('frm_pdfs_css', 'custom_font_pdfs_css', 10, 2);
function custom_font_pdfs_css( $css, $args ) {
$custom_css = 'body { font-family: Dejavu Sans, sans-serif; }';
return $css . $custom_css;
}

Use Truetype Font

If the Dejavu Sans font doesn't help, you must find another font and register it using CSS @font-face. You need a .ttf file (true type font) that can be accessed via a URL. Use the following example to add the Seto font, which we found to support most languages.

add_filter('frm_pdfs_css', 'ttf_font_pdfs_css', 10, 2);
function ttf_font_pdfs_css( $css, $args ) {
	$custom_css = "
		@font-face {
			font-family: 'Seto';
			font-style: normal;
			font-weight: normal;
			src: url(https://github.com/googlefonts/chinese/raw/gh-pages/fonts/SetoFont/setofont.ttf) format('truetype');
		}

		body {
			font-family: Seto, sans-serif;
		}
	";
	return $css . $custom_css;
}
  • font-style and font-weight should match your text styling. For example, if your text is bold italic, you need to add another @font-face with font-style: italic and font-weight: bold.
  • When a PDF file is generated for the first time, that .ttf file will be downloaded to the wp-content/uploads folder (you can change this location with the frm_pdfs_dompdf_args filter). So you will see that it is slower. After that, it will use the downloaded file, and you can remove the added @font-face in the custom code.
  • We suggest uploading the custom font files to your server, allowing them to be accessed through a URL. Occasionally, external links may not function properly.

Use custom font with CSS selector

If you don't want to apply the custom font to the whole PDF file, use the following code example to replace body with any CSS selector you want.

add_filter('frm_pdfs_css', 'custom_font_pdfs_css_selector',10, 2);
function custom_font_pdfs_css_selector( $css, $args ) {
$custom_css = '.custom-language-text { font-family: Dejavu Sans, sans-serif; }';
return $css . $custom_css;
}

Use custom font for specific entries

Use the following code example to apply the custom font for specific entries. It is useful if you have a multi languages site.

add_filter('frm_pdfs_css', 'custom_font_pdfs_css_entry' ,10, 2);
function custom_font_pdfs_css_entry( $css, $args ) {
	if ( empty( $args['id'] ) ) { // Check for entry ID.
		return $css;
	}

	if ( is_secondary_language_view( $args['id'] ) ) {
		return $css;
	}

	$custom_css = 'body { font-family: Dejavu Sans, sans-serif; }';
	return $css . $custom_css;
}

Add Chinese language using TrueType font

Use the following example to add fonts from the Chinese language. You can register it using @import and will need a .ttf file that can be accessed via a URL.

add_filter('frm_pdfs_css', 'ttf_font_pdfs_css', 10, 2);
function ttf_font_pdfs_css($css, $args) {
    $custom_css = "
        @import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@200..900&display=swap');

        body {
            font-family: \"Noto Serif SC\", sans-serif;
            font-optical-sizing: auto;
            font-style: normal;
        }
    ";

    return $css . $custom_css;
}
Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2025 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Complete your purchase
    Special offer unlocked.
    Get 55% OFF!
    Complete Purchase
    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms