Purpose
Modify the PDF object programmatically before the PDF is generated. This filter allows external plugins or custom logic to adjust the content, structure, or properties of the PDF object dynamically.
Usage
add_filter( "modify_PDF_model_before_pdf_generation", array( $this, "modify_pdf_object" ), 10, 2 );
Parameters
$pdf (PDF)
: The PDF object that will be used for generating the PDF.$request (PDFRequest)
: The request object containing information about the PDF generation process.
Use Case
This functionality is useful when:
- You need to adjust the content or properties of the PDF object based on specific conditions, such as removing sections or adding dynamic data.
- External logic or plugins need to influence the final output of the PDF generation process.
Implementation Example
The following example modifies the PDF object by filtering its content when generating a rehearsal plan PDF:
add_filter( "modify_PDF_model_before_pdf_generation", array( $this, "modify_pdf_object" ), 10, 2 );
public function modify_pdf_object( PDF $pdf, PDFRequest $request ): PDF {
if ( $this->should_modify_pdf( $request ) ) {
$this->apply_pdf_modifications( $pdf );
}
return $pdf;
}
private function should_modify_pdf( PDFRequest $request ): bool {
return isset( $request->type ) && $request->type === "specific_pdf_type";
}
private function apply_pdf_modifications( PDF $pdf ): void {
$pdf->addPageContent( "This is a custom modification." );
}