Skip to main content

Gravity PDF API – get_pdf_filename()

Description​

This method returns the processed filename of an entry's PDF. A processed filename has merge tags rendered, and invalid filename characters removed.

The .pdf extension is not included by default. Pass true to the third parameter if you need it.

Version​

This method was introduced in Gravity PDF 6.16.0.

Parameters​

$entry_id | integer​

  • The Gravity Forms entry ID

$pdf_id | string​

  • The PDF internal identifier (found in the pid URL parameter when viewing individual PDF settings in the admin area)

$include_extension | boolean​

  • Whether to append the .pdf extension to the filename. Defaults to false

Return​

string | WP_Error​

  • The PDF filename will be returned on success, otherwise a WP_Error object on failure

The error code will be invalid_entry when the entry ID doesn't exist, or invalid_pdf_setting when the PDF ID cannot be found on the entry's form.

Usage​

This snippet shows you how to get the filename of a PDF, and check for an error before using it:

add_action( 'init', function() {
if ( class_exists( 'GPDFAPI' ) ) {

/* Returns "Invoice for Ellie" */
$filename = GPDFAPI::get_pdf_filename( 25, '56c14c955d989' );

if ( is_wp_error( $filename ) ) {
return;
}

/* Safe to use $filename */
}
} );

Source Code​

This method is located in api.php.