Purpose

Overwrite the file name or path of the PDF file programmatically. This filter allows external plugins or custom logic to specify a custom file name or path for a generated PDF.

Usage

add_filter( "wr_pdf_template_container_pdf_file", array( $this, "set_pdf_template_container_pdf_file" ), 10, 4 );

Parameters

  • $pdf_file (string): The current file name or path of the PDF.
  • $options (array): An array of options associated with the PDF template.
  • $payload (array): The data associated with the template request.

Use Case

This functionality is useful when:

  • You need to set a specific file name or path for certain PDF templates.
  • You want to store or name the generated PDF files dynamically based on template-specific logic.

Implementation Example

The following example changes the PDF file name for a specific template identified by pdf_identifier:

add_filter( "wr_pdf_template_container_pdf_file", array(  
    $this,  
    "set_pdf_template_container_pdf_file",  
), 10, 4 );
 
public function set_pdf_template_container_pdf_file( $pdf_file, $options, $payload ) {  
    // Filter PDF Template Identifier  
    if ( $options["identifier"] == "pdf_identifier" ) {  
       $pdf_file = "custom_filename";  
    }  
  
    return $pdf_file;  
}