Different Stamp on First Page

Cartoon image of two different stamps on a booklet of paper, stamping (no ink left behind)

Brought to you by a longtime user, Jake, is the following snippet, which allows for a different stamp on the first page than all other pages. This is a function for users of TCPDF.

function jakes_overlay_function( $page, $strategy, $x_margin, $y_margin, $cell_width ) {

    // Only do this stamp on the first page
    $start_page = empty( $strategy->settings['setup']['start_page'] ) ? 1 : intval( $strategy->settings['setup']['start_page'] );
    if ( $page === $start_page ) {
        $ishtml = false;
        // If stamp has HTML Multicell needs HTML argument
        if ( $strategy->settings['placement'][0]['content'] != strip_tags( $strategy->settings['placement'][0]['content'] ) || strpos( $strategy->settings['placement'][0]['content'], 'opacity:' ) !== false ) {
            $ishtml = true;
        }
        $stamp->pdf->MultiCell( $cell_width, 1, $strategy->settings['placement'][0]['content'], 0, '', false, 1, $x_margin, $y_margin, true, 0, $ishtml, false, $strategy->size['h'], 'T', false );
    }
}
add_action( 'pdfink_custom_cell_function', 'jakes_overlay_function', 10, 6 );

PDF Ink 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_page” in PDF Ink settings), apply the special stamp. For all other pages, business as usual (maybe a different stamp. 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.

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.

To top