Watermark Width on a PDF

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, I just included a new filter in WaterWoo instead. It’s called ‘wwpdf_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.

add_filter( 'wwpdf_cell_width', 'my_custom_cell_width_function', 10, 2 );
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;

The filter is included in version 3.0.3 of WaterWoo PDF Premium and it applies to the rotatable overlay watermark.