fg_fillablepdfs_pdf_args

Description

This filter allows you to modify the details of the PDF before it is sent to ForGravity to be generated.

Usage

PHP
add_filter( 'fg_fillablepdfs_pdf_args', 'your_function_name', 10, 4 );

Parameters

$pdf_meta array
An array containing all the PDF meta data. Example:

PHP
array(
	'template_id'   => '996e96e0-6763-4bf1-bdc7-c5cc6d4e40db',
	'file_name'     => 'My Generated PDF.pdf',
	'field_values'  => array(
		'First Name' => 'John',
		'Last Name'  => 'Doe',
	),
	'password'      => null,
	'user_password' => 'Open Sesame',
	'permissions'   => array( 'Printing', 'DegradedPrinting', 'ModifyContents', 'Assembly', 'CopyContents', 'ScreenReaders', 'ModifyAnnotations', 'FillIn' ),
	'flatten'       => false,
);

$feed array
The current Feed object.

$entry array
The current Entry object.

$form array
The current Form object.

Examples

Populating Data From List Field

This example uses the contents of a multiple column List field to populate PDF fields matching the days of the week.

<?php
add_filter( 'fg_fillable_pdf_args', 'add_list_field_to_pdf', 10, 4 );
function add_list_field_to_pdf( $pdf_meta, $feed, $entry, $form ) {
// Prepare column names for each day of the week.
$column_names = array(
'Sunday %d',
'Monday %d',
'Tuesday %d',
'Wednesday %d',
'Thursday %d',
'Friday %d',
'Saturday %d',
);
// Set maximum number of rows.
$max_rows = 4;
// Get List items.
$list_items = rgar( $entry, 4 ); // Replace 4 with your List field ID.
$list_items = maybe_unserialize( $list_items );
// If there are no List items, return.
if ( empty( $list_items ) ) {
return $pdf_meta;
}
// Loop through List rows up to the maximum row count.
for ( $i = 0; $i < ( $max_rows + 1 ); $i++ ) {
// Get List row.
$list_row = rgar( $list_items, $i );
// If List row is not found, skip.
if ( ! $list_row ) {
continue;
}
// Remove array keys from List row contents.
$list_row = array_values( $list_row );
// Loop through each column in the row.
foreach ( $list_row as $col => $value ) {
// Get the PDF key for this column.
$pdf_key = sprintf( $column_names[ $col ], ( $i + 1 ) );
// Add value if it is not empty.
if ( ! rgblank( $value ) ) {
$pdf_meta['field_values'][ $pdf_key ] = $value;
}
}
}
return $pdf_meta;
}