Purpose

Allow external plugins or custom code to make final adjustments to the mPDF instance before the PDF is generated. This filter can be used to add headers, footers, or other configurations to the PDF.

Usage

add_filter( "wr_pdf_template_mpdf_before_write", array( $this, "add_header_and_footer" ), 10, 2 );

Parameters

  • $mpdf (mPDF): The mPDF instance used for generating the PDF.
  • $identifier (string): The identifier of the PDF template.

Use Case

This functionality is useful when:

  • You need to add or customize the HTML header and footer for specific PDF templates.
  • Final adjustments to the mPDF instance, such as metadata or rendering settings, are required before the PDF is written.

Implementation Example

The following example adds a custom HTML header and footer to a PDF identified by pdf_identifier:

add_filter( "wr_pdf_template_mpdf_before_write", array( $this, "add_header_and_footer" ), 10, 2 );
 
public function add_header_and_footer( $mpdf, $identifier ) {
	if($identifier === "pdf_identifier") {
		$mpdf->SetHTMLHeader( '<div style="margin-top: 90px;"> </div>' );
		$mpdf->SetHTMLFooter( '<div class="page-footer" style="margin-top: 20px;"></div>' );
	}
	return $mpdf;
}