ucec_generate_certificate_tcpdf_dest
Filters the destination of the generated certificate PDF before it is saved or outputted by the TCPDF library.
add_filter( 'ucec_generate_certificate_tcpdf_dest', $callback, 10, 1 );
Description
This filter hook allows developers to modify the output destination of the generated certificate PDF. By default, it's set to 'F' for saving on the server. You can change this value to control where the PDF is sent, for example, to the browser for download.
Usage
add_filter( 'ucec_generate_certificate_tcpdf_dest', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
add_filter( 'ucec_generate_certificate_tcpdf_dest', 'my_custom_ucec_pdf_destination', 10, 1 );
/**
* Custom function to control TCPDF PDF output destination for certificates.
*
* By default, the 'F' parameter saves the PDF to the server. This filter
* allows developers to change the output destination. For example, you might
* want to send it directly to the browser for download.
*
* @param string $default_destination The default output destination ('F' for file save).
* @return string The desired TCPDF output destination string.
*/
function my_custom_ucec_pdf_destination( $default_destination ) {
// Example: If a specific GET parameter is set, force download the PDF.
if ( isset( $_GET['download_certificate'] ) && $_GET['download_certificate'] === 'true' ) {
return 'D'; // 'D' for download
}
// Otherwise, use the default behavior (save to server).
return $default_destination;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/includes/tcpdf-certificate-code.php:717
$pdf->SetFillColor( 255, 255, 127 );
$pdf->setCellPaddings( 0, 0, 0, 0 );
// Print signature
ob_clean();
$full_path = $save_path . $file_name . '.pdf';
$output = apply_filters( 'ucec_generate_certificate_tcpdf_dest', 'F' );
$pdf->Output( $full_path, $output ); /* F means saving on server. */
return $full_path;
}