Skip to main content

PDF for GravityView Hooks – gfpdf_gv_pdf_settings_multiple

Description​

Change the settings a Multiple Entries PDF is built with. The filter receives the settings from the View's Multiple Entries PDF tab just before the PDF is generated. The saved View settings aren't changed. For the Single Entry PDF, use gfpdf_gv_pdf_settings.

The array has the same keys as the Single Entry one (listed on the gfpdf_gv_pdf_settings page), with two differences:

  • filename never contains merge tags. Use gfpdf_gv_pdf_filename to build a dynamic name.
  • template names a Multiple Entries template, such as gravityview-directory-entry-table-template.

Field merge tags in the header or footer don't output an entry's value, because the PDF covers many entries.

To read the settings saved on the View instead, use gravityview()->views->get( $view_id )->settings->get( 'gpdf_multiple_size' ). Each Single Entry key gpdf_x has a Multiple Entries equivalent gpdf_multiple_x.

Version​

This hook was introduced in PDF for GravityView 2.0.

Arguments​

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

$settings | array​

  • The PDF settings from the View's Multiple Entries PDF tab.

$view | \GV\View​

  • The View the PDF is being generated for.

$entries | \GV\Entry_Collection​

  • The entries included in the PDF, after any search, sort and entry limit is applied.

Usage​

Print every Multiple Entries PDF in landscape once it holds more than 100 entries:

add_filter( 'gfpdf_gv_pdf_settings_multiple', function( $settings, $view, $entries ) {
if ( $entries->count() > 100 ) {
$settings['orientation'] = 'landscape';
}

return $settings;
}, 10, 3 );

Add a line to the header saying how many entries the PDF holds and when it was generated:

add_filter( 'gfpdf_gv_pdf_settings_multiple', function( $settings, $view, $entries ) {
$settings['header'] .= sprintf(
'<p style="font-size: 8pt; text-align: right;">%d entries, generated %s</p>',
$entries->count(),
esc_html( wp_date( get_option( 'date_format' ) ) )
);

return $settings;
}, 10, 3 );

See Multiple Entries PDF Settings for what each setting does.

Source Code​

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