Different Watermark on First Page
Brought to you by a longtime user, Jake, is the following snippet, which allows for a different watermark on the first page than all other pages:
function jakes_custom_overlay_function( $page, $watermark, $o_X_margin, $o_Y_margin, $cell_width ) {
// Only do an overlay on the first page
$start_page = empty( $watermark->settings['start_page'] ) ? 1 : intval( $watermark->settings['start_page'] );
if ( $page === $start_page ) {
$ishtml = false;
// If watermark has HTML Multicell needs HTML argument
if ( $watermark->overlay != strip_tags( $watermark->overlay ) || strpos( $watermark->overlay, 'opacity:' ) !== false ) {
$ishtml = true;
}
$watermark->pdf->MultiCell( $cell_width, 1, $watermark->overlay, 0, '', false, 1, $o_X_margin, $o_Y_margin, true, 0, $ishtml, false, $watermark->size['h'], 'T', false );
}
}
add_action( 'wwpdf_custom_overlay_function', 'jakes_custom_overlay_function', 10, 5 );
WaterWoo loops through each PDF page with TCPDF to apply watermarks. What this PHP code says is that if inside this loop, and we are on the first page (the page indicated as “start” in WaterWoo settings), apply the Overlay watermark. For all other pages, no Overlay mark is applied. The code needs to be cut and pasted into your Wordpress child theme functions.php file, or maybe using the Code Snippets plugin if you are uncomfortable working with theme files via FTP/SSH.
What is the “Overlay?” That’s just a silly term I thought up ten years ago to describe the first watermarking position. It is interchangeable with the “Footer.” Overlay and footer could equally be called placement #1 and placement #2. In Jake’s case, he wanted a big watermark on page one, and just a small watermark on all subsequent pages. This code did the trick for him.
(advertisement)