Purpose

Modify the raw HTML output of individual PDF pages before rendering. This filter enables external plugins or custom logic to dynamically inject or replace content within the HTML of specific PDF pages.

Usage

add_filter( "wr_pdf_template_pdf_page_modify_html", array( $this, "modify_pdf_page_html" ), 10, 2 );

Parameters

  • $html (string): The current raw HTML output of the PDF page.
  • $pdf_page_DTO (PDFPageDTO): A data object containing context and configuration for the current PDF page, including its identifier and payload.

Use Case

This filter is useful when:

  • You want to replace placeholders in the HTML (e.g. ##placeholder##) with dynamic or customer-specific content.
  • You need to conditionally change the content or layout of a PDF page based on the template or settings.
  • You want to inject HTML blocks, inline styles, or customer-specific details.

Implementation Example

The following example replaces a placeholder in the HTML of a PDF page with a WordPress option value, only for a specific PDF identifier:

public function __construct() {
	add_filter( "wr_pdf_template_pdf_page_modify_html", array( $this, "modify_pdf_page_html" ), 10, 2 );
}
 
public function modify_pdf_page_html( string $html, PDFPageDTO $pdf_page_DTO ): string {
	if ( $pdf_page_DTO->identifier === "your_identifier" ) {
		$option = get_option( "your_option" );
		$html = str_replace( "##your_placeholder##", $option, $html );
	}
	return $html;
}