Skip to main content

PDF for GravityView Hooks – gfpdf_gv_pdf_metabox_settings

Description​

Add a setting to the Single Entry PDF and Multiple Entries PDF tabs in the View editor, or change an existing setting's label, options or default value.

PDF for GravityView doesn't act on a setting you add. Read its saved value with $view->settings->get( 'your_key' ) in a template override or a gfpdf_gv_template_styles listener.

info

Settings you add appear on both tabs. The Multiple Entries copy is saved as gpdf_multiple_ plus the key without its gpdf_ prefix, so gpdf_uppercase_labels becomes gpdf_multiple_uppercase_labels. A key without the gpdf_ prefix keeps its full name, so my_setting becomes gpdf_multiple_my_setting. The Multiple Entries tab leaves out Form Notifications, and its Filename doesn't accept merge tags.

Version​

This hook was introduced in PDF for GravityView 0.3.

In 2.0, the settings in this array are also copied to the new Multiple Entries PDF tab.

Arguments​

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

$pdf_settings | array​

  • The Single Entry PDF tab's settings, keyed by the setting's ID. The built-in keys are gpdf_filename, gpdf_size, gpdf_orientation, gpdf_page_margin, gpdf_font, gpdf_font_size, gpdf_font_color, gpdf_header, gpdf_footer, gpdf_background_color, gpdf_background_image, gpdf_show_title, gpdf_show_labels, gpdf_notifications and gpdf_css_editor.
  • Each setting is an array in GravityView's View setting format. The keys you'll use most are:
    • label: the setting's name.
    • type: a GravityView setting type, such as text, number, select, checkbox or checkboxes. PDF for GravityView adds color_picker, upload, rich_textarea and code_editor.
    • group: set this to pdf, or the setting won't appear on the Single Entry PDF tab.
    • value: the default value, used until the View is saved with something else.
    • options: the choices for a select or checkboxes setting, as value => label.
    • desc or tooltip: help text shown under or beside the setting.
    • show_in_shortcode: set this to false, as the built-in settings do.

$settings | array​

  • GravityView's default View settings, which the PDF settings are added to. Treat it as read-only.

Usage​

Add an Uppercase Labels? checkbox to both PDF tabs, and apply it when the PDF is generated:

add_filter( 'gfpdf_gv_pdf_metabox_settings', function( $pdf_settings, $settings ) {
$pdf_settings['gpdf_uppercase_labels'] = [
'label' => 'Uppercase Labels?',
'type' => 'checkbox',
'group' => 'pdf',
'value' => '0',
'desc' => 'Print field labels in capital letters.',
'show_in_shortcode' => false,
];

return $pdf_settings;
}, 10, 2 );

add_action( 'gfpdf_gv_template_styles', function( $view, $view_entry, $context ) {
$key = $context === 'directory' ? 'gpdf_multiple_uppercase_labels' : 'gpdf_uppercase_labels';

if ( empty( $view->settings->get( $key ) ) ) {
return;
}
?>
.gv-field-label, td.label, div.label, th {
text-transform: uppercase;
}
<?php
}, 10, 3 );

Make Landscape the default Paper Orientation. Views already saved keep their setting:

add_filter( 'gfpdf_gv_pdf_metabox_settings', function( $pdf_settings, $settings ) {
$pdf_settings['gpdf_orientation']['value'] = 'landscape';

return $pdf_settings;
}, 10, 2 );

Source Code​

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