Integration with Gravity PDF
How do you get the selected image to display in my Gravity PDF template? By default Gravity PDF will display the selected choice text or value. The image is stored as a custom value on the choice, separate to the text and value, but you can use one of Gravity PDF’s filters to get the image to display. Firstly, make sure that your Image Choices setting for “Default Entry / Notification Display” is set to an image-based option. Either “Image“, “Image and Label” or “Image and Value“, whichever suits your needs.
Gravity PDF Filters
There are two Gravity PDF filters. Which one you use will depend on the field type. For normal radio button or checkbox fields you can use the gfpdf_pdf_field_content
filter. The following example demonstrates this:
For normal image choices fields
<?php
add_filter('gfpdf_pdf_field_content', function ($value, $field, $entry, $form) {
if ( !function_exists('gf_image_choices') ) {
return $value;
}
// Update to suit
$image_width = 80;
return gf_image_choices()->gfpdf_ic_field_content($value, $field, $entry, $form, $image_width);
}, 10, 4);
For Product / Option fields
<?php
add_filter("gfpdf_field_product_value", function( $html, $products, $field, $form, $entry, $self ){
if ( !function_exists('gf_image_choices') ) {
return $html;
}
// Update to suit
$image_width = 80;
return gf_image_choices()->gfpdf_ic_field_product_value($html, $products, $field, $form, $entry, $image_width);
}, 10, 6);