Watermark Width on a PDF

Cartoon image of a measuring tape across the width of a scroll of paper.

A customer just brought up an interesting point: since the watermark width (“cell width” in TCPDF terms) is determined by the PDF page width, won’t a line of text be a “little short” (limited) if the watermark is rotated diagonally?

Since it would take a lot of math with a few variables (page size, mainly) to determine the max cell width based on degree of rotation, we just included a new filter in PDF Ink instead. It’s called ‘pdfink_filter_cell_width’. (Hey, I like math but it’s still really smokey in California and getting hard to think.) The following code is a simple example of an attempt to override the cell width with 300mm, which should work on pages larger than A4. The code includes a fallback if it won’t work.


function my_custom_cell_width_function( $cell_width, $page_size ) {

    $w = $page_size['w'];
    $h = $page_size['h'];
    $max = ( $w * $w ) + ( $h * $h ); // using Pythagorean max cell width can’t be bigger than diagonal
    $max = sqrt( $max );
    $cell_width = 300; // number of MILLIMETERS you wish your text to span. 
    // If it goes off the page, unexpected things will happen
    $cell_width = $cell_width > $max ? $max : $cell_width;
    return $cell_width;

}
add_filter( 'pdfink_filter_cell_width', 'my_custom_cell_width_function', 10, 2 );

The filter is included in PDF Ink for WordPress and it applies to all watermarks. All watermarks are rotatable.

To top