Skip to main content

PDF for GravityView Hooks – gfpdf_gv_pdf_filename

Description​

Change the name of a Single Entry or Multiple Entries PDF. Use it when the name needs a value that changes, such as today's date, the number of entries or the current user. The Multiple Entries PDF tab's Filename setting doesn't accept merge tags, because there's no single entry to read from.

By default the name comes from the Filename setting on the matching tab, or the View's title when that's blank. The .pdf extension is added if it's missing. The value you return isn't sanitized, so pass anything built from entry or user data through sanitize_file_name().

Version​

This hook was introduced in PDF for GravityView 2.0.

Arguments​

The following arguments are passed to functions that use this hook:

$filename | string​

  • The filename, without the .pdf extension.
  • The default value is the Filename setting for the tab being rendered, or the View's title when that setting is blank.

$view | \GV\View​

  • The View the PDF is being generated for.

$entry | \GV\Entry | \GV\Entry_Collection​

  • For a Single Entry PDF, the entry being rendered (a \GV\Entry). If the View joins forms with GravityView's Multiple Forms extension, it's the joined entry.
  • For a Multiple Entries PDF, a \GV\Entry_Collection of the entries in the PDF, after search, sort and the entry limit are applied.
  • Use $entry instanceof \GV\Entry_Collection to tell the two apart.

Usage​

Add today's date and the number of entries to every Multiple Entries PDF, such as Staff Directory 2026-09-21 (42 entries).pdf:

add_filter( 'gfpdf_gv_pdf_filename', function( $filename, $view, $entry ) {
if ( ! $entry instanceof \GV\Entry_Collection ) {
return $filename;
}

return sprintf( '%s %s (%d entries)', $filename, wp_date( 'Y-m-d' ), $entry->count() );
}, 10, 3 );

Add the logged-in user's display name to the filename:

add_filter( 'gfpdf_gv_pdf_filename', function( $filename, $view, $entry ) {
$user = wp_get_current_user();

if ( ! $user->exists() ) {
return $filename;
}

return $filename . ' - ' . sanitize_file_name( $user->display_name );
}, 10, 3 );

See the Filename setting for how the default name is chosen.

Source Code​

This filter is located in src/Pdf/Renderer.php of the PDF for GravityView extension.